Insert key-value pair into tree */
| 76 | |
| 77 | /* Insert key-value pair into tree */ |
| 78 | int 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 */ |
| 114 | int tree_delete(BPlusTree *tree, PyObject *key) { |
no test coverage detected