diff --git a/common/expbloom/bloom_test.go b/common/expbloom/bloom_test.go index 35eaf15136..6d5011692b 100644 --- a/common/expbloom/bloom_test.go +++ b/common/expbloom/bloom_test.go @@ -1,44 +1,28 @@ package bloom import ( + "encoding/binary" "testing" "time" ) -type hashable struct { - b []byte -} - -func (h hashable) BlockSize() int { - return len(h.b) -} - -func (h hashable) Hash() []byte { - return h.b -} - -func (h hashable) Sum([]byte) []byte { - return h.b -} +type hashable []byte +func (h hashable) Write(p []byte) (n int, err error) { panic("not implemented") } +func (h hashable) Sum(b []byte) []byte { panic("not implemented") } +func (h hashable) Reset() { panic("not implemented") } +func (h hashable) BlockSize() int { panic("not implemented") } +func (h hashable) Size() int { return 8 } func (h hashable) Sum64() uint64 { - return 1 -} - -func (h hashable) Write([]byte) (int, error) { - return 0, nil -} - -func (h hashable) Reset() {} - -func (h hashable) Size() int { - return len(h.b) + hash := make([]byte, 8) + copy(hash, h) + return binary.BigEndian.Uint64(hash[0:8]) } func TestBloom(t *testing.T) { bloom, _ := NewExpiringBloom(3, 1024, 10*time.Millisecond) - testKey := hashable{[]byte{0x01}} + testKey := hashable([]byte{0x01}) bloom.Add(testKey) if !bloom.Contains(testKey) { t.Fatal() @@ -60,7 +44,7 @@ func TestBloom(t *testing.T) { func TestBloom2(t *testing.T) { bloom, _ := NewExpiringBloom(3, 1024, 10*time.Second) - testKey := hashable{[]byte{0x01}} + testKey := hashable([]byte{0x01}) // Add key in bloom 0 bloom.Add(testKey) if !bloom.Contains(testKey) { @@ -86,7 +70,7 @@ func TestBloom2(t *testing.T) { func BenchmarkAdd(b *testing.B) { bloom, _ := NewExpiringBloom(2, 1024, 10*time.Second) - testKey := hashable{[]byte{0x01}} + testKey := hashable([]byte{0x01}) for i := 0; i < b.N; i++ { bloom.Add(testKey) }