MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / defragRadixTree

Function defragRadixTree

src/defrag.cpp:725–747  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

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 */
725long 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
749typedef struct {
750 streamCG *cg;

Callers 3

defragStreamConsumerFunction · 0.85
defragStreamFunction · 0.85

Calls 7

activeDefragAllocFunction · 0.85
raxStartFunction · 0.85
defragRaxNodeFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
raxSetDataFunction · 0.85
raxStopFunction · 0.85

Tested by

no test coverage detected