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

Function tree_insert_recursive

python/bplustree_c_src/tree_ops.c:43–75  ·  view source on GitHub ↗

Recursive insert helper */

Source from the content-addressed store, hash-verified

41
42/* Recursive insert helper */
43static 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 */
78int tree_insert(BPlusTree *tree, PyObject *key, PyObject *value) {

Callers 1

tree_insertFunction · 0.85

Calls 6

node_insert_leafFunction · 0.85
node_find_positionFunction · 0.85
node_get_keyFunction · 0.85
fast_compare_eqFunction · 0.85
node_get_childFunction · 0.85
node_insert_branchFunction · 0.85

Tested by

no test coverage detected