72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"maps"
|
|
)
|
|
|
|
type TestTree struct {
|
|
Tree *Node
|
|
Weights map[string]*WeightedNode
|
|
}
|
|
|
|
func getTestTree(branches, depth int, parent *Node) TestTree {
|
|
if depth == 0 {
|
|
return TestTree{}
|
|
}
|
|
id := uuid.NewString()
|
|
node := &Node{
|
|
ID: id,
|
|
Name: id,
|
|
Children: []*Node{},
|
|
}
|
|
tree := TestTree{
|
|
Tree: node,
|
|
Weights: map[string]*WeightedNode{id: &WeightedNode{
|
|
node: node,
|
|
parent: parent,
|
|
children: nil,
|
|
weight: node.getNodeWeight(),
|
|
}},
|
|
}
|
|
for i := 0; i < branches; i++ {
|
|
childTree := getTestTree(branches, depth-1, node)
|
|
if childTree.Tree != nil {
|
|
tree.Tree.Children = append(tree.Tree.Children, childTree.Tree)
|
|
tree.Weights[id].children = append(tree.Weights[id].children, childTree.Tree)
|
|
maps.Copy(tree.Weights, childTree.Weights)
|
|
}
|
|
}
|
|
for _, child := range tree.Tree.Children {
|
|
tree.Weights[id].weight = tree.Weights[id].weight + tree.Weights[child.ID].weight
|
|
}
|
|
return tree
|
|
}
|
|
|
|
type testDecomposingData struct {
|
|
Tree map[string]*WeightedNode
|
|
Threshold int
|
|
Parts []SubTree
|
|
}
|
|
|
|
var smallTree = testDecomposingData{
|
|
Tree: map[string]*WeightedNode{
|
|
"root": {
|
|
node: &Node{
|
|
ID: "root",
|
|
Name: "root",
|
|
},
|
|
},
|
|
},
|
|
Threshold: 2,
|
|
Parts: []SubTree{
|
|
{
|
|
path: "/",
|
|
tree: &Node{
|
|
ID: "root",
|
|
Name: "root",
|
|
},
|
|
},
|
|
},
|
|
}
|