diff --git a/js-assembler/runtime-src/baselib-hashes.js b/js-assembler/runtime-src/baselib-hashes.js index 38a6e67..c68fe22 100644 --- a/js-assembler/runtime-src/baselib-hashes.js +++ b/js-assembler/runtime-src/baselib-hashes.js @@ -51,10 +51,17 @@ }; + var eq = function (x, y) { return x === y; }; + var eqv = baselib.equality.eqv; + var equal = function (x, y) { + return baselib.equality.equals(x, y, new baselib.UnionFind()); + }; + + // Creates a low-level hashtable, following the interface of // http://www.timdown.co.uk/jshashtable/ var makeLowLevelEqHash = function () { - return new Hashtable(function (x) { return getEqHashCode(x); }, + return new Hashtable(getEqHashCode, function (x, y) { return x === y; }); }; @@ -63,17 +70,17 @@ var makeEqHashtable = function() { return new WhalesongHashtable( "hasheq", - function (x) { return getEqHashCode(x); }, - function (x, y) { return x === y; }); + getEqHashCode, + eq, + new Hashtable(getEqHashCode, eq)); }; var makeEqualHashtable = function() { return new WhalesongHashtable( "hash", getEqualHashCode, - function (x, y) { - return baselib.equality.equals(x, y, new baselib.UnionFind()); - }) + equal, + new Hashtable(getEqualHashCode, equal)); }; @@ -81,7 +88,8 @@ return new WhalesongHashtable( "hasheqv", getEqvHashCode, - baselib.equality.eqv); + baselib.equality.eqv, + new Hashtable(getEqvHashCode, baselib.equality.eqv)); }; @@ -92,7 +100,7 @@ if (hx < hy) { return -1; } if (hx > hy) { return 1; } - if eq(x, y) { return 0; } + if (eq(x, y)) { return 0; } hx = getEqHashCode(x); hy = getEqHashCode(y); @@ -109,11 +117,11 @@ ////////////////////////////////////////////////////////////////////// // Whalesong's Hashtables are a thin wrapper around the mutable Hashtable // class to make it printable and equatable. - var WhalesongHashtable = function (type, hash_function, equality_function) { + var WhalesongHashtable = function (type, hash_function, equality_function, hash) { this.type = type; this.hash_function = hash_function; this.equality_function = equality_function; - this.hash = new Hashtable(hash_function, equality_function); + this.hash = hash; }; WhalesongHashtable.prototype.toWrittenString = function (cache) { @@ -272,15 +280,22 @@ }; WhalesongImmutableHashtable.prototype.put = function(key, value) { - // this.hash.put(key, value); + throw new Error(); + }; + + WhalesongImmutableHashtable.prototype.functionalPut = function(key, value) { }; WhalesongImmutableHashtable.prototype.remove = function(key) { + throw new Error(); + }; + + WhalesongImmutableHashtable.prototype.functionalRemove = function(key) { // this.hash.remove(key); }; WhalesongImmutableHashtable.prototype.containsKey = function(key) { - // return this.hash.containsKey(key); + return this.map.contains(key); }; WhalesongImmutableHashtable.prototype.isImmutable = function() { @@ -312,11 +327,6 @@ - - - - - // Arbitrary magic number. We have to cut off the hashing at some point. var MAX_HASH_DEPTH = 128; diff --git a/tests/more-tests/hash-code.expected b/tests/more-tests/hash-code.expected new file mode 100644 index 0000000..5c43649 --- /dev/null +++ b/tests/more-tests/hash-code.expected @@ -0,0 +1,24 @@ +"boxes" +1159182323 +"bytes" +121827633 +"chars" +1932714901 +1932717986 +"hashes" +1118728238 +964361183 +"lists" +448104403 +1541271846 +"strings" +801766744 +"structs" +1930147392 +402355443 +"symbols" +22978968 +721172405 +"vectors" +1344488202 +803618204 diff --git a/tests/more-tests/hashes.expected b/tests/more-tests/hashes.expected new file mode 100644 index 0000000..824533c --- /dev/null +++ b/tests/more-tests/hashes.expected @@ -0,0 +1,23 @@ +false +false +true +true +true +true +true +true +#hash() +#hasheqv() +#hasheq() +#hash((4 . four) (3 . three) (2 . two) (1 . one)) +#hasheqv((4 . four) (3 . three) (2 . two) (1 . one)) +#hasheq((4 . four) (3 . three) (2 . two) (1 . one)) +one +not-found +1 +2 +2 +1 +1 +1 +1 diff --git a/tests/run-more-tests.rkt b/tests/run-more-tests.rkt index 409df25..8ce86cb 100644 --- a/tests/run-more-tests.rkt +++ b/tests/run-more-tests.rkt @@ -32,7 +32,8 @@ (test "more-tests/earley.rkt") (test "more-tests/view.rkt") (test "more-tests/weird-cc.rkt") - +(test "more-tests/hashes.rkt") +(test "more-tests/hash-code.rkt") (test "more-tests/booleans-cs019.rkt") (test "more-tests/checking-cs019.rkt") diff --git a/version.rkt b/version.rkt index 492c66b..5fb4bfd 100644 --- a/version.rkt +++ b/version.rkt @@ -6,4 +6,4 @@ (provide version) (: version String) -(define version "1.59") +(define version "1.60")