cheaply computing equal-hash-table codes.
This commit is contained in:
parent
c8bc9c182d
commit
6e9733afec
|
@ -178,9 +178,9 @@
|
||||||
// Returns a JavaScript number.
|
// Returns a JavaScript number.
|
||||||
var getEqualHashCode = function (x, depth) {
|
var getEqualHashCode = function (x, depth) {
|
||||||
var i, t, k = 0;
|
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)) {
|
if (baselib.numbers.isNumber(x)) {
|
||||||
return hashMix(baselib.numbers.toFixnum(x));
|
return hashMix(baselib.numbers.toFixnum(x));
|
||||||
|
@ -201,7 +201,8 @@
|
||||||
|
|
||||||
if (typeof(x) === 'object' &&
|
if (typeof(x) === 'object' &&
|
||||||
typeof(x.hashCode) === 'function') {
|
typeof(x.hashCode) === 'function') {
|
||||||
return x.hashCode(depth + 1);
|
depth[0] = depth[0] + 1;
|
||||||
|
return x.hashCode(depth);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,14 +46,14 @@
|
||||||
"structs"
|
"structs"
|
||||||
(define-struct thing (name age) #:mutable)
|
(define-struct thing (name age) #:mutable)
|
||||||
(equal-hash-code (make-thing "danny" 32))
|
(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
|
||||||
;; "symbols"
|
"symbols"
|
||||||
;; (equal-hash-code 'hello)
|
(equal-hash-code 'hello)
|
||||||
;; (equal-hash-code 'world)
|
(equal-hash-code 'world)
|
||||||
|
|
||||||
;; ;; vectors
|
;; vectors
|
||||||
;; "vectors"
|
"vectors"
|
||||||
;; (equal-hash-code #(1 2 3 4 5))
|
(equal-hash-code #(1 2 3 4 5))
|
||||||
;; (equal-hash-code (shared ([v (vector 1 2 v 3 v)]) v))
|
(equal-hash-code (shared ([v (vector 1 2 v 3 v)]) v))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user