fix calculation for hash code of a hash table

This commit is contained in:
Matthew Flatt 2011-09-15 14:23:44 -06:00
parent 87652cd32e
commit 039f9c10f3
2 changed files with 12 additions and 2 deletions

View File

@ -2521,6 +2521,16 @@
(list? (list* 1 2 p))
(test 1 hash-ref ht p #f))
;; Check that hash-table cycles don't lead to an
;; explosion in the time to compute a hash code.
(let ()
(define ht (make-hash))
(hash-set! ht 'a ht)
(hash-set! ht 'b ht)
(eq-hash-code ht)
(equal-hash-code ht)
(equal-secondary-hash-code ht))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Misc

View File

@ -1264,7 +1264,7 @@ static uintptr_t equal_hash_key(Scheme_Object *o, uintptr_t k, Hash_Info *hi)
# include "mzhashchk.inc"
k = (k << 1) + 3;
hi->depth += 2;
hi->depth *= 2; /* mult to counteract potential explosion due to old_depth reset */
old_depth = hi->depth;
keys = ht->keys;
@ -1676,7 +1676,7 @@ static uintptr_t equal_hash_key2(Scheme_Object *o, Hash_Info *hi)
# include "mzhashchk.inc"
hi->depth += 2;
hi->depth *= 2; /* mult to counteract potential explosion due to old_depth reset */
old_depth = hi->depth;
keys = ht->keys;