MCPcopy Create free account
hub / github.com/cosdata/cosdata / find_or_create_node

Method find_or_create_node

src/models/inverted_index.rs:141–166  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

139 /// Finds or creates the node where the data should be inserted.
140 /// Traverses the tree iteratively and returns a reference to the node.
141 pub fn find_or_create_node(&self, path: &[u8], mut offset_fn: impl FnMut() -> u32) -> &Self {
142 let mut current_node = self;
143 for &child_index in path {
144 let new_dim_index = current_node.dim_index + (1u32 << (child_index * 2));
145 if let Some(child) = current_node.children.get(child_index as usize) {
146 let res = unsafe { &*child };
147 current_node = res;
148 continue;
149 }
150 let (new_child, _is_newly_created) =
151 current_node
152 .children
153 .get_or_insert(child_index as usize, || {
154 Box::into_raw(Box::new(Self::new(
155 new_dim_index,
156 true,
157 self.quantization_bits,
158 FileOffset(offset_fn()),
159 )))
160 });
161 let res = unsafe { &*new_child };
162 current_node = res;
163 }
164
165 current_node
166 }
167
168 pub fn quantize(&self, value: f32, values_upper_bound: f32) -> u8 {
169 let quantization = ((1u32 << self.quantization_bits) - 1) as u8;

Callers 1

insertMethod · 0.45

Calls 3

FileOffsetClass · 0.85
getMethod · 0.45
get_or_insertMethod · 0.45

Tested by

no test coverage detected