From 432f0f0abda10b57ff2514b247d76fb300c9f2b1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 16 Oct 2014 16:50:04 +0200 Subject: [PATCH] comments in CCMultiSet.mli, to explain meet/intersection/union --- core/CCMultiSet.ml | 6 +++--- core/CCMultiSet.mli | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) 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