45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Package diagram provide diagram data structure and operation
|
|
package diagram
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"modelRT/util"
|
|
)
|
|
|
|
// graphOverview define struct of storage all circuit diagram topologic data keyed by pageID
|
|
var graphOverview util.TypedMap[int64, *Graph]
|
|
|
|
// PrintGrapMap define func of print circuit diagram topologic info data
|
|
func PrintGrapMap() {
|
|
graphOverview.Range(func(pageID int64, graph *Graph) bool {
|
|
fmt.Println(pageID, graph)
|
|
return true
|
|
})
|
|
}
|
|
|
|
// GetGraphMap define func of get circuit diagram topologic data by pageID
|
|
func GetGraphMap(pageID int64) (*Graph, error) {
|
|
graph, ok := graphOverview.Load(pageID)
|
|
if !ok {
|
|
return nil, fmt.Errorf("can not find graph by pageID:%d", pageID)
|
|
}
|
|
return graph, nil
|
|
}
|
|
|
|
// UpdateGrapMap define func of update circuit diagram data by pageID and topologic info
|
|
func UpdateGrapMap(pageID int64, graphInfo *Graph) bool {
|
|
_, result := graphOverview.Swap(pageID, graphInfo)
|
|
return result
|
|
}
|
|
|
|
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
|
|
func StoreGraphMap(pageID int64, graphInfo *Graph) {
|
|
graphOverview.Store(pageID, graphInfo)
|
|
}
|
|
|
|
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
|
|
func DeleteGraphMap(pageID int64) {
|
|
graphOverview.Delete(pageID)
|
|
}
|