[−][src]Module spatium::edit_based::hamming
Hamming implementation
Hamming distance
The Hamming distance between two strings of equal length is the number of positions at which two strings are different.
Examples
use spatium::edit_based::hamming; let alg = hamming::Default::default(); let x = [1, 2, 3]; let y = [1, 2, 4]; let distance = alg.distance(&x, &y).unwrap(); assert_eq!(distance, 1.0); // On &str. let x = "Hello-МИР"; let y = "Hello-ПИР"; let xc = x.chars().collect::<Vec<char>>(); let yc = y.chars().collect::<Vec<char>>(); let distance = alg.distance(&xc, &yc).unwrap(); assert_eq!(distance, 1.0); // With normaliztion (normalized distance = distance / x.len()) let alg = hamming::Default::default().normalize_result(true); let x = [1, 2, 3]; let y = [1, 2, 4]; let distance = alg.distance(&x, &y).unwrap(); assert_eq!(distance, 1.0 / 3.0);
References:
Some implementation
Re-exports
pub use hamming1::Hamming1; |
Modules
hamming1 | Hamming1 algorithm |
Type Definitions
Default | Default algorithm |