Skip to content

Commit

Permalink
Fix collision panic in DeletableBloomFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
tylertreat committed May 8, 2018
1 parent 964ea14 commit e4c39d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deletable.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewDeletableBloomFilter(n, r uint, fpRate float64) *DeletableBloomFilter {
)
return &DeletableBloomFilter{
buckets: NewBuckets(m-r, 1),
collisions: NewBuckets(r, 1),
collisions: NewBuckets(r+1, 1),
hash: fnv.New64(),
m: m - r,
regionSize: (m - r) / r,
Expand Down
8 changes: 8 additions & 0 deletions deletable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func TestDeletableTestAndAdd(t *testing.T) {
}
}

// Ensures collisions do not cause a panic due to regionSize.
func TestDeletableCollisions(t *testing.T) {
d := NewDeletableBloomFilter(100, 120, 0.05)
for i := 0; i < 100; i++ {
d.Add([]byte(strconv.Itoa(i)))
}
}

// Ensures that TestAndRemove behaves correctly.
func TestDeletableTestAndRemove(t *testing.T) {
d := NewDeletableBloomFilter(100, 10, 0.1)
Expand Down

0 comments on commit e4c39d4

Please sign in to comment.