diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-10-18 18:56:20 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-10-18 18:56:20 -0700 |
commit | d459fec84983e1ff0b842e7e1cb579c6bb754c2f (patch) | |
tree | 877148f984ef3851635854933d30f4d9d1cb7246 | |
parent | 110a0f7f387aad0314939056067bb8d21d814e20 (diff) | |
download | txr-d459fec84983e1ff0b842e7e1cb579c6bb754c2f.tar.gz txr-d459fec84983e1ff0b842e7e1cb579c6bb754c2f.tar.bz2 txr-d459fec84983e1ff0b842e7e1cb579c6bb754c2f.zip |
hash: observe count limit for vectors and hash tables.
* hash.c (equal_hash): Break out of hashing a vector when the
count is exceeded.
(hash_hash_op): Likewise for traversing a hash table.
-rw-r--r-- | hash.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -239,6 +239,8 @@ ucnum equal_hash(val obj, int *count, ucnum seed) for (i = 0, lseed = seed; i < len; i++, lseed += seed) { h *= 2; h += equal_hash(obj->v.vec[i], count, lseed); + if ((*count)-- <= 0) + break; } return h; @@ -474,7 +476,7 @@ static ucnum hash_hash_op(val obj, int *count, ucnum seed) iter = hash_begin(obj); - while ((cell = hash_next(iter)) != nil) { + while ((*count)-- > 0 && (cell = hash_next(iter)) != nil) { out += equal_hash(cell, count, seed); out &= NUM_MAX; } |