Skip to content

Commit

Permalink
Fix insert for repeated start, end
Browse files Browse the repository at this point in the history
If multiple vals are inserted into a MultiValueSearchTree with same start, end intervals, insert() will recurse to upsert() rather than insert(), which causes a wholesale replacement of vals rather than appending as it should, resulting in data loss. This causes insert() to recurse to insert() instead, which does the proper append.
  • Loading branch information
ttjoseph authored Jan 10, 2024
1 parent c7f7698 commit c9e90fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions interval/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func insert[V, T any](n *node[V, T], intervl interval[V, T], cmp CmpFunc[T]) *no
case intervl.equal(n.interval.start, n.interval.end, cmp):
n.interval.vals = append(n.interval.vals, intervl.vals...)
case intervl.less(n.interval.start, n.interval.end, cmp):
n.left = upsert(n.left, intervl, cmp)
n.left = insert(n.left, intervl, cmp)
default:
n.right = upsert(n.right, intervl, cmp)
n.right = insert(n.right, intervl, cmp)
}

if cmp.gt(intervl.end, n.maxEnd) {
Expand Down

0 comments on commit c9e90fe

Please sign in to comment.