(
&mut self,
vectors: Vec<[u8; QUANTIZED_VECTOR_SIZE]>,
)
| 80 | } |
| 81 | |
| 82 | pub fn batch_push( |
| 83 | &mut self, |
| 84 | vectors: Vec<[u8; QUANTIZED_VECTOR_SIZE]>, |
| 85 | ) -> io::Result<Vec<usize>> { |
| 86 | let start_offset = self.used_space + HEADER_SIZE; |
| 87 | let total_size = vectors.len() * QUANTIZED_VECTOR_SIZE; |
| 88 | let required_space = start_offset + total_size; |
| 89 | |
| 90 | // println!( |
| 91 | // "Required space: {}, mmap len: {}", |
| 92 | // required_space, |
| 93 | // self.mmap.len() |
| 94 | // ); |
| 95 | |
| 96 | if required_space > self.mmap.len() { |
| 97 | self.resize_mmap(required_space * 2)?; |
| 98 | } |
| 99 | |
| 100 | // println!("Batch push"); |
| 101 | |
| 102 | for (i, vector) in vectors.iter().enumerate() { |
| 103 | let offset = start_offset + i * QUANTIZED_VECTOR_SIZE; |
| 104 | self.mmap[offset..offset + QUANTIZED_VECTOR_SIZE].copy_from_slice(vector); |
| 105 | } |
| 106 | |
| 107 | // println!("Batch push done"); |
| 108 | |
| 109 | self.used_space += total_size; |
| 110 | // Update the header in the mmap |
| 111 | self.mmap[0..HEADER_SIZE].copy_from_slice(&(self.used_space as u64).to_le_bytes()); |
| 112 | |
| 113 | Ok((((start_offset - HEADER_SIZE) / QUANTIZED_VECTOR_SIZE) |
| 114 | ..(self.used_space / QUANTIZED_VECTOR_SIZE)) |
| 115 | .collect()) |
| 116 | } |
| 117 | |
| 118 | pub fn get(&self, index: usize) -> io::Result<&[u8; QUANTIZED_VECTOR_SIZE]> { |
| 119 | let offset = HEADER_SIZE + index * QUANTIZED_VECTOR_SIZE; |
no test coverage detected