diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-11 22:23:17 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-11 22:23:17 +0800 |
commit | 2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3 (patch) | |
tree | 9bf393d0aef53672594274359b4e0f23e2a69d8d /ethchain/bloom.go | |
parent | 42d2bc28affe9bbd8d57a5eb3deab804e5c4a206 (diff) | |
download | dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar.gz dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar.bz2 dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar.lz dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar.xz dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.tar.zst dexon-2e5d28c73f1d97865def3ffe8c7ad0a4819f15f3.zip |
Added bloom filter & block filter methods
Diffstat (limited to 'ethchain/bloom.go')
-rw-r--r-- | ethchain/bloom.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/ethchain/bloom.go b/ethchain/bloom.go new file mode 100644 index 000000000..320ce73fc --- /dev/null +++ b/ethchain/bloom.go @@ -0,0 +1,47 @@ +package ethchain + +type BloomFilter struct { + bin []byte +} + +func NewBloomFilter(bin []byte) *BloomFilter { + if bin == nil { + bin = make([]byte, 255) + } + + 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 +} |