Skip to content

Commit

Permalink
Fix: Locking for MultiValueSearchTree
Browse files Browse the repository at this point in the history
Previously not all API's for hte MVST were correctly locking and
unlocking the tree. This fixes those APIs
  • Loading branch information
thorfour authored and rdleal committed Nov 3, 2023
1 parent fee6a24 commit c7f7698
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion interval/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func deleteMax[V, T any](n *node[V, T], cmp CmpFunc[T]) *node[V, T] {
// Delete returns an InvalidIntervalError if the given end is less than or equal to the given start value.
func (st *MultiValueSearchTree[V, T]) Delete(start, end T) error {
st.mu.Lock()
st.mu.Unlock()
defer st.mu.Unlock()

if st.root == nil {
return nil
Expand Down
4 changes: 4 additions & 0 deletions interval/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func newEmptyValueListError[V, T any](it interval[V, T], action string) error {
// Insert returns an InvalidIntervalError if the given end is less than or equal to the given start value,
// or an EmptyValueListError if vals is an empty list.
func (st *MultiValueSearchTree[V, T]) Insert(start, end T, vals ...V) error {
st.mu.Lock()
defer st.mu.Unlock()
intervl := interval[V, T]{
start: start,
end: end,
Expand Down Expand Up @@ -124,6 +126,8 @@ func insert[V, T any](n *node[V, T], intervl interval[V, T], cmp CmpFunc[T]) *no
// Insert returns an InvalidIntervalError if the given end is less than or equal to the given start value,
// or an EmptyValueListError if vals is an empty list.
func (st *MultiValueSearchTree[V, T]) Upsert(start, end T, vals ...V) error {
st.mu.Lock()
defer st.mu.Unlock()
intervl := interval[V, T]{
start: start,
end: end,
Expand Down

0 comments on commit c7f7698

Please sign in to comment.