MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / hamming_distance

Function hamming_distance

nodedb-vector/src/quantize/binary.rs:45–52  ·  view source on GitHub ↗
(a: &[u8], b: &[u8])

Source from the content-addressed store, hash-verified

43/// POPCNT on x86_64).
44#[inline]
45pub fn hamming_distance(a: &[u8], b: &[u8]) -> u32 {
46 debug_assert_eq!(a.len(), b.len());
47 let mut dist = 0u32;
48 for i in 0..a.len() {
49 dist += (a[i] ^ b[i]).count_ones();
50 }
51 dist
52}
53
54/// Hamming distance operating on u64 chunks for better throughput.
55///

Callers 5

distance_preparedMethod · 0.50
distance_preparedMethod · 0.50

Calls 2

count_onesMethod · 0.80
lenMethod · 0.45

Tested by 1