summaryrefslogtreecommitdiffstats
path: root/src/hamming.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/hamming.rs')
-rw-r--r--src/hamming.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/hamming.rs b/src/hamming.rs
index c6822ee..da959b4 100644
--- a/src/hamming.rs
+++ b/src/hamming.rs
@@ -25,6 +25,13 @@ impl<T> Hamming<T> {
}
/// Compute the Hamming distance between two integers.
+///
+/// ```math
+/// \begin{aligned}
+/// \mathrm{hamming\_distance}(x, y) &= |\{i \mid x_i \ne y_i\}| \\
+/// &= \mathrm{popcount}(x \wedge y)
+/// \end{aligned}
+/// ```
pub fn hamming_distance<T: PrimInt>(x: T, y: T) -> i32 {
(x ^ y).count_ones() as i32
}