Function distance::hamming [] [src]

pub fn hamming(s: &str, t: &str) -> Result<usize, DistanceError>

Calculates the Hamming distance between two strings of equal length.

Hamming distance

The Hamming distance between two strings of equal length is the number of positions at which two strings are different. This returns an error of type DistanceError::InvalidArgs if the string arguments do not have equal length. This implementation does fully support unicode strings.

Complexity

Time complexity: O(n) Space complexity: O(1)

Examples

use distance::*;
 
// Hamming distance
let distance = hamming("karolin", "kathrin").unwrap();   
assert_eq!(3, distance);