MCPcopy Create free account
hub / github.com/ElementsProject/lightning / critbit0_insert

Function critbit0_insert

ccan/ccan/strset/tools/cbspeed.c:106–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104/*:3*//*8:*/
105
106int critbit0_insert(critbit0_tree*t,const char*u)
107{
108const uint8*const ubytes= (void*)u;
109const size_t ulen= strlen(u);
110uint8*p= t->root;
111
112/*9:*/
113
114if(!p){
115#if 0
116char*x;
117int a= posix_memalign((void**)&x,sizeof(void*),ulen+1);
118if(a)return 0;
119memcpy(x,u,ulen+1);
120t->root= x;
121#else
122t->root = (char *)u;
123#endif
124return 2;
125}
126
127/*:9*/
128
129/*5:*/
130
131while(1&(intptr_t)p){
132critbit0_node*q= (void*)(p-1);
133/*6:*/
134
135uint8 c= 0;
136if(q->byte<ulen)c= ubytes[q->byte];
137const int direction= (1+(q->otherbits|c))>>8;
138
139/*:6*/
140
141p= q->child[direction];
142}
143
144/*:5*/
145
146/*10:*/
147
148/*11:*/
149
150uint32 newbyte;
151uint32 newotherbits;
152
153for(newbyte= 0;newbyte<ulen;++newbyte){
154if(p[newbyte]!=ubytes[newbyte]){
155newotherbits= p[newbyte]^ubytes[newbyte];
156goto different_byte_found;
157}
158}
159
160if(p[newbyte]!=0){
161newotherbits= p[newbyte];
162goto different_byte_found;
163}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected