From 3199f7893a911604399a0def58d3b86df23f1a40 Mon Sep 17 00:00:00 2001 From: Rudi Theunissen Date: Thu, 1 Sep 2016 08:28:58 +1200 Subject: [PATCH] Fix htable put distinct rehash --- src/ds/ds_htable.c | 6 ++++-- src/ds/ds_htable.h | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ds/ds_htable.c b/src/ds/ds_htable.c index a56e6ca..9ded51b 100644 --- a/src/ds/ds_htable.c +++ b/src/ds/ds_htable.c @@ -620,8 +620,10 @@ void ds_htable_ensure_capacity(ds_htable_t *table, uint32_t capacity) */ static void ds_htable_put_distinct_bucket(ds_htable_t *table, ds_htable_bucket_t *bucket) { - DS_HTABLE_BUCKET_COPY(&table->buckets[table->next], bucket); - DS_HTABLE_BUCKET_REHASH(table, bucket, table->capacity - 1, table->next); + ds_htable_bucket_t *next = &table->buckets[table->next]; + + DS_HTABLE_BUCKET_COPY(next, bucket); + DS_HTABLE_BUCKET_REHASH(table, next, table->capacity - 1, table->next); table->next++; table->size++; diff --git a/src/ds/ds_htable.h b/src/ds/ds_htable.h index 0f58906..6f321d0 100644 --- a/src/ds/ds_htable.h +++ b/src/ds/ds_htable.h @@ -47,11 +47,16 @@ * This means that the next bucket can come before another in the buffer, * because a rehash unshifts the bucket into the chain. */ -#define DS_HTABLE_BUCKET_REHASH(_table, _bucket, _mask, _idx) \ -do { \ - uint32_t *head = &_table->lookup[DS_HTABLE_BUCKET_HASH(_bucket) & (_mask)];\ - DS_HTABLE_BUCKET_NEXT(_bucket) = *head; \ - *head = _idx; \ +#define DS_HTABLE_BUCKET_REHASH(table, bucket, mask, idx) \ +do { \ + ds_htable_bucket_t *_bucket = bucket; \ + ds_htable_t *_table = table; \ + \ + uint32_t hash = DS_HTABLE_BUCKET_HASH(_bucket); \ + uint32_t *head = &_table->lookup[hash & (mask)]; \ + \ + DS_HTABLE_BUCKET_NEXT(_bucket) = *head; \ + *head = idx; \ } while (0) /**