From 76c1836aaf2e7738829834c043ba1bc4d6ed6cec Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 29 Dec 2016 09:03:55 -0800 Subject: Test suite for idhash, fix symbol errors, and value changing. --- src/core/idhash.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/idhash.c b/src/core/idhash.c index 85759b93..050ba4fb 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -113,7 +113,7 @@ nni_hash_resize(nni_idhash *h) int -nni_hash_remove(nni_idhash *h, uint32_t id) +nni_idhash_remove(nni_idhash *h, uint32_t id) { uint32_t index = id & (h->ih_cap - 1); @@ -138,7 +138,7 @@ nni_hash_remove(nni_idhash *h, uint32_t id) int -nni_hash_insert(nni_idhash *h, uint32_t id, void *val) +nni_idhash_insert(nni_idhash *h, uint32_t id, void *val) { uint32_t index; @@ -149,10 +149,13 @@ nni_hash_insert(nni_idhash *h, uint32_t id, void *val) } index = id & (h->ih_cap - 1); for (;;) { - if (h->ih_entries[index].ihe_val == NULL) { + if ((h->ih_entries[index].ihe_val == NULL) || + (h->ih_entries[index].ihe_key == id)) { + if (h->ih_entries[index].ihe_val == NULL) { + h->ih_count++; + } h->ih_entries[index].ihe_key = id; h->ih_entries[index].ihe_val = val; - h->ih_count++; return (0); } index = NNI_IDHASH_NEXTPROBE(h, index); -- cgit v1.2.3-70-g09d2