adds an atomic variant of the bloom filter (#12422)

For crds_gossip_pull, we want to parallelize build_crds_filters, which
requires concurrent writes to bloom filters.

This commit implements a variant of the bloom filter which uses atomics
for its bits vector and so is thread-safe.
This commit is contained in:
behzad nouri
2020-09-24 18:37:19 +00:00
committed by GitHub
parent 42f1ef8acb
commit bb183938d9
3 changed files with 209 additions and 1 deletions

View File

@ -88,6 +88,17 @@ impl Hash {
pub fn to_bytes(self) -> [u8; HASH_BYTES] {
self.0
}
/// New random hash value for tests and benchmarks.
#[cfg(not(feature = "program"))]
pub fn new_rand<R: ?Sized>(rng: &mut R) -> Self
where
R: rand::Rng,
{
let mut buf = [0u8; HASH_BYTES];
rng.fill(&mut buf);
Hash::new(&buf)
}
}
/// Return a Sha256 hash for the given data.