Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use murmur3 for hashing #18

Merged
merged 1 commit into from
Dec 9, 2024
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 optimizely/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
serde_json = "1.0"
thiserror = "1.0"
error-stack = "0.5"
fasthash = "0.4"
murmur3 = "0.5.2"
log = "0.4"

[dependencies.serde]
Expand Down
5 changes: 3 additions & 2 deletions optimizely/src/client/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// External imports
use fasthash::murmur3::hash32_with_seed as murmur3_hash;
use murmur3::murmur3_32 as murmur3_hash;
use std::collections::HashMap;

// Imports from crate
Expand Down Expand Up @@ -223,7 +223,8 @@ impl UserContext<'_> {

// To hash the bucket key it needs to be converted to an array of `u8` bytes
// Use Murmur3 (32-bit) with seed
let hash_value = murmur3_hash(bucketing_key.as_bytes(), HASH_SEED);
let mut bytes = bucketing_key.as_bytes();
let hash_value = murmur3_hash(&mut bytes, HASH_SEED).unwrap();

// Bring the hash into a range of 0 to 10_000
let bucket_value = ((hash_value as f64) / (u32::MAX as f64) * MAX_OF_RANGE) as u64;
Expand Down
Loading