From 885fe38c01d7ca1923f1f649b2a42da0e8f57d73 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 10 Jan 2019 11:05:46 -0700 Subject: [PATCH] Move BloomHashIndex into its own module This trait is for bloom, not crds. Slightly better would be to put it in the SDK so that the trait implementations could go into hash and pubkey, but if we don't want compatibility constraints, this is the next best thing. --- src/bloom.rs | 7 +------ src/{crds_traits_impls.rs => bloom_hash_index.rs} | 7 ++++++- src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/{crds_traits_impls.rs => bloom_hash_index.rs} (75%) diff --git a/src/bloom.rs b/src/bloom.rs index fed8a16548..3c59713ac0 100644 --- a/src/bloom.rs +++ b/src/bloom.rs @@ -1,15 +1,10 @@ //! Simple Bloom Filter +use crate::bloom_hash_index::BloomHashIndex; use bv::BitVec; use rand::{self, Rng}; use std::cmp; use std::marker::PhantomData; -/// Generate a stable hash of `self` for each `hash_index` -/// Best effort can be made for uniqueness of each hash. -pub trait BloomHashIndex { - fn hash(&self, hash_index: u64) -> u64; -} - #[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)] pub struct Bloom { pub keys: Vec, diff --git a/src/crds_traits_impls.rs b/src/bloom_hash_index.rs similarity index 75% rename from src/crds_traits_impls.rs rename to src/bloom_hash_index.rs index a885e43b9d..a6c4931937 100644 --- a/src/crds_traits_impls.rs +++ b/src/bloom_hash_index.rs @@ -1,4 +1,3 @@ -use crate::bloom::BloomHashIndex; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; @@ -13,6 +12,12 @@ fn slice_hash(slice: &[u8], hash_index: u64) -> u64 { rv } +/// Generate a stable hash of `self` for each `hash_index` +/// Best effort can be made for uniqueness of each hash. +pub trait BloomHashIndex { + fn hash(&self, hash_index: u64) -> u64; +} + impl BloomHashIndex for Pubkey { fn hash(&self, hash_index: u64) -> u64 { slice_hash(self.as_ref(), hash_index) diff --git a/src/lib.rs b/src/lib.rs index 853bb0fc72..dadd32d352 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ pub mod bank; pub mod banking_stage; pub mod blob_fetch_stage; pub mod bloom; +pub mod bloom_hash_index; pub mod broadcast_service; #[cfg(feature = "chacha")] pub mod chacha; @@ -26,7 +27,6 @@ pub mod crds_gossip; pub mod crds_gossip_error; pub mod crds_gossip_pull; pub mod crds_gossip_push; -pub mod crds_traits_impls; pub mod crds_value; #[macro_use] pub mod contact_info;