defrag radix tree including: * 1) rax struct * 2) rax nodes * 3) rax entry data (only if defrag_data is specified) * 4) call a callback per element, and allow the callback to return a new pointer for the element */
| 723 | * 3) rax entry data (only if defrag_data is specified) |
| 724 | * 4) call a callback per element, and allow the callback to return a new pointer for the element */ |
| 725 | long defragRadixTree(rax **raxref, int defrag_data, raxDefragFunction *element_cb, void *element_cb_data) { |
| 726 | long defragged = 0; |
| 727 | raxIterator ri; |
| 728 | ::rax* rax; |
| 729 | if ((rax = (::rax*)activeDefragAlloc(*raxref))) |
| 730 | defragged++, *raxref = rax; |
| 731 | rax = *raxref; |
| 732 | raxStart(&ri,rax); |
| 733 | ri.node_cb = defragRaxNode; |
| 734 | defragRaxNode(&rax->head); |
| 735 | raxSeek(&ri,"^",NULL,0); |
| 736 | while (raxNext(&ri)) { |
| 737 | void *newdata = NULL; |
| 738 | if (element_cb) |
| 739 | newdata = element_cb(&ri, element_cb_data, &defragged); |
| 740 | if (defrag_data && !newdata) |
| 741 | newdata = activeDefragAlloc(ri.data); |
| 742 | if (newdata) |
| 743 | raxSetData(ri.node, ri.data=newdata), defragged++; |
| 744 | } |
| 745 | raxStop(&ri); |
| 746 | return defragged; |
| 747 | } |
| 748 | |
| 749 | typedef struct { |
| 750 | streamCG *cg; |
no test coverage detected