mod binary_ivf;
mod ivf_pq;
mod ivf_rabitq;
mod rabitq;
pub use binary_ivf::{BinaryIvfConfig, BinaryIvfIndex};
pub use ivf_pq::{IVFPQConfig, IVFPQIndex};
pub use ivf_rabitq::{IVFRaBitQConfig, IVFRaBitQIndex};
pub use rabitq::RaBitQIndex;
pub(crate) fn dedup_multi_assigned(candidates: &mut Vec<(u32, u16, f32)>) {
if candidates.len() < 2 {
return;
}
candidates.sort_unstable_by(|a, b| {
(a.0, a.1)
.cmp(&(b.0, b.1))
.then_with(|| a.2.total_cmp(&b.2))
});
candidates.dedup_by_key(|c| (c.0, c.1));
}
pub(crate) fn finalize_candidates(
candidates: &mut Vec<(u32, u16, f32)>,
k: usize,
dedup_spilled: bool,
) {
if dedup_spilled {
dedup_multi_assigned(candidates);
}
if candidates.len() > k {
candidates.select_nth_unstable_by(k, |a, b| a.2.partial_cmp(&b.2).unwrap());
candidates.truncate(k);
}
candidates.sort_unstable_by(|a, b| a.2.partial_cmp(&b.2).unwrap());
}