Skip to content

Commit

Permalink
Add finish_u128 to hasher.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dherse authored and ogxd committed Nov 17, 2023
1 parent b2b9d24 commit 3a2d4e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "gxhash"
authors = ["Olivier Giniaux"]
version = "2.0.0"
version = "2.1.0"
edition = "2021"
description = "GxHash non-cryptographic algorithm"
license = "MIT"
Expand Down
12 changes: 12 additions & 0 deletions src/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ impl GxHasher {
// Use gxhash64 to generate an initial state from a seed
GxHasher(unsafe { gxhash(&[], create_seed(seed)) })
}

/// Finish this hasher and return the hashed value as a 128 bit
/// unsigned integer.
#[inline]
fn finish_u128(&self) -> u128 {
debug_assert!(std::mem::size_of::<State>() >= std::mem::size_of::<u128>());

unsafe {
let p = &self.0 as *const State as *const u128;
*p
}
}
}

impl Hasher for GxHasher {
Expand Down

0 comments on commit 3a2d4e6

Please sign in to comment.