Initial packaging
[pkg-ocaml-deriving-ocsigen.git] / tests / bimap.ml
blob878c9dd6f93b27320866713f3175e3e358d7e28b
1 (* Bidirectional map {t -> t} *)
3 module type S =
4 sig
5 type item
6 type t
7 val empty : t
8 val add : item -> item -> t -> t
9 val find : item -> t -> item
10 val mem : item -> t -> bool
11 val rmem : item -> t -> bool
12 end
14 module type OrderedType = sig type t val compare : t -> t -> int end
15 module Make (Ord : OrderedType) =
16 struct
17 type item = Ord.t
18 type t = (item * item) list
19 let empty = []
20 let add l r list = (l,r)::list
21 let find = List.assoc
22 let mem = List.mem_assoc
23 let rmem item = List.exists (fun (_,i) -> i = item)
24 end