From b97f002b10dfe21047d130acf2e4f6d3f77779c4 Mon Sep 17 00:00:00 2001 From: jojii Date: Mon, 16 Aug 2021 22:34:43 +0200 Subject: [PATCH] add From for Hash --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7ef90e2..1fd33fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,14 @@ impl Into for Hash { } } +/// Get a `Hash` value from its hash value. +impl From for Hash { + #[inline] + fn from(hash: u64) -> Self { + Hash { hash } + } +} + /// Calculate the difference of two hashes. impl ops::Sub for Hash { type Output = Difference; @@ -105,7 +113,7 @@ impl Difference { #[inline] pub fn dist(self) -> u32 { (self.xor as u8).count_ones() as u32 - + ((self.xor >> 8 ) as u8).count_ones() as u32 * 2 + + ((self.xor >> 8) as u8).count_ones() as u32 * 2 + ((self.xor >> 16) as u8).count_ones() as u32 * 3 + ((self.xor >> 24) as u8).count_ones() as u32 * 5 + ((self.xor >> 32) as u8).count_ones() as u32 * 8