Skip to content

Commit

Permalink
Fix htable put distinct rehash
Browse files Browse the repository at this point in the history
  • Loading branch information
rtheunissen committed Aug 31, 2016
1 parent 3589f0b commit 3199f78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/ds/ds_htable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
15 changes: 10 additions & 5 deletions src/ds/ds_htable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \

This comment has been minimized.

Copy link
@rtheunissen

rtheunissen Aug 31, 2016

Author Member

Nothing changed here, just a refactor.

} while (0)

/**
Expand Down

0 comments on commit 3199f78

Please sign in to comment.