summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-10-18 18:56:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-10-18 18:56:20 -0700
commit2154663a0a553385171c08674a009c6f64e62cd5 (patch)
tree877148f984ef3851635854933d30f4d9d1cb7246 /hash.c
parenta7ab51c02e36aa9e2a6a6faa2b59c965bf82d309 (diff)
downloadtxr-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.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 22532e5b..529202e4 100644
--- a/hash.c
+++ b/hash.c
@@ -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;
}