Исправлен каттер
continuous-integration/drone/push Build is passing Details

main
Андрей Иванов 2024-10-08 19:05:11 +03:00
parent 154fb2c7b2
commit 17b4b34bd3
1 changed files with 7 additions and 12 deletions

View File

@ -1,9 +1,8 @@
package main package main
import ( import (
"slices"
"github.com/pkg/errors" "github.com/pkg/errors"
"slices"
) )
func DecomposeTree(tree map[string]*WeightedNode, threshold uint16) ([]SubTree, error) { func DecomposeTree(tree map[string]*WeightedNode, threshold uint16) ([]SubTree, error) {
@ -109,18 +108,14 @@ func RecalculateParents(tree map[string]*WeightedNode, currentID string, nodeWei
func CutBranch(tree map[string]*WeightedNode, nodeID string) *Node { func CutBranch(tree map[string]*WeightedNode, nodeID string) *Node {
// Удаление ссылки на ноду из родительской ноды // Удаление ссылки на ноду из родительской ноды
if tree[nodeID].parent != nil { if tree[nodeID].parent != nil {
parentID := tree[nodeID].parent.ID parent := tree[nodeID].parent
k := slices.IndexFunc(tree[parentID].children, func(node *Node) bool { m := slices.IndexFunc(parent.Children, func(node *Node) bool {
return node.ID == nodeID return node.ID == nodeID
}) })
if k > 0 { if m >= 0 {
tree[parentID].children = append(tree[parentID].children[:k], tree[parentID].children[k+1:]...) parent.Children[m] = parent.Children[len(parent.Children)-1]
} parent.Children = parent.Children[:len(parent.Children)-1]
m := slices.IndexFunc(tree[parentID].node.Children, func(node *Node) bool { //parent.Children = append(parent.Children[:m], parent.Children[m+1:]...)
return node.ID == nodeID
})
if m > 0 {
tree[parentID].children = append(tree[parentID].node.Children[:m], tree[parentID].node.Children[m+1:]...)
} }
} }