mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-14 08:07:14 +03:00
invert distance counting
This commit is contained in:
parent
63b503e27f
commit
33d73dd514
10
hash.c
10
hash.c
@ -130,13 +130,13 @@ hash_item hash_find(hash* h, hash_item item)
|
|||||||
|
|
||||||
|
|
||||||
/* Returns DIB: distance to initial bucket */
|
/* Returns DIB: distance to initial bucket */
|
||||||
static int distance(int actual_index, hash* h, hash_item item)
|
static int distance(int current_index, hash* h, hash_item item)
|
||||||
{
|
{
|
||||||
int wanted_index = hash_make_key(h, item);
|
int wanted_index = hash_make_key(h, item);
|
||||||
if (wanted_index <= actual_index)
|
if (wanted_index <= current_index)
|
||||||
return wanted_index - actual_index;
|
return current_index - wanted_index;
|
||||||
else
|
else
|
||||||
return wanted_index + hash_size - actual_index;
|
return current_index - wanted_index + hash_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ int hash_insert(hash* h, hash_item new)
|
|||||||
|
|
||||||
hash_item curr_item = gap_get(hash, index);
|
hash_item curr_item = gap_get(hash, index);
|
||||||
while (curr_item) {
|
while (curr_item) {
|
||||||
if (distance(index, h, curr_item) > distance(index, h, new)) {
|
if (distance(index, h, curr_item) < distance(index, h, new)) {
|
||||||
gap_set(h->data, index, new);
|
gap_set(h->data, index, new);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fprintf(stderr, "intermediate insert [%s] at %d\n", &new->client_addr, index);
|
fprintf(stderr, "intermediate insert [%s] at %d\n", &new->client_addr, index);
|
||||||
|
BIN
hashtest/htest
BIN
hashtest/htest
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user