Merge pull request #297 from status-im/update_bloom

make 'bloom.contains' public
This commit is contained in:
andri lim 2020-09-30 13:03:57 +07:00 committed by GitHub
commit d9e57e4d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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