Skip to content

Commit

Permalink
swap hashing crates
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzwilksch committed Nov 27, 2024
1 parent 0743e7a commit 921999a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions polars_hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ sha1 = { version = "0.10.6" }
sha2 = { version = "0.10.8" }
sha3 = { version = "0.10.8" }
blake3 = { version = "1.5.4" }
md5 = {version = "0.7.0"}
md5 = { version = "0.7.0" }
h3o = { version = "0.6.4" }
fasthash = "0.4.0"
xxhash-rust = { version = "0.8.12", features = ["xxh32", "xxh64"] }
mur3 = { version = "0.1.0" }


[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
21 changes: 14 additions & 7 deletions polars_hash/src/fasthash_hashers.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
use fasthash::{murmur3, xx};
use mur3::murmurhash3_x64_128;
use mur3::murmurhash3_x86_32;
use xxhash_rust::xxh32::xxh32;
use xxhash_rust::xxh64::xxh64;

pub fn murmurhash3_32(value: Option<&str>, seed: u32) -> Option<u32> {
value.map(|v| murmur3::hash32_with_seed(v.as_bytes(), seed))
value.map(|v| murmurhash3_x86_32(v.as_bytes(), seed))
}

pub fn murmurhash3_128(value: Option<&str>, seed: u32) -> Option<Vec<u8>> {
value.map(|v| {
murmur3::hash128_with_seed(v.as_bytes(), seed)
.to_le_bytes()
.to_vec()
let mut result = Vec::new();
let hash = murmurhash3_x64_128(v.as_bytes(), seed);

result.extend_from_slice(hash.0.to_le_bytes().as_ref());
result.extend_from_slice(hash.1.to_le_bytes().as_ref());

result
})
}

pub fn xxhash_32(value: Option<&str>, seed: u32) -> Option<u32> {
value.map(|v| xx::hash32_with_seed(v.as_bytes(), seed))
value.map(|v| xxh32(v.as_bytes(), seed))
}

pub fn xxhash_64(value: Option<&str>, seed: u64) -> Option<u64> {
value.map(|v| xx::hash64_with_seed(v.as_bytes(), seed))
value.map(|v| xxh64(v.as_bytes(), seed))
}

0 comments on commit 921999a

Please sign in to comment.