Expand description
Distance functions for binary vectors.
This module provides efficient distance calculations for bit-packed binary vectors using hardware popcount instructions.
§Hamming Distance
Hamming distance counts the number of positions where corresponding bits differ. It’s computed efficiently using XOR (to find differing bits) followed by popcount (to count them).
Modern CPUs provide hardware popcount instructions:
- x86/x86_64: POPCNT instruction (SSE4.2+)
- ARM: CNT instruction (NEON)
Rust’s u64::count_ones() automatically uses these intrinsics when available.
Enums§
- Binary
Distance Metric - Distance metric for comparing binary vectors.
Functions§
- hamming_
distance - Calculate the Hamming distance between two binary embeddings.
- hamming_
distance_ normalized - Calculate the normalized Hamming distance (Hamming distance / dimension).
- hamming_
distance_ raw - Calculate the Hamming distance between two raw u64 slices.
- jaccard_
distance - Calculate the Jaccard distance between two binary embeddings.
- jaccard_
similarity - Calculate the Jaccard similarity between two binary embeddings.