Skip to content

Commit

Permalink
Simplify finding duplicates in sstable.aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
antw committed Dec 26, 2021
1 parent ce9e3e2 commit 66d1ae2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/sstable/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ func (a *aggregator) Ascend(iterator func(key string, value []byte) bool) {
item := heap.Pop(pq).(*mergeItem)
conflict := false

// Check that no later iterator has a conflicting key. This is surely not the optimal way
// of doing this... perhaps a separate priority queue data structure could be used, wrapping
// around mergeHeap, that would handle de-duplication when adding new items?
for _, other := range *pq {
if other.kv.Key == item.kv.Key && other.iterIndex > item.iterIndex {
conflict = true
break
}
// Check that no later iterator has a conflicting key. If a conflict is found it will always
// be the next element in the heap.
if next := pq.Peek(); next != nil && next.kv.Key == item.kv.Key {
conflict = true
}

if !conflict && !iterator(item.kv.Key, item.kv.Value) {
Expand Down Expand Up @@ -83,3 +79,13 @@ func (h *mergeHeap) Pop() interface{} {

return x
}

func (h *mergeHeap) Peek() *mergeItem {
hp := *h

if len(hp) == 0 {
return nil
}

return hp[0]
}

0 comments on commit 66d1ae2

Please sign in to comment.