Skip to content

Commit f3b4131

Browse files
committed
Fixing issue 35
1 parent 6d1b855 commit f3b4131

File tree

6 files changed

+97
-373
lines changed

6 files changed

+97
-373
lines changed

binaryfusefilter.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package xorfilter
22

33
import (
4+
"errors"
45
"math"
56
"math/bits"
6-
"sort"
77
)
88

99
type BinaryFuse8 struct {
@@ -114,13 +114,8 @@ func PopulateBinaryFuse8(keys []uint64) (*BinaryFuse8, error) {
114114
iterations += 1
115115
if iterations > MaxIterations {
116116
// The probability of this happening is lower than the
117-
// the cosmic-ray probability (i.e., a cosmic ray corrupts your system),
118-
// but if it happens, we just fill the fingerprint with ones which
119-
// will flag all possible keys as 'possible', ensuring a correct result.
120-
for i := 0; i < len(filter.Fingerprints); i++ {
121-
filter.Fingerprints[i] = ^uint8(0)
122-
}
123-
return filter, nil
117+
// the cosmic-ray probability (i.e., a cosmic ray corrupts your system).
118+
return nil, errors.New("too many iterations")
124119
}
125120

126121
blockBits := 1
@@ -252,7 +247,7 @@ func PopulateBinaryFuse8(keys []uint64) (*BinaryFuse8, error) {
252247
// manage to remove them all. We may simply sort the key to
253248
// solve the issue. This will run in time O(n log n) and it
254249
// mutates the input.
255-
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
250+
keys = pruneDuplicates(keys)
256251
}
257252
for i := uint32(0); i < size; i++ {
258253
reverseOrder[i] = 0

binaryfusefilter_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/rand"
66
"testing"
77

8+
"github.com/cespare/xxhash"
89
"github.com/stretchr/testify/assert"
910
)
1011

@@ -305,3 +306,24 @@ func BenchmarkBinaryFuse8Contains50000000(b *testing.B) {
305306
binaryfusedbig.Contains(rand.Uint64())
306307
}
307308
}
309+
310+
func Test_Issue35(t *testing.T) {
311+
for test := 0; test < 100; test++ {
312+
hashes := make([]uint64, 0)
313+
for i := 0; i < 40000; i++ {
314+
v := encode(int32(rand.Intn(10)), int32(rand.Intn(100000)))
315+
hashes = append(hashes, xxhash.Sum64(v))
316+
}
317+
inner, err := PopulateBinaryFuse8(hashes)
318+
if err != nil {
319+
panic(err)
320+
}
321+
for i, d := range hashes {
322+
e := inner.Contains(d)
323+
if !e {
324+
panic(i)
325+
}
326+
327+
}
328+
}
329+
}

fusefilter.go

Lines changed: 0 additions & 207 deletions
This file was deleted.

0 commit comments

Comments
 (0)