diff --git a/src/hashset.c b/src/hashset.c index 87d7e7dcd4..e7d7056d27 100644 --- a/src/hashset.c +++ b/src/hashset.c @@ -355,9 +355,12 @@ static inline uint8_t highBits(uint64_t hash) { return hash >> (CHAR_BIT * 7); } +static inline int numBucketPoitions(bucket *b) { + return ELEMENTS_PER_BUCKET - (b->chained ? 1 : 0); +} + static inline int bucketIsFull(bucket *b) { - int num_positions = ELEMENTS_PER_BUCKET - (b->chained ? 1 : 0); - return b->presence == (1 << num_positions) - 1; + return b->presence == (1 << numBucketPoitions(b)) - 1; } /* Returns non-zero if the position within the bucket is occupied. */ @@ -461,9 +464,8 @@ static bucket *bucketDefrag(bucket *prev, bucket *b, void *(*defragfn)(void *)) /* Rehashes one bucket. */ static void rehashBucket(hashset *s, bucket *b) { - int num_positions = ELEMENTS_PER_BUCKET - (b->chained ? 1 : 0); int pos; - for (pos = 0; pos < num_positions; pos++) { + for (pos = 0; pos < numBucketPoitions(b); pos++) { if (!isPositionFilled(b, pos)) continue; /* empty */ void *element = b->elements[pos]; uint8_t h2 = b->hashes[pos]; @@ -645,8 +647,7 @@ static bucket *findBucket(hashset *s, uint64_t hash, const void *key, int *pos_i bucket *b = &s->tables[table][bucket_idx]; do { /* Find candidate elements with presence flag set and matching h2 hash. */ - int num_positions = ELEMENTS_PER_BUCKET - (b->chained ? 1 : 0); - for (int pos = 0; pos < num_positions; pos++) { + for (int pos = 0; pos < numBucketPoitions(b); pos++) { if (isPositionFilled(b, pos) && b->hashes[pos] == h2) { /* It's a candidate. */ void *element = b->elements[pos];