This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
forked from RobYang1024/OCaMOSS
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dictionary.mli
76 lines (51 loc) · 1.8 KB
/
dictionary.mli
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
(* A [Comparable] is a value that can be compared. *)
module type Comparable = sig
(* Type t gives the type of the value that is stored in the comparable. *)
type t
(* [compare t1 t2] returns a positive number if t1 is greater than t2,
* a negative number if it is less than t2 and 0 if they are equal.
*)
val compare: t -> t -> int
end
module type Formattable = sig
type t
val format: t -> unit
end
(* A [Dictionary] maps keys to values. The keys
* must be comparable, but there are no restrictions
* on the values.
*)
module type Dictionary = sig
module Key : Comparable
module Value : Formattable
type key = Key.t
type value = Value.t
(* Type t represents how the dictionary itself is implemented and stored as.
*)
type t
(* [empty] represents an empty dictionary. *)
val empty : t
(* [size d] represents the size of the dictionary d. *)
val size : t -> int
(* [member k dict] returns true if k is a binding in the dictionary d
* and false if not.
*)
val member : key -> t -> bool
(* [find k dict] returns None if k is not a binding in dict, and Some v
* if v is the value bound to k in dict.
*)
val find : key -> t -> value option
(* [insert k v dict] adds a new binding of k with value v to dict if k is not
* in dict already, and binds k to a new value v if it is already
* present in the dictionary, and returns the new dictionary.
*)
val insert : key -> value -> t -> t
(* [to_list dict] returns an association list where each element of the list
* is a tuple of a key and it's corresponding value in dict. *)
val to_list : t -> (key * value) list
end
module type DictionaryMaker =
functor (K : Comparable)
-> functor (V : Formattable)
-> Dictionary with module Key = K and module Value = V
module HashtblDict : DictionaryMaker