Skip to content

Commit f2f0690

Browse files
committed
remove manual fnv
1 parent e9e89a8 commit f2f0690

File tree

2 files changed

+0
-43
lines changed

2 files changed

+0
-43
lines changed

bloom.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package gobloomgo
22

33
import (
4-
"bytes"
5-
"encoding/gob"
64
"fmt"
75
"log"
86
"math"
@@ -53,8 +51,6 @@ func NewBloom(err_rate float64, capacity int, database Store) *BloomFilter {
5351
panic("Capacity must be greater than 0")
5452
}
5553

56-
// P = err_rate
57-
5854
// number of hash functions (k)
5955
numHashFn := int(math.Ceil(math.Log2(1.0 / err_rate)))
6056

@@ -187,31 +183,3 @@ func (bf *BloomFilter) Count() int {
187183
func (bf *BloomFilter) FilterSize() int {
188184
return bf.bit_width
189185
}
190-
191-
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
192-
// fnvHash implements the Fowler–Noll–Vo hash function
193-
func fnvHash(key string) (int64, error) {
194-
var offsetBasis, fnvPrime int64
195-
offsetBasis = math.MaxInt64
196-
fnvPrime = 0x100000001b3
197-
hash := offsetBasis
198-
199-
buf := new(bytes.Buffer)
200-
enc := gob.NewEncoder(buf)
201-
err := enc.Encode(&key)
202-
if err != nil {
203-
return 0, err
204-
}
205-
206-
for i := 0; i < buf.Len(); i++ {
207-
b, err := buf.ReadByte()
208-
if err != nil {
209-
return 0, err
210-
}
211-
hash = hash * fnvPrime
212-
hash = int64(uint8(hash>>8) ^ uint8(b))
213-
}
214-
215-
return hash, nil
216-
217-
}

bloom_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ func BadgerDBSetupTest(t *testing.T) (Store, func()) {
3030
}
3131
}
3232

33-
func TestFnvHash(t *testing.T) {
34-
35-
t.Run("success", func(t *testing.T) {
36-
val := "hello"
37-
_, err := fnvHash(val)
38-
if err != nil {
39-
t.Errorf("error occured when fnvHash(%s) : %s", val, err)
40-
}
41-
})
42-
}
43-
4433
func TestBloomFilter_Add(t *testing.T) {
4534
bf := NewBloom(0.01, 1000, nil)
4635

0 commit comments

Comments
 (0)