Skip to content

Commit

Permalink
Fixing duplicate issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire committed May 9, 2022
1 parent 8dbf88a commit f48bfee
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions binaryfusefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"math"
"math/bits"
"sort"
)

type BinaryFuse8 struct {
Expand Down Expand Up @@ -86,6 +87,7 @@ func mod3(x uint8) uint8 {

// PopulateBinaryFuse8 fills a BinaryFuse8 filter with provided keys.
// The function may return an error after too many iterations: it is unlikely.
// If your input has duplicates, it may get sorted.
func PopulateBinaryFuse8(keys []uint64) (*BinaryFuse8, error) {
size := uint32(len(keys))
filter := &BinaryFuse8{}
Expand Down Expand Up @@ -240,6 +242,12 @@ func PopulateBinaryFuse8(keys []uint64) (*BinaryFuse8, error) {
// Success
size = stacksize
break
} else if duplicates > 0 {
// Duplicates were found, but we did not
// manage to remove them all. We may simply sort the key to
// solve the issue. This will run in time O(n log n) and it
// mutates the input.
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
}
for i := uint32(0); i < size; i++ {
reverseOrder[i] = 0
Expand Down

0 comments on commit f48bfee

Please sign in to comment.