Skip to content

Commit

Permalink
refactor: heap reset
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Sep 26, 2024
1 parent a989134 commit f7bb0a2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions heap/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ func (me *Min) Update(item string, fingerprint uint32, count uint32) bool {
heap.Fix(me, 0)
return true
}

// Reset resets the heap.
func (me *Min) Reset() {
clear(me.Items)
clear(me.Index)
me.StoredKeysBytes = 0
me.Items = me.Items[:0]
}
3 changes: 1 addition & 2 deletions sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,5 @@ func (me *Sketch) SortedSlice() []heap.Item {
// Reset resets the sketch to an empty state.
func (me *Sketch) Reset() {
clear(me.Buckets)
clear(me.Heap.Items)
clear(me.Heap.Index)
me.Heap.Reset()
}
3 changes: 1 addition & 2 deletions sliding/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,5 @@ func (me *Sketch) Reset() {
clear(me.Buckets[i].Counts)
}
clear(me.Buckets)
clear(me.Heap.Items)
clear(me.Heap.Index)
me.Heap.Reset()
}

0 comments on commit f7bb0a2

Please sign in to comment.