[][src]Function nilsimsa::compare

pub fn compare(digest_a: &str, digest_b: &str) -> i16

Compare two hex digests with a Hamming distance calculation. Returns an i16 in the range [-128, 128] representing the similarity of the two input digests, where -128 is most dissimilar and 128 is most similar, or equal. The input strings must be of the same length.

let similar = compare(
    "42c82c184080082040001004000000084e1043b0c0925829003e84c860410010",
    "00480cba20810802408000000400000a481091b088b21e21003e840a20011016",
);
assert_eq!(similar, 90);

let very_dissimilar = compare(
    "51613b08c286b8054e09847c51928935289e623b63308db6b1606b0883804264",
    "1db4dd17fb93907f2dbb52a5d7dddc268f15545be7da0f75efcb0f9df7cc65b3",
);
assert_eq!(very_dissimilar, 1);