if (comp->used >= 4) return -1;
- edge = 0;
+ edge = comp->used;
for (i = 0; i < comp->used; i++) {
if (comp->index[i] < chunk) continue;
* Move the nodes up so that we have room for the
* new edge.
*/
- for (i = comp->used; i > edge; i--) {
- comp->index[i] = comp->index[i - 1];
- comp->trie[i] = comp->trie[i - 1];
+ for (i = edge; i < comp->used; i++) {
+ comp->index[i + 1] = comp->index[i];
+ comp->trie[i + 1] = comp->trie[i];
}
comp->index[edge] = chunk;
comp->trie[edge] = child;
comp->used++;
+ VERIFY(comp);
return 0;
}
#endif
chunk = get_chunk(key, start_bit, comp->bits);
for (i = 0; i < comp->used; i++) {
- MPRINT3("%.*scomp[%d] = index %04x ? chunk %04x\n",
- start_bit, spaces, i, comp->index[i], chunk);
+ if (comp->index[i] < chunk) continue;
if (comp->index[i] == chunk) {
return fr_trie_key_match(comp->trie[i], key, start_bit + comp->bits, end_bit, exact);
* if the edge is larger than the chunk, NO edge
* will match the chunk.
*/
- if (comp->index[i] > chunk) return NULL;
+ return NULL;
}
return NULL;