Terminate search early when the distance-to-initial-bucket is shorter than i
This commit is contained in:
parent
2ed7bb0d88
commit
1656f3aedc
12
treetrie.c
12
treetrie.c
|
@ -453,12 +453,22 @@ tt_node_ptr_t tt_arena_cons(tt_arena_t *a,
|
|||
tt_node_idx_t candidate_i = tt_ptr_idx(candidate);
|
||||
|
||||
/* printf("cons at %d candidate %d\n", i, candidate); */
|
||||
/* TODO: perhaps also bail early if we detect that the hash code changes */
|
||||
if (candidate == TT_NO_PTR) {
|
||||
/* printf("cons empty cell\n"); */
|
||||
break;
|
||||
}
|
||||
|
||||
{
|
||||
tt_hash_t candidate_h = a->table[index].hash;
|
||||
int distance = index - (candidate_h % a->table_length);
|
||||
if (distance < 0) distance += a->table_length;
|
||||
|
||||
if (i > distance) {
|
||||
/* printf("early exit as we found a slot that would have been used instead\n"); */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* printf("tag %d %d\n", tt_ptr_tag(candidate), tag); */
|
||||
/* printf("index %d %d\n", a->headers[candidate].inuse.index, nindex); */
|
||||
/* printf("a %d %d\n", a->nodes[candidate].a, na); */
|
||||
|
|
Loading…
Reference in New Issue