mirror of https://github.com/status-im/op-geth.git
removed old bloom
This commit is contained in:
parent
d56d0c64aa
commit
1025d097fd
|
@ -1,47 +0,0 @@
|
|||
package chain
|
||||
|
||||
type BloomFilter struct {
|
||||
bin []byte
|
||||
}
|
||||
|
||||
func NewBloomFilter(bin []byte) *BloomFilter {
|
||||
if bin == nil {
|
||||
bin = make([]byte, 256)
|
||||
}
|
||||
|
||||
return &BloomFilter{
|
||||
bin: bin,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *BloomFilter) Set(addr []byte) {
|
||||
if len(addr) < 8 {
|
||||
chainlogger.Warnf("err: bloom set to small: %x\n", addr)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
for _, i := range addr[len(addr)-8:] {
|
||||
self.bin[i] = 1
|
||||
}
|
||||
}
|
||||
|
||||
func (self *BloomFilter) Search(addr []byte) bool {
|
||||
if len(addr) < 8 {
|
||||
chainlogger.Warnf("err: bloom search to small: %x\n", addr)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for _, i := range addr[len(addr)-8:] {
|
||||
if self.bin[i] == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *BloomFilter) Bin() []byte {
|
||||
return self.bin
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package chain
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBloomFilter(t *testing.T) {
|
||||
bf := NewBloomFilter(nil)
|
||||
|
||||
a := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
|
||||
bf.Set(a)
|
||||
|
||||
b := []byte{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
|
||||
|
||||
if bf.Search(a) == false {
|
||||
t.Error("Expected 'a' to yield true using a bloom filter")
|
||||
}
|
||||
|
||||
if bf.Search(b) {
|
||||
t.Error("Expected 'b' not to field trie using a bloom filter")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue