1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! The one distance metric the kit specifies: Hamming distance between
//! digests.
use crateDigest;
/// Widens a byte chunk to `u64`, first byte most significant. A chunk
/// shorter than eight bytes is zero-padded on the right; when both
/// sides are widened, as [`hamming`] does, the padding is identical and
/// cancels out in the XOR.
/// The number of differing bits between two digests.
///
/// This is the single comparison used by every perceptual crate and the
/// index layer, so it is specified once, here. It walks eight bytes at
/// a time and counts with `u64::count_ones` — one `POPCNT`-class
/// instruction per stride, never a per-bit loop; the tail of fewer than
/// eight bytes is widened and counted the same way.
///
/// ```
/// let a = pith_digest::Digest::<1>::from_bytes([0b0000_1111]);
/// let b = pith_digest::Digest::<1>::from_bytes([0b0000_0001]);
/// assert_eq!(pith_digest::hamming(&a, &b), 3);
/// ```