mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-23 23:28:46 +00:00
Hash table
This commit is contained in:
parent
46dfd58bda
commit
149984f5c0
14 changed files with 258 additions and 21 deletions
|
|
@ -8,7 +8,7 @@ check: $(TESTS)
|
|||
|
||||
$(TESTS): %: %.expr
|
||||
@echo $@
|
||||
RC_RUNTIME=../../runtime $(RC) -I .. $< && ./$@ > $@.log && diff $@.log orig/$@.log
|
||||
RC_RUNTIME=../../runtime $(RC) -I .. -ds -dp $< && ./$@ > $@.log && diff $@.log orig/$@.log
|
||||
|
||||
clean:
|
||||
$(RM) test*.log *.s *~ $(TESTS) *.i
|
||||
|
|
|
|||
9
stdlib/regression/orig/test05.log
Normal file
9
stdlib/regression/orig/test05.log
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
Cached: 1
|
||||
6
stdlib/regression/orig/test06.log
Normal file
6
stdlib/regression/orig/test06.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Flattening: 0
|
||||
Flattening: 0
|
||||
Flattening: {1, 2, 3}
|
||||
Flattening: {1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
List to array: [1, 2, 3, 4, 5]
|
||||
Array to list: {1, 2, 3, 4, 5}
|
||||
6
stdlib/regression/orig/test07.log
Normal file
6
stdlib/regression/orig/test07.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
HashTab internal structure: MNode (-624426958, {[{1, 2, 3}, 100]}, 0, 0, 0)
|
||||
HashTab internal structure: MNode (-624426958, {[{1, 2, 3}, 200], [{1, 2, 3}, 100]}, 0, 0, 0)
|
||||
Searching: Some (100)
|
||||
Searching: Some (200)
|
||||
Replaced: Some (800)
|
||||
Restored: Some (100)
|
||||
22
stdlib/regression/test05.expr
Normal file
22
stdlib/regression/test05.expr
Normal 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)
|
||||
9
stdlib/regression/test06.expr
Normal file
9
stdlib/regression/test06.expr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import List;
|
||||
import Array;
|
||||
|
||||
printf ("Flattening: %s\n", flatten ({}).string);
|
||||
printf ("Flattening: %s\n", flatten ({{}, {}, {}}).string);
|
||||
printf ("Flattening: %s\n", flatten ({1, 2, 3} : {}).string);
|
||||
printf ("Flattening: %s\n", flatten ({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}).string);
|
||||
printf ("List to array: %s\n", listArray ({1, 2, 3, 4, 5}).string);
|
||||
printf ("Array to list: %s\n", arrayList ([1, 2,3, 4, 5]).string)
|
||||
26
stdlib/regression/test07.expr
Normal file
26
stdlib/regression/test07.expr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import Collection;
|
||||
|
||||
local a = {1, 2, 3}, b = {1, 2, 3}, t = emptyHashTab ();
|
||||
|
||||
t := addHashTab (t, a, 100);
|
||||
validateColl ();
|
||||
printf ("HashTab internal structure: %s\n", t.string);
|
||||
|
||||
t := addHashTab (t, b, 200);
|
||||
validateColl ();
|
||||
printf ("HashTab internal structure: %s\n", t.string);
|
||||
|
||||
printf ("Searching: %s\n", findHashTab (t, a).string);
|
||||
printf ("Searching: %s\n", findHashTab (t, b).string);
|
||||
|
||||
t := addHashTab (t, a, 800);
|
||||
validateColl (t);
|
||||
|
||||
printf ("Replaced: %s\n", findHashTab (t, a).string);
|
||||
|
||||
t := removeHashTab (t, a);
|
||||
validateColl (t);
|
||||
printf ("Restored: %s\n", findHashTab (t, a).string)
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue