aboutsummaryrefslogtreecommitdiff
path: root/src/core/idhash.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-22 12:21:36 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-22 12:21:36 -0700
commit7074c5c50936308d1ef58be4ce1ca5e776e4c8cb (patch)
treed9f45ba6536a4ce846865319c77829c90d09f2da /src/core/idhash.c
parent9b6ac0a1ea92b1ec99acdd021087f6d8fdc75f14 (diff)
downloadnng-7074c5c50936308d1ef58be4ce1ca5e776e4c8cb.tar.gz
nng-7074c5c50936308d1ef58be4ce1ca5e776e4c8cb.tar.bz2
nng-7074c5c50936308d1ef58be4ce1ca5e776e4c8cb.zip
Hash all 64-bits of IDs when calculating hash values.
Diffstat (limited to 'src/core/idhash.c')
-rw-r--r--src/core/idhash.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/idhash.c b/src/core/idhash.c
index 08352ea3..6d8c8163 100644
--- a/src/core/idhash.c
+++ b/src/core/idhash.c
@@ -95,11 +95,13 @@ nni_idhash_set_limits(
// Inspired by Python dict implementation. This probe will visit every
// cell. We always hash consecutively assigned IDs.
#define NNI_IDHASH_NEXTPROBE(h, j) ((((j) *5) + 1) & (h->ih_cap - 1))
+#define NNI_IDHASH_INDEX(h, j) \
+ (((j & 0xffffffff) ^ (j >> 32)) & (h->ih_cap - 1))
static int
nni_hash_find(nni_idhash *h, uint64_t id, void **valp)
{
- uint32_t index = id & (h->ih_cap - 1);
+ uint32_t index = NNI_IDHASH_INDEX(h, id);
if (h->ih_count == 0) {
return (NNG_ENOENT);
@@ -210,7 +212,7 @@ nni_idhash_remove(nni_idhash *h, uint64_t id)
return (rv);
}
- index = id & (h->ih_cap - 1);
+ index = NNI_IDHASH_INDEX(h, id);
for (;;) {
nni_idhash_entry *ent = &h->ih_entries[index];
@@ -253,7 +255,7 @@ nni_hash_insert(nni_idhash *h, uint64_t id, void *val)
if ((nni_hash_resize(h) != 0) && (h->ih_count >= (h->ih_cap - 1))) {
return (NNG_ENOMEM);
}
- index = id & (h->ih_cap - 1);
+ index = NNI_IDHASH_INDEX(h, id);
for (;;) {
nni_idhash_entry *ent = &h->ih_entries[index];
if ((ent->ihe_val == NULL) || (ent->ihe_key == id)) {