Recursive insert helper */
| 41 | |
| 42 | /* Recursive insert helper */ |
| 43 | static int tree_insert_recursive(BPlusNode *node, PyObject *key, PyObject *value, |
| 44 | BPlusNode **new_node, PyObject **split_key) { |
| 45 | if (node->type == NODE_LEAF) { |
| 46 | return node_insert_leaf(node, key, value, new_node, split_key); |
| 47 | } |
| 48 | |
| 49 | /* Find child to insert into */ |
| 50 | int child_pos = node_find_position(node, key); |
| 51 | if (child_pos < 0) { |
| 52 | return -1; |
| 53 | } |
| 54 | /* bisect_right semantics: advance past equal keys */ |
| 55 | if (child_pos < node->num_keys) { |
| 56 | PyObject *node_key = node_get_key(node, child_pos); |
| 57 | int eq = fast_compare_eq(node_key, key); |
| 58 | if (eq < 0) { |
| 59 | return -1; |
| 60 | } |
| 61 | if (eq) { |
| 62 | child_pos++; |
| 63 | } |
| 64 | } |
| 65 | BPlusNode *child = node_get_child(node, child_pos); |
| 66 | BPlusNode *new_child = NULL; |
| 67 | PyObject *new_key = NULL; |
| 68 | |
| 69 | int result = tree_insert_recursive(child, key, value, &new_child, &new_key); |
| 70 | if (result < 0) return result; /* Error or update - propagate as-is */ |
| 71 | if (result == 0) return 0; /* No split */ |
| 72 | |
| 73 | /* Child was split, need to insert new_key and new_child into this node */ |
| 74 | return node_insert_branch(node, new_key, new_child, new_node, split_key); |
| 75 | } |
| 76 | |
| 77 | /* Insert key-value pair into tree */ |
| 78 | int tree_insert(BPlusTree *tree, PyObject *key, PyObject *value) { |
no test coverage detected