1use crate::hamdist;
2use crate::CodeInt;
3
4pub fn range_search<T: CodeInt>(codes: &[T], qcode: T, radius: usize) -> Vec<u32> {
7 let mut answers = Vec::<u32>::with_capacity(1 << 8);
8 range_search_with_buf(codes, qcode, radius, &mut answers);
9 answers
10}
11
12pub fn range_search_with_buf<T: CodeInt>(
15 codes: &[T],
16 qcode: T,
17 radius: usize,
18 answers: &mut Vec<u32>,
19) {
20 answers.clear();
21 for (i, &code) in codes.iter().enumerate() {
22 let dist = hamdist(code, qcode);
23 if dist <= radius {
24 answers.push(i as u32);
25 }
26 }
27}
28
29pub fn exhaustive_search<T: CodeInt>(codes: &[T], qcode: T) -> Vec<(u32, u32)> {
32 let mut answers = Vec::<(u32, u32)>::new();
33 exhaustive_search_with_buf(codes, qcode, &mut answers);
34 answers
35}
36
37pub fn exhaustive_search_with_buf<T: CodeInt>(
40 codes: &[T],
41 qcode: T,
42 answers: &mut Vec<(u32, u32)>,
43) {
44 answers.resize(codes.len(), Default::default());
45 for i in 0..codes.len() {
46 let dist = hamdist(codes[i], qcode);
47 answers[i] = (i as u32, dist as u32);
48 }
49}