This is an automated email from the ASF dual-hosted git repository. tisonkun pushed a commit to branch hashable in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit d9bda5fdf8c61872ec695f423e31059c9afa3f88 Author: tison <[email protected]> AuthorDate: Thu May 7 00:47:04 2026 +0800 more convience Signed-off-by: tison <[email protected]> --- datasketches/src/hash_value.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/datasketches/src/hash_value.rs b/datasketches/src/hash_value.rs index 1b1439e..f45eae0 100644 --- a/datasketches/src/hash_value.rs +++ b/datasketches/src/hash_value.rs @@ -22,7 +22,7 @@ impl<T: Hash> HashValue<T> { } impl HashValue<u64> { - /// Create a `HashValue` from a f64 value using the canonical mapping. + /// Create a `HashValue` from a `f64` value using the canonical mapping. #[inline(always)] pub fn canonical_f64(value: f64) -> Self { HashValue { @@ -38,9 +38,22 @@ impl HashValue<u64> { } } - /// Create a `HashValue` from a f32 value using the canonical mapping. + /// Create a `HashValue` from a `f32` value using the canonical mapping. #[inline(always)] pub fn canonical_f32(value: f32) -> Self { HashValue::canonical_f64(value as f64) } } + +impl HashValue<i64> { + /// Create a `HashValue` from an `i8` value by casting the value to `i64`. + /// + /// This canonical mapping ensures that the same hash value is produced for the same numeric + /// value, regardless of the original type. For example, `HashValue::canonical_i8(42)` will + /// produce the same hash value as `HashValue::from_hash(42i64)`. + /// + /// This is compatible with datasketches-cpp's behavior. + pub fn canonical_i8(value: i8) -> Self { + HashValue { value: value as i64 } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
