Skip to content

Commit

Permalink
Adjust IntSeqDecoder API (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyb0807 authored Jan 5, 2025
1 parent 7833a39 commit 018c91e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 1 addition & 4 deletions rs/compression/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ pub trait IntSeqDecoder {
type Item;

/// Creates a decoder
fn new_decoder(byte_slice: &[u8]) -> Self
fn new_decoder(byte_slice: &[u8]) -> Result<Self>
where
Self: Sized;

/// Creates an iterator that iterates the encoded data and decodes one element at a time on the
/// fly
fn get_iterator<'a>(&self, encoded_data: &'a [u8]) -> Self::IteratorType<'a>;

/// Returns the number of elements in the sequence
fn num_elem(&self) -> usize;
}
16 changes: 9 additions & 7 deletions rs/compression/src/noc/noc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ pub struct PlainDecoder {
size: usize,
}

impl PlainDecoder {
pub fn num_elem(&self) -> usize {
self.size / std::mem::size_of::<<PlainDecoder as IntSeqDecoder>::Item>()
}
}

impl IntSeqDecoder for PlainDecoder {
type IteratorType<'a> = PlainDecodingIterator<'a>;
type Item = u64;

fn new_decoder(encoded_data: &[u8]) -> Self {
Self {
fn new_decoder(encoded_data: &[u8]) -> Result<Self> {
Ok(Self {
size: encoded_data.len(),
}
})
}

fn get_iterator<'a>(&self, encoded_data: &'a [u8]) -> PlainDecodingIterator<'a> {
Expand All @@ -80,10 +86,6 @@ impl IntSeqDecoder for PlainDecoder {
encoded_data_ptr: utils::mem::transmute_u8_to_slice(encoded_data),
}
}

fn num_elem(&self) -> usize {
self.size / std::mem::size_of::<Self::Item>()
}
}

pub struct PlainDecodingIterator<'a> {
Expand Down
3 changes: 2 additions & 1 deletion rs/index/src/ivf/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ impl<Q: Quantizer, DC: DistanceCalculator, D: IntSeqDecoder<Item = u64>> Ivf<Q,
if let Ok(byte_slice) = self.index_storage.get_posting_list(centroid) {
let quantized_query = Q::QuantizedT::process_vector(query, &self.quantizer);
let mut results: Vec<IdWithScore> = Vec::new();
let decoder = D::new_decoder(byte_slice);
let decoder =
D::new_decoder(byte_slice).expect("Failed to create posting list decoder");
for idx in decoder.get_iterator(byte_slice) {
match self.vector_storage.get(idx as usize, context) {
Some(vector) => {
Expand Down

0 comments on commit 018c91e

Please sign in to comment.