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

Function node_gc_op

python/bplustree_c_src/bplustree_module.c:326–358  ·  view source on GitHub ↗

Common GC operation: traverse or clear Python references in a node and its children. */

Source from the content-addressed store, hash-verified

324
325/* Common GC operation: traverse or clear Python references in a node and its children. */
326static int
327node_gc_op(BPlusNode *node, visitproc visit, void *arg, int clear)
328{
329 if (!node) {
330 return 0;
331 }
332 for (int i = 0; i < node->num_keys; i++) {
333 if (clear) {
334 Py_CLEAR(node->data[i]);
335 } else {
336 Py_VISIT(node_get_key(node, i));
337 }
338 }
339 if (node->type == NODE_LEAF) {
340 for (int i = 0; i < node->num_keys; i++) {
341 if (clear) {
342 Py_CLEAR(node->data[node->capacity + i]);
343 } else {
344 Py_VISIT(node_get_value(node, i));
345 }
346 }
347 } else {
348 for (int i = 0; i <= node->num_keys; i++) {
349 BPlusNode *child = node_get_child(node, i);
350 if (clear) {
351 node_gc_op(child, NULL, NULL, 1);
352 } else if (child && node_gc_op(child, visit, arg, 0)) {
353 return -1;
354 }
355 }
356 }
357 return 0;
358}
359
360static int
361node_traverse(BPlusNode *node, visitproc visit, void *arg)

Callers 2

node_traverseFunction · 0.85
node_clear_gcFunction · 0.85

Calls 3

node_get_keyFunction · 0.85
node_get_valueFunction · 0.85
node_get_childFunction · 0.85

Tested by

no test coverage detected