From 3a2d4e684da97fbc4760011e3d20b5613327d34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20d=27Herbais=20de=20Thun=20=28Dherse=29?= Date: Fri, 17 Nov 2023 16:43:19 +0100 Subject: [PATCH] Add `finish_u128` to `hasher.rs` --- Cargo.toml | 2 +- src/hasher.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ebad45c..522907a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/hasher.rs b/src/hasher.rs index ca1390b..60c4075 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -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::() >= std::mem::size_of::()); + + unsafe { + let p = &self.0 as *const State as *const u128; + *p + } + } } impl Hasher for GxHasher {