Module binary

Module binary 

Source
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§

BinaryDistanceMetric
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.