Finds or creates the node where the data should be inserted. Traverses the tree iteratively and returns a reference to the node.
(&self, path: &[u8], mut offset_fn: impl FnMut() -> u32)
| 213 | /// Finds or creates the node where the data should be inserted. |
| 214 | /// Traverses the tree iteratively and returns a reference to the node. |
| 215 | pub fn find_or_create_node(&self, path: &[u8], mut offset_fn: impl FnMut() -> u32) -> &Self { |
| 216 | let mut current_node = self; |
| 217 | for &child_index in path { |
| 218 | let new_dim_index = current_node.dim_index + (1u32 << (child_index * 2)); |
| 219 | if let Some(child) = current_node.children.get(child_index as usize) { |
| 220 | let res = unsafe { &*child }; |
| 221 | current_node = res; |
| 222 | continue; |
| 223 | } |
| 224 | let (new_child, _is_newly_created) = |
| 225 | current_node |
| 226 | .children |
| 227 | .get_or_insert_with(child_index as usize, || { |
| 228 | Self::new( |
| 229 | new_dim_index, |
| 230 | self.quantization_bits, |
| 231 | FileOffset(offset_fn()), |
| 232 | ) |
| 233 | }); |
| 234 | let res = unsafe { &*new_child }; |
| 235 | current_node = res; |
| 236 | } |
| 237 | |
| 238 | current_node |
| 239 | } |
| 240 | |
| 241 | pub fn quantize(&self, value: f32, values_upper_bound: f32) -> u8 { |
| 242 | let quantization = ((1u32 << self.quantization_bits) - 1) as u8; |
no test coverage detected