use super::rabitq::RaBitQCorrection;
#[derive(Debug)]
#[allow(dead_code)] pub struct RaBitQVectorStore {
bits_data: Vec<u64>,
corrections: Vec<RaBitQCorrection>,
words_per_vector: usize,
dimension: usize,
count: usize,
}
#[allow(dead_code)] impl RaBitQVectorStore {
#[must_use]
pub fn new(dimension: usize, capacity: usize) -> Self {
let words_per_vector = dimension.div_ceil(64);
Self {
bits_data: Vec::with_capacity(capacity * words_per_vector),
corrections: Vec::with_capacity(capacity),
words_per_vector,
dimension,
count: 0,
}
}
pub fn push(&mut self, bits: &[u64], correction: RaBitQCorrection) {
debug_assert_eq!(bits.len(), self.words_per_vector);
self.bits_data.extend_from_slice(bits);
self.corrections.push(correction);
self.count += 1;
}
#[must_use]
pub fn get_bits_slice(&self, index: usize) -> Option<&[u64]> {
if index >= self.count {
return None;
}
let start = index * self.words_per_vector;
let end = start + self.words_per_vector;
Some(&self.bits_data[start..end])
}
#[must_use]
pub fn get_correction(&self, index: usize) -> Option<&RaBitQCorrection> {
self.corrections.get(index)
}
#[inline]
pub fn prefetch(&self, index: usize) {
if index < self.count {
let start = index * self.words_per_vector;
crate::simd_native::prefetch_vector_u64(&self.bits_data[start..]);
}
}
#[must_use]
pub fn len(&self) -> usize {
self.count
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.count == 0
}
#[must_use]
pub fn dimension(&self) -> usize {
self.dimension
}
}
#[cfg(test)]
#[path = "rabitq_store_tests.rs"]
mod tests;