Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

fix: switch murmur3 implementation #222

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ctrlc = "3.2.4"
db = { package = "forest_db", version = "0.2.0", git = "https://github.com/theBeardA/forest-rocksdb", branch = "chore/upgrade-db", features = ["rocksdb"] }
dirs = "4"
dotenv = "0.15.0"
fasthash = "0.4.0"
fastmurmur3 = "0.1.2"
fnv = "1.0.7"
futures = "0.3.25"
futures-util = "0.3.25"
Expand Down
2 changes: 1 addition & 1 deletion crates/ursa-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bytes.workspace = true
cid.workspace = true
db.workspace = true
dirs.workspace = true
fasthash.workspace = true
fastmurmur3.workspace = true
fnv.workspace = true
futures.workspace = true
futures-util.workspace = true
Expand Down
12 changes: 6 additions & 6 deletions crates/ursa-network/src/utils/bloom_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ impl CountingBloomFilter {

pub fn insert<T: AsRef<[u8]>>(&mut self, value: &T) {
for i in 0..self.num_hashes {
let hash = fasthash::murmur3::hash32_with_seed(value, i as u32);
let index = (hash % (self.buckets.len() as u32)) as usize;
let hash = fastmurmur3::murmur3_x64_128(value.as_ref(), i as u32);
let index = (hash % (self.buckets.len() as u128)) as usize;
let count = self.buckets.get_mut(index).unwrap();
*count = count.saturating_add(1);
}
Expand All @@ -34,8 +34,8 @@ impl CountingBloomFilter {
#[allow(dead_code)]
pub fn contains<T: AsRef<[u8]>>(&self, value: &T) -> bool {
for i in 0..self.num_hashes {
let hash = fasthash::murmur3::hash32_with_seed(value, i as u32);
let index = (hash % (self.buckets.len() as u32)) as usize;
let hash = fastmurmur3::murmur3_x64_128(value.as_ref(), i as u32);
let index = (hash % (self.buckets.len() as u128)) as usize;
if self.buckets.get(index).unwrap() == &0u8 {
return false;
}
Expand All @@ -49,8 +49,8 @@ impl CountingBloomFilter {
return Err(anyhow!("Element does not exist."));
}
for i in 0..self.num_hashes {
let hash = fasthash::murmur3::hash32_with_seed(value, i as u32);
let index = (hash % (self.buckets.len() as u32)) as usize;
let hash = fastmurmur3::murmur3_x64_128(value.as_ref(), i as u32);
let index = (hash % (self.buckets.len() as u128)) as usize;
let count = self.buckets.get_mut(index).unwrap();
*count = count.saturating_sub(1);
}
Expand Down