package mset
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Mset.ENSource
The type of multisets. Immutable. Polymorphic equality, comparison, and hashing can be used on this type.
val empty : tthe empty multiset
val full : tthe full multiset, where each element has its maximal multiplicity
val size : t -> intreturns the size of the multiset i.e. the sum of all multiplicities
val is_empty : t -> boolreturns true if and only if the multiset is empty; this is equivalent to checking that the size is zero.
val is_full : t -> boolreturns true if and only if the multiset is full (the multiplicity of each element is maximal).
returns the mutiplicity of an element (and 0 if the element does not belong to the multiset)
adds one occurrence of an element (and fails with Invalid_argument if the capacity for that element is exceeded)
add x n ms adds n occurrences of element x to the multiset ms (or subtract from it if n is negative)
removes one occurrence of an element (and does nothing if the element does not belong to the multiset)
removes all occurrences of a given element (and does nothing if the element does not belong to the multiset)
returns a minimal element, if any, and raises Invalid_argument if the multiset is empty
inclusion ms1 ms2 tests whether the multiset ms1 is included is the multiset ms2 i.e. for any element from the universe, its multiplicity in ms1 is no larger than its multiplicity in ms2.
diff ms2 ms1 computes the difference of the multiset ms2 and the multiset ms1 i.e. for any element from the universe, the difference from its multiplicity in ms2 and its multiplicity in ms1. Raises Invalid_argument if ms1 is not included in ms2.
diff_no_check ms2 ms1 computes the difference of the multiset ms2 and the multiset ms1 assuming that ms1 is included in ms2. This is a programming error to use this function when ms1 is not included in ms2, and the result is not even guaranteed to be a valid multiset.
union ms1 ms2 computes the union of the multisets ms1 and ms2 i.e. for any element from the universe, the sum from its multiplicity in ms1 and its multiplicity in ms2. Raises Invalid_argument if the capacity is exceeded.
union_no_check ms1 ms2 computes the union of the multiset ms1 and the multiset ms2 assuming no capacity overflow. This is a programming error to use this function when the union exceeds the capacity, and the result is not even guaranteed to be a valid multiset.
Iterates over all the elements of the universe, in ascending order. For each element, it applies the given function to the element and its multiplicity in the given multiset. This iteration includes elements for which the multiplicity is zero.
iter_sub f ms iterates f over all the sub-multisets of ms. For each sub-multiset x, function f is applied to x and diff ms x.
fold_sub f ms folds f over all the sub-multisets of ms. For each sub-multiset x, function f is applied to x and diff ms x.
val nb_sub : t -> intTotal number of sub-multisets
val hash : t -> intThis is a total order over multisets.
This implements multiset ordering if we consider the elements being ordered according to the list given to function create below.
val print : (Format.formatter -> elt -> unit) -> Format.formatter -> t -> unitPrints a multiset in the following format:
{ a:3; b:0; c:1 }Elements appear in ascending order.
val print_nat :
(Format.formatter -> elt -> unit) ->
Format.formatter ->
t ->
unitPrints a multiset in the following format:
{ a,a,a,c }Elements appear in ascending order.
val print_compact :
(Format.formatter -> elt -> unit) ->
Format.formatter ->
t ->
unitPrints a multiset in the following format:
a3cElements appear in ascending order.