module BatISet:sig..end
DIET : Discrete Interval Encoding Trees
Sets of integers represented as ranges
This data structure is efficient for large sets of integers where many adjacent integers are all part of the set. This will have higher overhead for sets with lots of point elements, but will be much more efficient for sets containing mostly ranges.
typet =(int * int) BatAvlTree.tree
the underlying representation is a balanced tree of ranges
typeelt =int
This kind of set only holds ints
val empty : tThe empty set
val is_empty : t -> boolTest whether a set is empty, returns true if the set is empty.
val mem : int -> t -> booltest whether a given int is a member of the set
val add : int -> t -> tAdd the given int to the set, returning a new set
val add_range : int -> int -> t -> tadd_range lo hi t adds the range of integers lo, hi (including both endpoints) to
the given set, returning a new set
Invalid_argument if lo > hival singleton : int -> tReturn the singleton set containing only the given element
val remove : int -> t -> tRemove an element from the given set, returning a new set
val remove_range : int -> int -> t -> tremove_range lo hi t removes a range of elements from the given set, returning a new set
Invalid_argument if lo > hival union : t -> t -> tCompute the union of two sets. This is the set whose elements are those elements in either input set.
val inter : t -> t -> tCompute the intersection of two sets. This is the set whose elements are those in *both* of the input sets.
val diff : t -> t -> tCompute the difference between two sets. This is the set of
elements that are in the first but not in the second. Unlike
union and inter, order matters here.
val compl : t -> tCreate the complement of the given set - i.e. the set of all values not in the input set.
val compare : t -> t -> intCompare two sets. It is not safe to use the polymorphic (<) and related functions to compare these sets, as the tree representation used can balance in multiple ways.
val equal : t -> t -> boolTest whether two sets are equal. It is not safe to use the polymorphic (=) on these sets, as the same set can have multiple representations depending on how it was built.
val ord : t -> t -> BatOrd.orderSame as compare but returns BatOrd.Lt | BatOrd.Eq | BatOrd.Gt
instead of an int.
val subset : t -> t -> boolsubset t u returns true if t is a subset of u
val from : int -> t -> tfrom x t returns the portion of t in the range x, max_int
val after : int -> t -> tafter x t returns the portion of t in the range x+1, max_int
val until : int -> t -> tuntil x t returns the portion of t in the range min_int, x
val before : int -> t -> tbefore x t returns the portion of t in the range min_int, x-1
val iter : (int -> unit) -> t -> unititer f t calls f once for each element of t
val iter_range : (int -> int -> unit) -> t -> unititer_range f t calls f once for each contiguous range of t.
The contiguous ranges of a set are sequences of adjacent integers
all part of the set.
val fold : (int -> 'a -> 'a) -> t -> 'a -> 'afold f t x0 returns the final result of merging each element of
t into x0 using merge function f
val fold_range : (int -> int -> 'a -> 'a) -> t -> 'a -> 'aAs fold, but operates on contiguous ranges
val for_all : (int -> bool) -> t -> boolTests whether a predicate applies to all elements of the set
val exists : (int -> bool) -> t -> boolTest whether some element of a set satisfies a predicate
val filter : (int -> bool) -> t -> tBuilds the subset of those elements that satisfy the predicate
val partition : (int -> bool) -> t -> t * tpartitions the input set into two sets with elements that satisfy the predicate and those that don't
val cardinal : t -> intReturns the number of elements in the set
val elements : t -> int listReturns a list of all elements in the set
val ranges : t -> (int * int) listReturns a list of all contiguous ranges in the set
val min_elt : t -> intReturns the minimum element in the set
val max_elt : t -> intReturns the maximum element in the set
val choose : t -> intReturns some element in the set
val enum : t -> (int * int) BatEnum.tEnumerates all contiguous ranges in the set
val of_enum : (int * int) BatEnum.t -> t
val of_list : (int * int) list -> tBuild a ISet.t out of a list or enum of ranges
val print : 'a BatIO.output -> t -> unit