pub fn hamming<T: Int, U: UInt>(x: &[T], y: &[T]) -> U
Expand description
Computes the Hamming distance between two vectors.
The Hamming distance is defined as the number of positions at which the corresponding elements are different.
See the crate::vectors
module documentation for information on this
function’s potentially unexpected behaviors
§Arguments
x
: A slice of numbers.y
: A slice of numbers.
§Examples
use distances::vectors::hamming;
let x: Vec<u8> = vec![1, 2, 3];
let y: Vec<u8> = vec![1, 2, 3];
let distance: u8 = hamming(&x, &y);
assert_eq!(distance, 0);
let x: Vec<u8> = vec![1, 2, 3];
let y: Vec<u8> = vec![1, 2, 4];
let distance: u8 = hamming(&x, &y);
assert_eq!(distance, 1);