Find leaf node that should contain the key */ Find leaf node that should contain the key */
| 9 | /* Find leaf node that should contain the key */ |
| 10 | /* Find leaf node that should contain the key */ |
| 11 | BPlusNode* 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 */ |
| 43 | static int tree_insert_recursive(BPlusNode *node, PyObject *key, PyObject *value, |
no test coverage detected