summaryrefslogtreecommitdiff
path: root/src/dict.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/dict.c b/src/dict.c
index 4eeb26e0e..95a141d0d 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -146,14 +146,14 @@ int dictResize(dict *d)
/* Expand or create the hash table */
int dictExpand(dict *d, unsigned long size)
{
- dictht n; /* the new hash table */
- unsigned long realsize = _dictNextPower(size);
-
/* the size is invalid if it is smaller than the number of
* elements already inside the hash table */
if (dictIsRehashing(d) || d->ht[0].used > size)
return DICT_ERR;
+ dictht n; /* the new hash table */
+ unsigned long realsize = _dictNextPower(size);
+
/* Rehashing to the same table size is not useful. */
if (realsize == d->ht[0].size) return DICT_ERR;
@@ -327,7 +327,7 @@ int dictReplace(dict *d, void *key, void *val)
dictEntry *entry, *existing, auxentry;
/* Try to add the element. If the key
- * does not exists dictAdd will suceed. */
+ * does not exists dictAdd will succeed. */
entry = dictAddRaw(d,key,&existing);
if (entry) {
dictSetVal(d, entry, val);
@@ -860,6 +860,15 @@ unsigned long dictScan(dict *d,
de = next;
}
+ /* Set unmasked bits so incrementing the reversed cursor
+ * operates on the masked bits */
+ v |= ~m0;
+
+ /* Increment the reverse cursor */
+ v = rev(v);
+ v++;
+ v = rev(v);
+
} else {
t0 = &d->ht[0];
t1 = &d->ht[1];
@@ -894,22 +903,16 @@ unsigned long dictScan(dict *d,
de = next;
}
- /* Increment bits not covered by the smaller mask */
- v = (((v | m0) + 1) & ~m0) | (v & m0);
+ /* Increment the reverse cursor not covered by the smaller mask.*/
+ v |= ~m1;
+ v = rev(v);
+ v++;
+ v = rev(v);
/* Continue while bits covered by mask difference is non-zero */
} while (v & (m0 ^ m1));
}
- /* Set unmasked bits so incrementing the reversed cursor
- * operates on the masked bits of the smaller table */
- v |= ~m0;
-
- /* Increment the reverse cursor */
- v = rev(v);
- v++;
- v = rev(v);
-
return v;
}