From 8580f607d25341291c212f71afc84d32080726c9 Mon Sep 17 00:00:00 2001 From: Henning Kowalk Date: Sun, 14 May 2017 23:14:16 +0200 Subject: [PATCH] optimized hamming distance calculation (#1) Merging pull request with hamming distance optimization. --- src/hash/mod.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/hash/mod.rs b/src/hash/mod.rs index 4cb40ae..482a182 100644 --- a/src/hash/mod.rs +++ b/src/hash/mod.rs @@ -233,14 +233,5 @@ pub fn calculate_hamming_distance(hash1: u64, hash2: u64) -> u64 { // The binary xor of the two hashes should give us a number representing // the differences between the two hashes. All that's left is to count // the number of 1's in the difference to determine the hamming distance - let bin_diff = hash1 ^ hash2; - let bin_diff_str = format!("{:b}", bin_diff); - let mut hamming = 0u64; - for bit in bin_diff_str.chars() { - match bit { - '1' => hamming += 1, - _ => continue, - } - } - hamming + (hash1 ^ hash2).count_ones() as u64 }