1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the GNU Library General Public License. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Sets over ordered types.
|
1995-08-09 06:15:01 -07:00
|
|
|
|
2001-10-26 16:33:00 -07:00
|
|
|
This module implements the set data structure, given a total ordering
|
1995-08-09 06:15:01 -07:00
|
|
|
function over the set elements. All operations over sets
|
|
|
|
are purely applicative (no side-effects).
|
|
|
|
The implementation uses balanced binary trees, and is therefore
|
|
|
|
reasonably efficient: insertion and membership take time
|
2001-10-26 16:33:00 -07:00
|
|
|
logarithmic in the size of the set, for instance.
|
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
module type OrderedType = sig type t val compare : t -> t -> int end
|
2001-10-26 16:33:00 -07:00
|
|
|
(** The input signature of the functor {!Set.Make}.
|
|
|
|
[t] is the type of the set elements.
|
|
|
|
[compare] is a total ordering function over the set elements.
|
|
|
|
This is a two-argument function [f] such that
|
|
|
|
[f e1 e2] is zero if the elements [e1] and [e2] are equal,
|
|
|
|
[f e1 e2] is strictly negative if [e1] is smaller than [e2],
|
|
|
|
and [f e1 e2] is strictly positive if [e1] is greater than [e2].
|
|
|
|
Example: a suitable ordering function is
|
|
|
|
the generic structural comparison function {!Pervasives.compare}. *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
module type S =
|
|
|
|
sig
|
|
|
|
type elt
|
|
|
|
type t
|
2001-12-03 14:16:03 -08:00
|
|
|
val empty : t
|
|
|
|
val is_empty : t -> bool
|
|
|
|
val mem : elt -> t -> bool
|
|
|
|
val add : elt -> t -> t
|
|
|
|
val singleton : elt -> t
|
|
|
|
val remove : elt -> t -> t
|
|
|
|
val union : t -> t -> t
|
|
|
|
val inter : t -> t -> t
|
|
|
|
val diff : t -> t -> t
|
|
|
|
val compare : t -> t -> int
|
|
|
|
val equal : t -> t -> bool
|
|
|
|
val subset : t -> t -> bool
|
|
|
|
val iter : (elt -> unit) -> t -> unit
|
|
|
|
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
|
|
|
|
val for_all : (elt -> bool) -> t -> bool
|
|
|
|
val exists : (elt -> bool) -> t -> bool
|
|
|
|
val filter : (elt -> bool) -> t -> t
|
|
|
|
val partition : (elt -> bool) -> t -> t * t
|
|
|
|
val cardinal : t -> int
|
|
|
|
val elements : t -> elt list
|
|
|
|
val min_elt : t -> elt
|
|
|
|
val max_elt : t -> elt
|
|
|
|
val choose : t -> elt
|
1995-05-04 03:15:53 -07:00
|
|
|
end
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
module Make (Ord : OrderedType) : S with type elt = Ord.t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Functor building an implementation of the set structure
|
2001-12-03 14:16:03 -08:00
|
|
|
given a totally ordered type. *)
|