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