MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / tree_find_leaf

Function tree_find_leaf

python/bplustree_c_src/tree_ops.c:11–40  ·  view source on GitHub ↗

Find leaf node that should contain the key */ Find leaf node that should contain the key */

Source from the content-addressed store, hash-verified

9/* Find leaf node that should contain the key */
10/* Find leaf node that should contain the key */
11BPlusNode* tree_find_leaf(BPlusTree *tree, PyObject *key) {
12 BPlusNode *node = tree->root;
13
14 while (node->type == NODE_BRANCH) {
15 int pos = node_find_position(node, key);
16 if (pos < 0) {
17 return NULL;
18 }
19 /* bisect_right semantics: advance past equal keys */
20 if (pos < node->num_keys) {
21 PyObject *node_key = node_get_key(node, pos);
22 int eq = fast_compare_eq(node_key, key);
23 if (eq < 0) {
24 return NULL;
25 }
26 if (eq) {
27 pos++;
28 }
29 }
30 /* Ensure pos is within valid child range */
31 if (pos > node->num_keys) {
32 return NULL;
33 }
34 {
35 node = node_prefetch_child(node, pos);
36 }
37 }
38
39 return node;
40}
41
42/* Recursive insert helper */
43static int tree_insert_recursive(BPlusNode *node, PyObject *key, PyObject *value,

Callers 2

tree_deleteFunction · 0.85
tree_getFunction · 0.85

Calls 4

node_find_positionFunction · 0.85
node_get_keyFunction · 0.85
fast_compare_eqFunction · 0.85
node_prefetch_childFunction · 0.85

Tested by

no test coverage detected