-
Notifications
You must be signed in to change notification settings - Fork 9
/
chap_hashtable.dats
101 lines (91 loc) · 1.91 KB
/
chap_hashtable.dats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
(*
** For ATS2TUTORIAL
*)
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
local
//
typedef
key = string and itm = int
//
in (* in-of-local *)
#include "libats/ML/HATS/myhashtblref.hats"
end // end of [local]
(* ****** ****** *)
//
val mymap = myhashtbl_make_nil(1000)
//
val () =
fprintln! (stdout_ref, "mymap.size = ", mymap.size())
val () =
fprintln! (stdout_ref, "mymap.capacity = ", mymap.capacity())
//
(* ****** ****** *)
//
val-~None_vt() = mymap.insert("a", 0)
val-~Some_vt(0) = mymap.insert("a", 1)
//
val-~None_vt() = mymap.insert("b", 1)
val-~Some_vt(1) = mymap.insert("b", 2)
//
val-~None_vt() = mymap.insert("c", 2)
val-~Some_vt(2) = mymap.insert("c", 3)
//
(* ****** ****** *)
//
val () = assertloc (mymap.size() = 3)
val () = fprintln! (stdout_ref, "mymap = ", mymap)
//
(* ****** ****** *)
val-~None_vt() = mymap.search("")
val-~Some_vt(1) = mymap.search("a")
(* ****** ****** *)
//
val-true = mymap.remove("a")
val-false = mymap.remove("a")
//
val-~Some_vt(2) = mymap.takeout("b")
val-~Some_vt(3) = mymap.takeout("c")
//
(* ****** ****** *)
//
val () = assertloc (mymap.size() = 0)
//
(* ****** ****** *)
//
val () = mymap.insert_any("a", 0)
val () = mymap.insert_any("b", 1)
val () = mymap.insert_any("c", 2)
val kxs = mymap.listize1((*void*))
val ((*void*)) = fprintln! (stdout_ref, "kxs = ", kxs)
val kxs = mymap.takeout_all((*void*))
val ((*void*)) = fprintln! (stdout_ref, "kxs = ", kxs)
//
val () = assertloc (mymap.size() = 0)
//
(* ****** ****** *)
//
val () = mymap.insert_any("a", 0)
val () = mymap.insert_any("b", 1)
val () = mymap.insert_any("c", 2)
//
val () =
myhashtbl_foreach_cloref
(
mymap
, lam (k, x) =>
fprintln! (stdout_ref, "k=", k, " and ", "x=", x)
) (* myhashtbl_foreach_cloref *)
//
val () =
mymap.foreach()
(lam(k, x) => println! ("k=", k, " and ", "x=", x))
//
(* ****** ****** *)
implement main0 () = {}
(* ****** ****** *)
(* end of [chap_hashtable.dats] *)