MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / search_node

Method search_node

src/structures/mmap_tree.rs:179–193  ·  view source on GitHub ↗
(&mut self, node_offset: usize, key: K)

Source from the content-addressed store, hash-verified

177 }
178
179 fn search_node(&mut self, node_offset: usize, key: K) -> Result<Option<V>, io::Error> {
180 // println!("Searching for key: {} at offset: {}", key, node_offset);
181 let node = self.storage_manager.load_node(node_offset)?;
182
183 match node.node_type {
184 NodeType::Internal => {
185 let idx = node.keys.binary_search(&key).unwrap_or_else(|x| x); // Find the child to go to
186 self.search_node(node.children[idx], key)
187 }
188 NodeType::Leaf => match node.keys.binary_search(&key) {
189 Ok(idx) => Ok(node.values[idx].clone()),
190 Err(_) => Ok(None),
191 },
192 }
193 }
194
195 pub fn has_key(&mut self, key: K) -> Result<bool, io::Error> {
196 self.has_key_node(self.storage_manager.root_offset(), key)

Callers 1

searchMethod · 0.45

Calls 2

load_nodeMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected