From 39aec525909daad1439e3bb88d2ddd27116d1488 Mon Sep 17 00:00:00 2001 From: Matthias Wright Date: Mon, 2 Jan 2023 15:38:59 +0100 Subject: [PATCH] fix: switch murmur3 implementation --- Cargo.toml | 2 +- crates/ursa-network/Cargo.toml | 2 +- crates/ursa-network/src/utils/bloom_filter.rs | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 433d288f..7d63eb6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/ursa-network/Cargo.toml b/crates/ursa-network/Cargo.toml index e5c840b1..87cad3cd 100644 --- a/crates/ursa-network/Cargo.toml +++ b/crates/ursa-network/Cargo.toml @@ -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 diff --git a/crates/ursa-network/src/utils/bloom_filter.rs b/crates/ursa-network/src/utils/bloom_filter.rs index e2809a8e..fd3baa24 100644 --- a/crates/ursa-network/src/utils/bloom_filter.rs +++ b/crates/ursa-network/src/utils/bloom_filter.rs @@ -24,8 +24,8 @@ impl CountingBloomFilter { pub fn insert>(&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); } @@ -34,8 +34,8 @@ impl CountingBloomFilter { #[allow(dead_code)] pub fn contains>(&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; } @@ -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); }