diff --git a/core/CCMultiSet.ml b/core/CCMultiSet.ml index 0dcd6707..2a0b2747 100644 --- a/core/CCMultiSet.ml +++ b/core/CCMultiSet.ml @@ -148,16 +148,16 @@ module Make(O : Set.OrderedType) = struct | Some n1, None -> Some n1 | None, Some n2 -> None | Some n1, Some n2 -> - if n1 > n2 + if n1 > n2 then Some (n1 - n2) else None) m1 m2 let contains m1 m2 = - try + try M.for_all (fun x c -> M.find x m1 >= c) m2 with Not_found -> false - + let compare m1 m2 = M.compare (fun x y -> x - y) m1 m2 diff --git a/core/CCMultiSet.mli b/core/CCMultiSet.mli index b11d0385..89d32f83 100644 --- a/core/CCMultiSet.mli +++ b/core/CCMultiSet.mli @@ -46,25 +46,35 @@ module type S = sig val remove : t -> elt -> t val min : t -> elt + (** Minimal element w.r.t the total ordering on elements *) val max : t -> elt val union : t -> t -> t + (** [union a b] contains as many occurrences of an element [x] + as [count a x + count b x]. *) val meet : t -> t -> t + (** [meet a b] is a multiset such that + [count (meet a b) x = max (count a x) (count b x)] *) val intersection : t -> t -> t + (** [intersection a b] is a multiset such that + [count (intersection a b) x = min (count a x) (count b x)] *) val diff : t -> t -> t + (** MultiSet difference. + [count (diff a b) x = max (count a x - count b x) 0] *) val contains : t -> t -> bool + (** [contains a x = (count m x > 0)] *) val compare : t -> t -> int val equal : t -> t -> bool val cardinal : t -> int - (** Number of distinct elements *) + (** Number of distinct elements *) val iter : t -> (int -> elt -> unit) -> unit