| 50 | } |
| 51 | |
| 52 | pub fn push(&mut self, vector: [u8; QUANTIZED_VECTOR_SIZE]) -> io::Result<usize> { |
| 53 | let offset = self.used_space + HEADER_SIZE; |
| 54 | let required_space = offset + QUANTIZED_VECTOR_SIZE; |
| 55 | |
| 56 | if required_space > self.mmap.len() { |
| 57 | self.resize_mmap(required_space * 2)?; |
| 58 | } |
| 59 | |
| 60 | self.mmap[offset..required_space].copy_from_slice(&vector); |
| 61 | self.used_space += QUANTIZED_VECTOR_SIZE; |
| 62 | // Update the header in the mmap |
| 63 | self.mmap[0..HEADER_SIZE].copy_from_slice(&(self.used_space as u64).to_le_bytes()); |
| 64 | |
| 65 | Ok(self.used_space / QUANTIZED_VECTOR_SIZE - 1) |
| 66 | } |
| 67 | |
| 68 | fn resize_mmap(&mut self, new_len: usize) -> io::Result<()> { |
| 69 | println!("Resizing mmap in DenseVectorList"); |