Updated spec

This commit is contained in:
Dmitry Boulytchev 2020-08-10 20:55:10 +03:00
parent 6f9d0850c7
commit 94e4b16267
7 changed files with 48 additions and 18 deletions

View file

@ -323,10 +323,10 @@ public fun lookupMemo (m, v) {
-- Maps of hashed pointers
public fun emptyHashTab (n, hash, compare) {
[initArray (n, fun (_) {{}}), fun (x) {hash (x) % n}, compare]
[initArray (n, fun (_) {{}}), compare, fun (x) {hash (x) % n}]
}
public fun addHashTab (ht@[a, hash, compare], k, v) {
public fun addHashTab (ht@[a, compare, hash], k, v) {
local h = hash (k);
a [h] := [k, v] : a [h];
@ -334,17 +334,21 @@ public fun addHashTab (ht@[a, hash, compare], k, v) {
ht
}
public fun findHashTab ([a, hash, compare], k) {
public fun findHashTab ([a, compare, hash], k) {
case find (fun ([k0, _]) {compare (k, k0) == 0}, a[hash(k)]) of
Some ([_, v]) -> Some (v)
| _ -> None
esac
}
public fun removeHashTab (ht@[a, hash, compare], k) {
public fun removeHashTab (ht@[a, compare, hash], k) {
local h = hash (k);
a [h] := remove (fun ([k0, _]) {compare (k, k0) == 0}, a [h]);
ht
}
}
public fun hashOf (ht) {
ht [2]
}

View file

@ -13,10 +13,19 @@ public infix =?= at < (x, y) {
fun alreadyEq (x, y) {
fun find (x) {
fun walk (r) {
case r of
[#unboxed] -> r
| [x] -> walk (x)
esac
fun walkrec (p1, p2, r) {
case p2 of
[_] -> p2 [0] := r
| _ -> skip
esac;
case r of
[#unboxed] -> r
| [x] -> walkrec (r, p1, x)
esac
}
walkrec ({}, {}, r)
}
case findMap (deref (m), x) of
@ -43,7 +52,14 @@ public infix =?= at < (x, y) {
if rx == ry
then true
else
rx [0] := ry;
if rx[0] < ry[0]
then
ry [0] := ry [0] + rx [0];
rx [0] := ry
else
rx [0] := rx [0] + ry [0];
ry [0] := rx
fi;
false
fi
esac
@ -63,7 +79,7 @@ public infix =?= at < (x, y) {
if alreadyEq (x, y)
then 0
else
local diff = x.rawTag - y.rawTag;
local diff = x.kindOf - y.kindOf;
if diff != 0 then diff
else