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

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.

(cherry picked from commit bb183938d9)

Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
mergify[bot]
2020-09-24 19:49:10 +00:00
committed by GitHub
parent 0213016999
commit c44f6981b1
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.