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

Function node_delete

python/bplustree_c_src/node_ops.c:290–323  ·  view source on GitHub ↗

Delete key from leaf node */

Source from the content-addressed store, hash-verified

288
289/* Delete key from leaf node */
290int node_delete(BPlusNode *node, PyObject *key) {
291 if (node->type != NODE_LEAF) {
292 return 0; /* Can only delete from leaf nodes directly */
293 }
294
295 int pos = node_find_position(node, key);
296 if (pos < 0) return -1; /* Comparison error */
297
298 /* Check if key exists */
299 if (pos >= node->num_keys) {
300 return 0; /* Key not found */
301 }
302
303 PyObject *found_key = node_get_key(node, pos);
304 int cmp = fast_compare_eq(found_key, key);
305 if (cmp < 0) return -1; /* Comparison error */
306 if (!cmp) return 0; /* Key not found */
307
308 /* Clear the removed slot */
309 node_clear_slot(node, pos);
310
311 /* Shift elements left to fill the gap */
312 for (int i = pos; i < node->num_keys - 1; i++) {
313 node_set_key(node, i, node_get_key(node, i + 1));
314 node_set_value(node, i, node_get_value(node, i + 1));
315 }
316
317 /* Clear the last slot */
318 node->num_keys--;
319 node_set_key(node, node->num_keys, NULL);
320 node_set_value(node, node->num_keys, NULL);
321
322 return 1; /* Successfully deleted */
323}
324
325/* Get value from leaf node */
326PyObject* node_get(BPlusNode *node, PyObject *key) {

Callers 1

tree_deleteFunction · 0.85

Calls 7

node_find_positionFunction · 0.85
node_get_keyFunction · 0.85
fast_compare_eqFunction · 0.85
node_clear_slotFunction · 0.85
node_set_keyFunction · 0.85
node_set_valueFunction · 0.85
node_get_valueFunction · 0.85

Tested by

no test coverage detected