mirror of https://github.com/status-im/nim-eth.git
Merge pull request #297 from status-im/update_bloom
make 'bloom.contains' public
This commit is contained in:
commit
d9e57e4d1a
|
@ -19,15 +19,18 @@ iterator bloomBits(h: MDigest[256]): UInt2048 =
|
|||
type BloomFilter* = object
|
||||
value*: UInt2048
|
||||
|
||||
proc incl(f: var BloomFilter, h: MDigest[256]) = # Should this be public?
|
||||
proc incl*(f: var BloomFilter, h: MDigest[256]) =
|
||||
for bits in bloomBits(h):
|
||||
f.value = f.value or bits
|
||||
|
||||
proc init*(_: type BloomFilter, h: MDigest[256]): BloomFilter =
|
||||
result.incl(h)
|
||||
|
||||
# TODO: The following 2 procs should be one genric, but it doesn't compile. Nim bug?
|
||||
proc incl*(f: var BloomFilter, v: string) = f.incl(keccak256.digest(v))
|
||||
proc incl*(f: var BloomFilter, v: openarray[byte]) = f.incl(keccak256.digest(v))
|
||||
|
||||
proc contains(f: BloomFilter, h: MDigest[256]): bool = # Should this be public?
|
||||
proc contains*(f: BloomFilter, h: MDigest[256]): bool =
|
||||
for bits in bloomBits(h):
|
||||
if (f.value and bits).isZero: return false
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue