Hash table

This commit is contained in:
Dmitry Boulytchev 2020-01-16 06:59:34 +03:00
parent 46dfd58bda
commit 149984f5c0
14 changed files with 258 additions and 21 deletions

View file

@ -0,0 +1,22 @@
import Collection;
fun f (x, y) {
fun () {x+y}
}
local t = emptyMemo (),
a = lookupMemo (t, "abc"),
b = lookupMemo (t, [1, 2, 3, 4, "abc"]),
c = lookupMemo (t, f (5, 6));
printf ("Cached: %d\n", lookupMemo (t, "abc") == a);
printf ("Cached: %d\n", lookupMemo (t, "abc") == a);
printf ("Cached: %d\n", lookupMemo (t, "abc") == a);
printf ("Cached: %d\n", lookupMemo (t, [1, 2, 3, 4, "abc"]) == b);
printf ("Cached: %d\n", lookupMemo (t, [1, 2, 3, 4, "abc"]) == b);
printf ("Cached: %d\n", lookupMemo (t, [1, 2, 3, 4, "abc"]) == b);
printf ("Cached: %d\n", lookupMemo (t, f (5, 6)) == c);
printf ("Cached: %d\n", lookupMemo (t, f (5, 6)) == c);
printf ("Cached: %d\n", lookupMemo (t, f (5, 6)) == c)