package proximity
import (
"slices"
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph"
)
func CommonUncleSiblings (graph *layoutgraph .Graph ) map [*layoutgraph .Node ]layoutgraph .Nodes {
uncleToCousins := make (map [*layoutgraph .Node ]layoutgraph .Nodes )
common := make (map [*layoutgraph .Node ]layoutgraph .Nodes )
var orderedUncles []*layoutgraph .Node
for _ , container := range graph .ContainerRDFSOrderUnbounded (nil ) {
children := graph .Containers [container ]
for _ , node := range children {
for _ , edge := range node .Edges {
adjacent := node .Adjacent (edge )
if adjacent .Container == container .Container {
if _ , ok := uncleToCousins [adjacent ]; !ok {
orderedUncles = append (orderedUncles , adjacent )
uncleToCousins [adjacent ] = []*layoutgraph .Node {}
}
if !slices .Contains (uncleToCousins [adjacent ], node ) {
uncleToCousins [adjacent ] = append (uncleToCousins [adjacent ], node )
}
}
}
}
for _ , uncle := range orderedUncles {
siblings := uncleToCousins [uncle ]
if len (siblings ) < 2 {
continue
}
for _ , sibling := range siblings {
if existing , ok := common [sibling ]; !ok || len (existing ) < len (siblings ) {
common [sibling ] = siblings
}
}
}
uncleToCousins = make (map [*layoutgraph .Node ]layoutgraph .Nodes )
}
return common
}
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 .