Clear a single slot: decref or destroy payload and null out key/value or child pointer */
| 146 | |
| 147 | /* Clear a single slot: decref or destroy payload and null out key/value or child pointer */ |
| 148 | static void node_clear_slot(BPlusNode *node, int i) { |
| 149 | if (i < 0 || i >= node->capacity) { |
| 150 | return; /* Invalid index */ |
| 151 | } |
| 152 | |
| 153 | if (node->type == NODE_LEAF) { |
| 154 | Py_XDECREF(node_get_key(node, i)); |
| 155 | Py_XDECREF(node_get_value(node, i)); |
| 156 | node_set_key(node, i, NULL); |
| 157 | node_set_value(node, i, NULL); |
| 158 | } else { |
| 159 | /* For branch nodes, we only clear during deletion operations |
| 160 | * where it's safe to destroy the child subtree */ |
| 161 | BPlusNode *child = node_get_child(node, i); |
| 162 | if (child) { |
| 163 | node_destroy(child); |
| 164 | } |
| 165 | Py_XDECREF(node_get_key(node, i)); |
| 166 | node_set_key(node, i, NULL); |
| 167 | node_set_child(node, i, NULL); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /* Insert into leaf node */ |
| 172 | int node_insert_leaf(BPlusNode *node, PyObject *key, PyObject *value, |
no test coverage detected