mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-02-07 04:06:37 -05:00
hash: Improve double hashing
Instead of artificially introducing collisions in the step value by replacing 0 with 1 (which causes the value 1 to have twice the frequency of any other value), the step value can simply be computed as an uniformly distributed value in the range [1, rehash], extremes included. This is safe because any step value smaller than the hash modulus is co-prime with it, hence induces an orbit which includes every integer in [0, size - 1].
This commit is contained in:
parent
e742dcc9ed
commit
3175e91efa
1 changed files with 2 additions and 6 deletions
|
|
@ -176,9 +176,7 @@ hash_table_search(struct wl_hash_table *ht, uint32_t hash)
|
|||
return entry;
|
||||
}
|
||||
|
||||
double_hash = hash % ht->rehash;
|
||||
if (double_hash == 0)
|
||||
double_hash = 1;
|
||||
double_hash = 1 + hash % ht->rehash;
|
||||
|
||||
hash_address = (hash_address + double_hash) % ht->size;
|
||||
} while (hash_address != hash % ht->size);
|
||||
|
|
@ -277,9 +275,7 @@ wl_hash_table_insert(struct wl_hash_table *ht, uint32_t hash, void *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
double_hash = hash % ht->rehash;
|
||||
if (double_hash == 0)
|
||||
double_hash = 1;
|
||||
double_hash = 1 + hash % ht->rehash;
|
||||
|
||||
hash_address = (hash_address + double_hash) % ht->size;
|
||||
} while (hash_address != hash % ht->size);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue