Fixes
continuous-integration/drone/push Build is passing Details

main
Андрей Иванов 2024-09-27 11:36:35 +03:00
parent 8829d0bec7
commit ecea2852f6
2 changed files with 14 additions and 15 deletions

View File

@ -42,7 +42,7 @@ func (root *Node) WeightingTreeWithRecursion(parent *Node) map[string]*WeightedN
return res
}
func (root *Node) WeightingTreeWithStack(parent *Node) map[string]*WeightedNode {
func (root *Node) WeightingTreeWithStack() map[string]*WeightedNode {
weight := root.getNodeWeight()
res := map[string]*WeightedNode{root.ID: {
weight: weight,
@ -79,7 +79,7 @@ func (root *Node) WeightingTreeWithStack(parent *Node) map[string]*WeightedNode
return res
}
func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
func (root *Node) WeightingTreeWithDLL() map[string]*WeightedNode {
weight := root.getNodeWeight()
counter := map[string]*WeightedNode{root.ID: {
weight: weight,
@ -123,12 +123,11 @@ func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
// return nil, nil
//}
func (n *Node) getNodeWeight() uint16 {
weighted := &Node{
ID: n.ID,
Name: n.Name,
func (root *Node) getNodeWeight() uint16 {
nodeBytes, _ := json.Marshal(&Node{
ID: root.ID,
Name: root.Name,
Children: []*Node{},
}
nodeBytes, _ := json.Marshal(weighted)
})
return uint16(len(nodeBytes))
}

View File

@ -20,12 +20,12 @@ func TestNode_WeighingTreeAllAlgo(t *testing.T) {
assert.EqualValues(t, tt.Weights, weightTreeWithRecursion)
})
t.Run("WeightingTreeWithStack", func(t *testing.T) {
weightTreeWithStack := tt.Tree.WeightingTreeWithStack(nil)
weightTreeWithStack := tt.Tree.WeightingTreeWithStack()
printExpectations(tt.Weights, weightTreeWithStack)
assert.EqualValues(t, tt.Weights, weightTreeWithStack)
})
t.Run("WeightingTreeWithDLL", func(t *testing.T) {
weightTreeWithDLL := tt.Tree.WeightingTreeWithDLL(nil)
weightTreeWithDLL := tt.Tree.WeightingTreeWithDLL()
printExpectations(tt.Weights, weightTreeWithDLL)
assert.EqualValues(t, tt.Weights, weightTreeWithDLL)
})
@ -41,9 +41,9 @@ func Benchmark(b *testing.B) {
depth int
}{
"Small tree (85 nodes)":{4, 4}, // 85 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,
//"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) {
@ -61,14 +61,14 @@ func Benchmark(b *testing.B) {
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(nil))
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithStack())
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(nil))
assert.EqualValues(b, tree.Weights, tree.Tree.WeightingTreeWithDLL())
b.StopTimer()
}
})