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

Method search_node

src/structures/tree.rs:87–102  ·  view source on GitHub ↗
(&self, node: &Node<K, V>, key: K)

Source from the content-addressed store, hash-verified

85 }
86
87 fn search_node(&self, node: &Node<K, V>, key: K) -> Result<Option<V>, io::Error> {
88 match node.node_type {
89 NodeType::Internal => {
90 let idx = node.keys.binary_search(&key).unwrap_or_else(|x| x);
91 if idx < node.keys.len() && node.keys[idx] == key {
92 self.search_node(&node.children[idx + 1], key)
93 } else {
94 self.search_node(&node.children[idx], key)
95 }
96 }
97 NodeType::Leaf => match node.keys.binary_search(&key) {
98 Ok(idx) => Ok(node.values.get(idx).expect("could not get value").clone()),
99 Err(_) => Ok(None),
100 },
101 }
102 }
103}

Callers 1

searchMethod · 0.45

Calls 3

lenMethod · 0.80
cloneMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected