module Set:sig..end
Set module for Core.Std. We use "core_set" as the file
name rather than "set" to avoid conflicts with OCaml's standard set module.
This module uses the same organizational approach as Map. See the
documentation in core_map.mli for a description of the approach.
type ('elt, 'cmp) t
module Tree:sig..end
val invariants : ('a, 'b) t -> boolval comparator : ('a, 'cmp) t -> ('a, 'cmp) Comparator.tval empty : comparator:('a, 'cmp) Comparator.t -> ('a, 'cmp) tval singleton : comparator:('a, 'cmp) Comparator.t -> 'a -> ('a, 'cmp) tval length : ('a, 'b) t -> intval is_empty : ('a, 'b) t -> boolval mem : ('a, 'b) t -> 'a -> boolval add : ('a, 'cmp) t -> 'a -> ('a, 'cmp) tval remove : ('a, 'cmp) t -> 'a -> ('a, 'cmp) tval union : ('a, 'cmp) t -> ('a, 'cmp) t -> ('a, 'cmp) tval union_list : comparator:('a, 'cmp) Comparator.t ->
('a, 'cmp) t list -> ('a, 'cmp) tval inter : ('a, 'cmp) t -> ('a, 'cmp) t -> ('a, 'cmp) tval diff : ('a, 'cmp) t -> ('a, 'cmp) t -> ('a, 'cmp) tval compare_direct : ('a, 'cmp) t -> ('a, 'cmp) t -> intval equal : ('a, 'cmp) t -> ('a, 'cmp) t -> boolval exists : ('a, 'b) t -> f:('a -> bool) -> boolval for_all : ('a, 'b) t -> f:('a -> bool) -> boolval count : ('a, 'b) t -> f:('a -> bool) -> intval find : ('a, 'b) t -> f:('a -> bool) -> 'a optionval find_map : ('a, 'c) t -> f:('a -> 'b option) -> 'b optionval find_exn : ('a, 'b) t -> f:('a -> bool) -> 'aval find_index : ('a, 'b) t -> int -> 'a optionfind_index t i returns the ith smallest element of t in O(log n) time. The
smallest element has i = 0.val remove_index : ('a, 'cmp) t -> int -> ('a, 'cmp) tval subset : ('a, 'cmp) t -> ('a, 'cmp) t -> boolsubset t1 t2 returns true iff t1 is a subset of t2.val of_list : comparator:('a, 'cmp) Comparator.t -> 'a list -> ('a, 'cmp) tof_list and of_array need not be sorted.val of_array : comparator:('a, 'cmp) Comparator.t -> 'a array -> ('a, 'cmp) tval to_list : ('a, 'b) t -> 'a listto_list and to_array produce sequences sorted in ascending order according to the
comparator.val to_array : ('a, 'b) t -> 'a arrayval to_tree : ('a, 'cmp) t -> ('a, 'cmp) Tree.tval of_tree : comparator:('a, 'cmp) Comparator.t ->
('a, 'cmp) Tree.t -> ('a, 'cmp) tval of_sorted_array : comparator:('a, 'cmp) Comparator.t ->
'a array -> ('a, 'cmp) t Or_error.tval of_sorted_array_unchecked : comparator:('a, 'cmp) Comparator.t -> 'a array -> ('a, 'cmp) tof_sorted_array, but without checking the input array.val stable_dedup_list : comparator:('a, 'b) Comparator.t -> 'a list -> 'a liststable_dedup_list is here rather than in the List module because the
implementation relies crucially on sets, and because doing so allows one to avoid uses
of polymorphic comparison by instantiating the functor at a different implementation
of Comparator and using the resulting stable_dedup_list.val map : comparator:('b, 'cmp) Comparator.t ->
('a, 'c) t -> f:('a -> 'b) -> ('b, 'cmp) tval filter_map : comparator:('b, 'cmp) Comparator.t ->
('a, 'c) t -> f:('a -> 'b option) -> ('b, 'cmp) tval filter : ('a, 'cmp) t -> f:('a -> bool) -> ('a, 'cmp) tval fold : ('a, 'b) t -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accumval fold_until : ('a, 'b) t ->
init:'accum ->
f:('accum -> 'a -> [ `Continue of 'accum | `Stop of 'accum ]) -> 'accumval fold_right : ('a, 'b) t -> init:'accum -> f:('a -> 'accum -> 'accum) -> 'accumval iter : ('a, 'b) t -> f:('a -> unit) -> unitval iter2 : ('a, 'cmp) t ->
('a, 'cmp) t ->
f:([ `Both of 'a * 'a | `Left of 'a | `Right of 'a ] -> unit) -> unit0; 1 and 1; 2, f will be
called with `Left 0; `Both (1, 1); and `Right 2.val partition_tf : ('a, 'cmp) t ->
f:('a -> bool) -> ('a, 'cmp) t * ('a, 'cmp) ta, b = partition_tf set ~f then a is the elements on which f produced true,
and b is the elements on which f produces false.val elements : ('a, 'b) t -> 'a listSet.to_list.val min_elt : ('a, 'b) t -> 'a optionval min_elt_exn : ('a, 'b) t -> 'aval max_elt : ('a, 'b) t -> 'a optionval max_elt_exn : ('a, 'b) t -> 'aval choose : ('a, 'b) t -> 'a optionNone if the set is empty.val choose_exn : ('a, 'b) t -> 'aval split : ('a, 'cmp) t ->
'a -> ('a, 'cmp) t * bool * ('a, 'cmp) tsplit t x produces a triple (t1, b, t2) where t1 is the set of elements strictly
less than x, b = mem set x, and t2 is the set of elements strictly larger than
x.val group_by : ('a, 'cmp) t ->
equiv:('a -> 'a -> bool) -> ('a, 'cmp) t listequiv is an equivalence predicate, then group_by set ~equiv produces a list
of equivalence classes (i.e., a set-theoretic quotient). E.g.,
let chars = Set.of_list ['A'; 'a'; 'b'; 'c'] in
let equiv c c' = Char.equal (Char.uppercase c) (Char.uppercase c') in
group_by chars ~equiv
produces:
Set.of_list['A';'a']; Set.singleton 'b'; Set.singleton 'c']
group_by runs in O(n^2) time.
module Poly:sig..endwith type ('a, 'b) set := ('a, 'b) t
module type Elt = Core_set_intf.Eltmodule type Elt_binable = Core_set_intf.Elt_binablemodule type S =S0with type ('a, 'b) set := ('a, 'b) twith type ('a, 'b) tree := ('a, 'b) Tree.t
module type S_binable =S0_binablewith type ('a, 'b) set := ('a, 'b) twith type ('a, 'b) tree := ('a, 'b) Tree.t
module Make:
module Make_using_comparator:
module Make_binable:
module Make_binable_using_comparator:functor (Elt:Comparator.S_binable) ->S_binablewith type Elt.t = Elt.twith type Elt.comparator = Elt.comparator
val compare : ('elt -> 'elt -> int) ->
('cmp -> 'cmp -> int) ->
('elt, 'cmp) t -> ('elt, 'cmp) t -> intfind_index t i returns the ith smallest element of t in O(log n) time. The
smallest element has i = 0.subset t1 t2 returns true iff t1 is a subset of t2.of_list and of_array need not be sorted.to_list and to_array produce sequences sorted in ascending order according to the
comparator.of_sorted_array, but without checking the input array.stable_dedup_list is here rather than in the List module because the
implementation relies crucially on sets, and because doing so allows one to avoid uses
of polymorphic comparison by instantiating the functor at a different implementation
of Comparator and using the resulting stable_dedup_list.0; 1 and 1; 2, f will be
called with `Left 0; `Both (1, 1); and `Right 2.a, b = partition_tf set ~f then a is the elements on which f produced true,
and b is the elements on which f produces false.Set.to_list.None if the set is empty.split t x produces a triple (t1, b, t2) where t1 is the set of elements strictly
less than x, b = mem set x, and t2 is the set of elements strictly larger than
x.equiv is an equivalence predicate, then group_by set ~equiv produces a list
of equivalence classes (i.e., a set-theoretic quotient). E.g.,
let chars = Set.of_list ['A'; 'a'; 'b'; 'c'] in
let equiv c c' = Char.equal (Char.uppercase c) (Char.uppercase c') in
group_by chars ~equiv
produces:
Set.of_list['A';'a']; Set.singleton 'b'; Set.singleton 'c']
group_by runs in O(n^2) time.