Skip to content

Commit

Permalink
Fix erroneous update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcphailtom committed Sep 11, 2023
1 parent aecdaa3 commit a4b4e64
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func (t *Tree[T, id]) Root() Node[T, id] {
func (t *Tree[T, id]) Insert(node Node[T, id]) error {

// Check for the existence of the nodeIndex key in the index
var exists bool
existingNode, err := t.nodeIndex.find(node.GetID())
if err == nil {
if !t.updatesAllowed {
return NodeExists
}
exists = true
existingNode.UpdateNode(node)
return nil
}

if reflect.ValueOf(&t.root).Elem().IsZero() { // always insert the first element
Expand All @@ -85,12 +85,6 @@ func (t *Tree[T, id]) Insert(node Node[T, id]) error {
parent.AddChildren(node)
}

// If there is an existing node, update it
if exists {
existingNode.UpdateNode(node)
return nil
}

// add to nodeIndex index
t.nodeIndex.insert(node)
return nil
Expand Down

0 comments on commit a4b4e64

Please sign in to comment.