This is the core of raxFree(): performs a depth-first scan of the * tree and releases all the nodes found. */
| 1467 | /* This is the core of raxFree(): performs a depth-first scan of the |
| 1468 | * tree and releases all the nodes found. */ |
| 1469 | void raxRecursiveFree(rax *rax, raxNode *n, void (*free_callback)(void*)) { |
| 1470 | debugnode("free traversing",n); |
| 1471 | int numchildren = n->iscompr ? 1 : n->size; |
| 1472 | raxNode **cp = raxNodeLastChildPtr(n); |
| 1473 | while(numchildren--) { |
| 1474 | if (raxIsInlineLeaf(n,numchildren)) { |
| 1475 | /* Inline leaf: the slot contains a value, not a node pointer. |
| 1476 | * Call the free callback on the value but don't recurse. */ |
| 1477 | if (free_callback) { |
| 1478 | void *val; |
| 1479 | memcpy(&val,cp,sizeof(val)); |
| 1480 | if (val != NULL) free_callback(val); |
| 1481 | } |
| 1482 | } else { |
| 1483 | raxNode *child; |
| 1484 | memcpy(&child,cp,sizeof(child)); |
| 1485 | raxRecursiveFree(rax,child,free_callback); |
| 1486 | } |
| 1487 | cp--; |
| 1488 | } |
| 1489 | debugnode("free depth-first",n); |
| 1490 | if (free_callback && n->iskey && !n->isnull) |
| 1491 | free_callback(raxGetData(n)); |
| 1492 | rax_free(n); |
| 1493 | rax->numnodes--; |
| 1494 | } |
| 1495 | |
| 1496 | /* Free a whole radix tree, calling the specified callback in order to |
| 1497 | * free the auxiliary data. */ |
no test coverage detected