From 6e9733afec2600acf71ca3c315b0c270023e8081 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 4 Nov 2011 18:05:21 -0400 Subject: [PATCH] cheaply computing equal-hash-table codes. --- js-assembler/runtime-src/baselib-hashes.js | 7 ++++--- tests/more-tests/hash-code.rkt | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/js-assembler/runtime-src/baselib-hashes.js b/js-assembler/runtime-src/baselib-hashes.js index 4ee70ea..69407a7 100644 --- a/js-assembler/runtime-src/baselib-hashes.js +++ b/js-assembler/runtime-src/baselib-hashes.js @@ -178,9 +178,9 @@ // Returns a JavaScript number. var getEqualHashCode = function (x, depth) { var i, t, k = 0; - if (depth === undefined) { depth = 0; } + if (depth === undefined) { depth = [0]; } - if (depth > MAX_HASH_DEPTH) { return 0; } + if (depth[0] > MAX_HASH_DEPTH) { return 0; } if (baselib.numbers.isNumber(x)) { return hashMix(baselib.numbers.toFixnum(x)); @@ -201,7 +201,8 @@ if (typeof(x) === 'object' && typeof(x.hashCode) === 'function') { - return x.hashCode(depth + 1); + depth[0] = depth[0] + 1; + return x.hashCode(depth); } return 0; }; diff --git a/tests/more-tests/hash-code.rkt b/tests/more-tests/hash-code.rkt index f7842d0..5265c76 100644 --- a/tests/more-tests/hash-code.rkt +++ b/tests/more-tests/hash-code.rkt @@ -46,14 +46,14 @@ "structs" (define-struct thing (name age) #:mutable) (equal-hash-code (make-thing "danny" 32)) -(void (equal-hash-code (shared ([a (make-thing a a)]) a))) +(equal-hash-code (shared ([a (make-thing a a)]) a)) -;; ;; symbols -;; "symbols" -;; (equal-hash-code 'hello) -;; (equal-hash-code 'world) +;; symbols +"symbols" +(equal-hash-code 'hello) +(equal-hash-code 'world) -;; ;; vectors -;; "vectors" -;; (equal-hash-code #(1 2 3 4 5)) -;; (equal-hash-code (shared ([v (vector 1 2 v 3 v)]) v)) +;; vectors +"vectors" +(equal-hash-code #(1 2 3 4 5)) +(equal-hash-code (shared ([v (vector 1 2 v 3 v)]) v))