package layoutgraph
import (
"context"
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/invariant"
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/limits"
)
const nodeGraphOwnershipSnapshotLocation = "NodeGraphOwnershipSnapshot"
type NodeGraphOwnershipSnapshot struct {
owners []nodeGraphOwner
}
type nodeGraphOwner struct {
node *Node
graph *Graph
}
func (snapshot NodeGraphOwnershipSnapshot ) Restore () {
for _ , owner := range snapshot .owners {
owner .node .Graph = owner .graph
}
}
func SnapshotNodeGraphOwnership (ctx context .Context , graph *Graph ) (NodeGraphOwnershipSnapshot , error ) {
if graph == nil {
return NodeGraphOwnershipSnapshot {}, invariant .New ("node graph ownership snapshot requires a graph" )
}
guard , err := limits .NewWorkGuard (ctx , nodeGraphOwnershipSnapshotLocation , maxEngineWorkUnits )
if err != nil {
return NodeGraphOwnershipSnapshot {}, err
}
objects , err := collectRuntimeObjectsContext (graph , guard , "ownership runtime" )
if err != nil {
return NodeGraphOwnershipSnapshot {}, err
}
owners := make ([]nodeGraphOwner , len (objects .nodeOrder ))
for index , node := range objects .nodeOrder {
if err := guard .Step (); err != nil {
return NodeGraphOwnershipSnapshot {}, err
}
owners [index ] = nodeGraphOwner {node : node , graph : node .Graph }
}
if err := guard .Finish (); err != nil {
return NodeGraphOwnershipSnapshot {}, err
}
return NodeGraphOwnershipSnapshot {owners : owners }, nil
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .