(*
* ISet - Interval sets
* Copyright (C) 1996-2003 Xavier Leroy, Nicolas Cannasse, Markus Mottl, Jacek Chrzaszcz
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
(** Interval Set.
This is an interval set, i.e. a set of integers, where large
intervals can be stored as single elements. Intervals stored in the
set are disjoint.
*)
type t
val empty : t
(** The empty set *)
val is_empty : t -> bool
(** returns true if the set is empty. *)
val add : int * int -> t -> t
(** [add (x, y) s] returns a set containing the same elements as [s],
plus all elements of the interval [[x,y]] including [x] and [y].
Assumes [x <= y]. *)
val remove : int * int -> t -> t
(** [remove (x, y) s] returns a set containing the same elements as [s],
except for all those which are included between [x] and [y].
Assumes [x <= y]. *)
val mem : int -> t -> bool
(** [mem x s] returns [true] if [s] contains [x], and [false] otherwise. *)
val iter : (int * int -> unit) -> t -> unit
(** [iter f s] applies [f] to all continuous intervals in the set [s].
The intervals are passed to [f] in increasing order. *)
val fold : (int * int -> 'a -> 'a) -> t -> 'a -> 'a
(** [fold f s a] computes [(f xN ... (f x2 (f x1 a))...)], where x1
... xN are all continuous intervals of s, in increasing order. *)
val elements : t -> (int * int) list
(** Return the list of all continuous intervals of the given set.
The returned list is sorted in increasing order. *)
val below : int -> t -> int
(** [below n s] returns the number of elements of [s] that are lesser
or equal to [n]. If there are more than max_int such elements,
the result should be max_int. *)
val split : int -> t -> t * bool * t
(** [split x s] returns a triple [(l, present, r)], where
[l] is the set of elements of [s] that are strictly lesser than [x];
[r] is the set of elements of [s] that are strictly greater than [x];
[present] is [false] if [s] contains no element equal to [x],
or [true] if [s] contains an element equal to [x]. *)