Fix dll algo
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
5fa2cd8bb3
commit
8829d0bec7
|
@ -85,7 +85,7 @@ func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
|
|||
weight: weight,
|
||||
}}
|
||||
dllist := dll.NewList()
|
||||
dllist.PushFront(*root)
|
||||
dllist.PushFront(root)
|
||||
|
||||
for dllist.Len() > 0 {
|
||||
current := dllist.Front()
|
||||
|
@ -93,6 +93,7 @@ func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
|
|||
|
||||
nodeWeight := current.Value.(*Node).getNodeWeight()
|
||||
counter[current.Value.(*Node).ID].weight = nodeWeight
|
||||
counter[current.Value.(*Node).ID].node = current.Value.(*Node)
|
||||
// Прибавляем вес всем родительским нодам до корня
|
||||
parentNode := counter[current.Value.(*Node).ID].parent
|
||||
for {
|
||||
|
@ -103,12 +104,14 @@ func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
|
|||
currentNode.weight = currentNode.weight + nodeWeight
|
||||
parentNode = currentNode.parent
|
||||
}
|
||||
|
||||
if len(current.Value.(*Node).Children) > 0 {
|
||||
counter[current.Value.(*Node).ID].children = current.Value.(*Node).Children
|
||||
}
|
||||
for _, child := range current.Value.(*Node).Children {
|
||||
counter[child.ID] = &WeightedNode{
|
||||
parent: current.Value.(*Node),
|
||||
}
|
||||
dllist.PushFront(*child)
|
||||
dllist.PushFront(child)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestNode_WeighingTreeAllAlgo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func Benchmark(b *testing.B) {
|
||||
b.StopTimer()
|
||||
b.ResetTimer()
|
||||
|
@ -42,34 +41,34 @@ func Benchmark(b *testing.B) {
|
|||
depth int
|
||||
}{
|
||||
"Small tree (85 nodes)":{4, 4}, // 85 nodes,
|
||||
"Wide tree (2,65K nodes)": {515, 3}, // 265'741 nodes,
|
||||
"Deep tree (2,65K nodes)": {3, 12}, // 265'720 nodes,
|
||||
"Wide tree (265K nodes)": {515, 3}, // 265'741 nodes,
|
||||
"Deep tree (265K nodes)": {3, 12}, // 265'720 nodes,
|
||||
"Huge tree (2,44M nodes)": {5, 10}, // 2'441'406 nodes,
|
||||
"Pathological tree (10K nodes)": {1, 10000}, // 10'000 nodes,
|
||||
}{
|
||||
b.Run(name, func(b *testing.B) {
|
||||
tree := getTestTree(tt.branches, tt.depth)
|
||||
tree := getTestTree(tt.branches, tt.depth, nil)
|
||||
b.Cleanup(func() {
|
||||
tree = TestTree{nil, nil}
|
||||
})
|
||||
b.Run("Weighing with recursion", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StartTimer()
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithRecursion())
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithRecursion(nil))
|
||||
b.StopTimer()
|
||||
}
|
||||
})
|
||||
b.Run("Weighting with stack", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StartTimer()
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithStack())
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithStack(nil))
|
||||
b.StopTimer()
|
||||
}
|
||||
})
|
||||
b.Run("Weighting with DLL", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StartTimer()
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithDLL())
|
||||
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithDLL(nil))
|
||||
b.StopTimer()
|
||||
}
|
||||
})
|
||||
|
@ -78,8 +77,6 @@ func Benchmark(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func printExpectations(expected, actual map[string]*WeightedNode) {
|
||||
var expectedSlice, actualSlice []int
|
||||
for _,v := range expected {
|
||||
|
|
Loading…
Reference in New Issue