Multiset.Makemodule Ord : OrderedTypetype elt = Ord.tThe type of the multiset elements.
val empty : tThe empty set.
(support t) is the list of all the distinct (under Ord.compare) elements of the multiset t.
Note that each of the elements in the result is an arbitrary exemplar of its equivalent repetitions.
support is equivalent to (to_list >> sort_uniq Ord.compare) but is faster.
val support_size : t -> int(support_size) is (len << support) but is faster.
See also support_size.
val cardinal : t -> int(cardinal t) is the sum of the multiplicities of all the elements of t.
val size : t -> intsize is cardinal.
val is_empty : t -> bool(is_empty t) is true iff t is empty.
(equal a b) is true iff both multisets contain the same elements, and the same repetitions of elements.
(subset a b) is true iff all the distinct elements of a are contained in b, and the multiplicity of each element of a is <= the multiplicity of the corresponding element of b.
(for_all p t) is true iff all elements of t satisfy the predicate p.
(exists p t) is true iff at least one element of t satisfies the predicate p.
(of_list xs) is the multiset containing containing all the elements of xs.
(split x t) is a triple (l, present, r), where l is the multiset of elements of t that are strictly less than x; r is the multiset of elements of t that are strictly greater than x; present is false if t contains no element equal to x, or true if t contains an element equal to x.
If you also need the repetitions of x, you can call (find x t).
(add elt t) is the multiset t with elt added.
Invariant: (multiplicity elt (add elt t)) = (1 + multiplicity elt t)
(addwhen p x t) is (add x t) when p x = true and otherwise is t.
(remove elt t) is the multiset that contains all the elements of t excepting elt.
All repetitions of elt are removed.
Invariants:
(mem x (remove x t)) = false(multiplicity x (remove x t)) = 0(replace elt reps t) is t with all the repetitions of elt replaced by reps.
(iter f t) iterates f across each distinct element of t; the repetitions of each element are given to f as a list.
(flatiter f t) iterates f over all the repetitions of all the elements of t.
flatiter f is equivalent to (iter (List.iter f)).
(map f t) is a multiset where all repetitions of all elements have been replaced by the result of applying f to those elements.
(flatfold f t init) computes (f xn ... (f x2 (f x1 init))...), where x1 ... xn are the repetitions of all elements of t, in increasing order.
(fold f t init) is like flatfold except that f is called once for each distinct distinct element of t, and f receives the repetitions of an element as a list.
(filter p t) is the multiset of all elements that satisfy the predicate p.
p is applied to each repetition of each distinct element.
(partition p t) returns a pair of multisets (t1, t2), where t1 is the multiset of all the elements of t that satisfy the predicate p, and t2 is the multiset of all the elements of t that do not satisfy p.
(union s t) is the maximum or lowest common multiple of multisets s and t.
See sum for what seems to me a more practical function.
(sum s t) is the disjoint union of s and t.
The sum contains the union of the distinct elements of s and t, and the repetitions of each element is the union of its repetitions in the two original sets..
Invariants:
(support (sum s t)) = List.union (support s) (support t)(sort Ord.compare (elements (sum s t))) = sort Ord.compare (elements s @ elements t)(diff s t) is the multiset that contains the distinct elements of s that are not in t.
(find elt t) is the list of the repetitions of elt in t.
Invariant: (len (default [] (find elt) t)) = (multiplicity elt t)
(elements t) are all the repetitions of all the distinct elements of t, in ascending order of Ord.compare.
Invariant:
len (support t) <= len (elements t)(repetitions t) is the list of all repetitions of each distinct element, in ascending order of Ord.compare, in the form of a list of lists.
Invariants:
(len << repetitions) = (len << support)(repetitions >> List.map len >> List.sum) = cardinalflatten (repetitions t) = elements t(choose t) is the set of repetitions of one distinct element of the given multiset. Which element is chosen is unspecified, but equal elements will be chosen for equal multisets.
(choose t) is the set of repetitions of one distinct element of the given multiset; if the multiset is empty, the result is None. Which element is chosen is unspecified, but equal elements will be chosen for equal multisets.
(find_first f t) where f is a monotonically increasing function, returns the repetitions of the lowest element e of t such that (f e).
(find_first_opt f) is (catch (find_first_opt f)).
(find_last f t) where f is a monotonically decreasing function, returns the repetitions of the highest element e of t such that (f e).
(find_last_opt f) is (catch (find_last_opt f)).
(to_seq_from elt t) is (to_seq t) but containing only those elements from elt or above.
(to_string ?(sep=", ") f t) returns a string representation of the multiset t, where the string representation of each elt is given by f.
(print ?sep f t) is (to_string ?sep f t |> print_endline).