type elt = tThe type of the set elements.
val empty : tThe empty set.
val is_empty : t -> boolTest whether a set is empty or not.
val add : elt -> t -> tadd x sreturns a set containing all elements ofs, plusx. Ifxwas already ins,sis returned unchanged (the result of the function is then physically equal tos).- before 4.03
Physical equality was not ensured.
val remove : elt -> t -> tremove x sreturns a set containing all elements ofs, exceptx. Ifxwas not ins,sis returned unchanged (the result of the function is then physically equal tos).- before 4.03
Physical equality was not ensured.
val compare : t -> t -> intTotal ordering between sets. Can be used as the ordering function for doing sets of sets.
val equal : t -> t -> boolequal s1 s2tests whether the setss1ands2are equal, that is, contain equal elements.
val iter : (elt -> unit) -> t -> unititer f sappliesfin turn to all elements ofs. The elements ofsare presented tofin increasing order with respect to the ordering over the type of the elements.
val map : (elt -> elt) -> t -> tmap f sis the set whose elements aref a0,f a1...f aN, wherea0,a1...aNare the elements ofs.The elements are passed to
fin increasing order with respect to the ordering over the type of the elements.If no element of
sis changed byf,sis returned unchanged. (If each output offis physically equal to its input, the returned set is physically equal tos.)- since
- 4.04.0
val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'afold f s acomputes(f xN ... (f x2 (f x1 a))...), wherex1 ... xNare the elements ofs, in increasing order.
val for_all : (elt -> bool) -> t -> boolfor_all p schecks if all elements of the set satisfy the predicatep.
val exists : (elt -> bool) -> t -> boolexists p schecks if at least one element of the set satisfies the predicatep.
val filter : (elt -> bool) -> t -> tfilter p sreturns the set of all elements insthat satisfy predicatep. Ifpsatisfies every element ins,sis returned unchanged (the result of the function is then physically equal tos).- before 4.03
Physical equality was not ensured.
val partition : (elt -> bool) -> t -> t * tpartition p sreturns a pair of sets(s1, s2), wheres1is the set of all the elements ofsthat satisfy the predicatep, ands2is the set of all the elements ofsthat do not satisfyp.
val cardinal : t -> intReturn the number of elements of a set.
val elements : t -> elt listReturn the list of all elements of the given set. The returned list is sorted in increasing order with respect to the ordering
Ord.compare, whereOrdis the argument given toSet.Make.
val min_elt : t -> eltReturn the smallest element of the given set (with respect to the
Ord.compareordering), or raiseNot_foundif the set is empty.
val min_elt_opt : t -> elt optionReturn the smallest element of the given set (with respect to the
Ord.compareordering), orNoneif the set is empty.- since
- 4.05
val max_elt_opt : t -> elt optionSame as
Set.S.min_elt_opt, but returns the largest element of the given set.- since
- 4.05
val choose : t -> eltReturn one element of the given set, or raise
Not_foundif the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.
val choose_opt : t -> elt optionReturn one element of the given set, or
Noneif the set is empty. Which element is chosen is unspecified, but equal elements will be chosen for equal sets.- since
- 4.05
val split : elt -> t -> t * bool * tsplit x sreturns a triple(l, present, r), wherelis the set of elements ofsthat are strictly less thanx;ris the set of elements ofsthat are strictly greater thanx;presentisfalseifscontains no element equal tox, ortrueifscontains an element equal tox.
val find : elt -> t -> eltfind x sreturns the element ofsequal tox(according toOrd.compare), or raiseNot_foundif no such element exists.- since
- 4.01.0
val find_opt : elt -> t -> elt optionfind_opt x sreturns the element ofsequal tox(according toOrd.compare), orNoneif no such element exists.- since
- 4.05
val find_first : (elt -> bool) -> t -> eltfind_first f s, wherefis a monotonically increasing function, returns the lowest elementeofssuch thatf e, or raisesNot_foundif no such element exists.For example,
find_first (fun e -> Ord.compare e x >= 0) swill return the first elementeofswhereOrd.compare e x >= 0(intuitively:e >= x), or raiseNot_foundifxis greater than any element ofs.- since
- 4.05
val find_first_opt : (elt -> bool) -> t -> elt optionfind_first_opt f s, wherefis a monotonically increasing function, returns an option containing the lowest elementeofssuch thatf e, orNoneif no such element exists.- since
- 4.05
val find_last : (elt -> bool) -> t -> eltfind_last f s, wherefis a monotonically decreasing function, returns the highest elementeofssuch thatf e, or raisesNot_foundif no such element exists.- since
- 4.05
val find_last_opt : (elt -> bool) -> t -> elt optionfind_last_opt f s, wherefis a monotonically decreasing function, returns an option containing the highest elementeofssuch thatf e, orNoneif no such element exists.- since
- 4.05
val of_list : elt list -> tof_list lcreates a set from a list of elements. This is usually more efficient than foldingaddover the list, except perhaps for lists with many duplicated elements.- since
- 4.02.0
Iterators
val to_seq_from : elt -> t -> elt Stdlib.Seq.tto_seq_from x siterates on a subset of the elements ofsin ascending order, fromxor above.- since
- 4.07
val to_seq : t -> elt Stdlib.Seq.tIterate on the whole set, in ascending order
- since
- 4.07
val add_seq : elt Stdlib.Seq.t -> t -> tAdd the given elements to the set, in order.
- since
- 4.07
val of_seq : elt Stdlib.Seq.t -> tBuild a set from the given bindings
- since
- 4.07