Skip to main content

batch

Function batch 

Source
pub fn batch(source: &[u8], targets: &[&[u8]], out: &mut [u32])
Expand description

Compute Hamming distance from one source slice to many target slices (one-to-many).

Faster than calling distance in a loop for one-to-many comparisons.

§Panics

Panics if out.len() != targets.len() or any target has a different length than source.

§Example

use hamming_bitwise_fast::slice;

let source = vec![0u8; 128];
let targets_owned: Vec<Vec<u8>> = vec![vec![1u8; 128], vec![2u8; 128]];
let targets: Vec<&[u8]> = targets_owned.iter().map(|v| v.as_slice()).collect();
let mut distances = vec![0u32; 2];  // pre-allocate and reuse

slice::batch(&source, &targets, &mut distances);