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

Function tree_insert

python/bplustree_c_src/tree_ops.c:78–111  ·  view source on GitHub ↗

Insert key-value pair into tree */

Source from the content-addressed store, hash-verified

76
77/* Insert key-value pair into tree */
78int tree_insert(BPlusTree *tree, PyObject *key, PyObject *value) {
79 BPlusNode *new_node = NULL;
80 PyObject *split_key = NULL;
81
82 int result = tree_insert_recursive(tree->root, key, value, &new_node, &split_key);
83 if (result == -1) return -1; /* Error */
84 if (result == -2) {
85 tree->modification_count++; /* Update - increment modification count */
86 return 0; /* Update - don't increment size */
87 }
88
89 if (result > 0) {
90 /* Root was split, create new root */
91 BPlusNode *new_root = node_create(NODE_BRANCH, tree->capacity);
92 if (!new_root) {
93 Py_XDECREF(split_key);
94 return -1;
95 }
96
97 /* Set up new root with old root as first child */
98 node_set_child(new_root, 0, tree->root);
99 node_set_key(new_root, 0, split_key);
100 node_set_child(new_root, 1, new_node);
101 new_root->num_keys = 1;
102
103 tree->root = new_root;
104 }
105
106 /* Increment size for new insertions (result == 0 or result > 0) */
107 tree->size++;
108 tree->modification_count++;
109
110 return 0;
111}
112
113/* Delete key from tree */
114int tree_delete(BPlusTree *tree, PyObject *key) {

Callers 1

BPlusTree_setitemFunction · 0.85

Calls 4

tree_insert_recursiveFunction · 0.85
node_createFunction · 0.85
node_set_childFunction · 0.85
node_set_keyFunction · 0.85

Tested by

no test coverage detected