File: bimap.ml

package info (click to toggle)
ocaml-deriving-ocsigen 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 1,159
  • sloc: ml: 6,334; makefile: 63; sh: 18
file content (25 lines) | stat: -rw-r--r-- 543 bytes parent folder | download | duplicates (4)
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
(* Bidirectional map {t -> t} *)

module type S =
sig
  type item
  type t
  val empty : t
  val add : item -> item -> t -> t
  val find : item -> t -> item
  val mem : item -> t -> bool
  val rmem : item -> t -> bool
end

module type OrderedType = sig type t val compare : t -> t -> int end
module Make (Ord : OrderedType) =
struct
  type item = Ord.t
  type t = (item * item) list
  let empty = []
  let add l r list = (l,r)::list
  let find = List.assoc
  let mem = List.mem_assoc
  let rmem item = List.exists (fun (_,i) -> i = item)
end