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 | 2154663a0a553385171c08674a009c6f64e62cd5 (patch) | |
tree | 877148f984ef3851635854933d30f4d9d1cb7246 /hash.c | |
parent | a7ab51c02e36aa9e2a6a6faa2b59c965bf82d309 (diff) | |
download | txr-2154663a0a553385171c08674a009c6f64e62cd5.tar.gz txr-2154663a0a553385171c08674a009c6f64e62cd5.tar.bz2 txr-2154663a0a553385171c08674a009c6f64e62cd5.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.
Diffstat (limited to 'hash.c')
-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; } |