From dc0b5873a4fcfa46121d190238c052043e6d75ec Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Thu, 16 Oct 2014 16:42:21 +0200 Subject: [PATCH] CCMultiset: Add meet --- core/CCMultiSet.ml | 14 ++++++++++++-- core/CCMultiSet.mli | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/CCMultiSet.ml b/core/CCMultiSet.ml index 60640411..0dcd6707 100644 --- a/core/CCMultiSet.ml +++ b/core/CCMultiSet.ml @@ -51,6 +51,8 @@ module type S = sig val union : t -> t -> t + val meet : t -> t -> t + val intersection : t -> t -> t val diff : t -> t -> t @@ -117,11 +119,19 @@ module Make(O : Set.OrderedType) = struct M.merge (fun x n1 n2 -> match n1, n2 with | None, None -> assert false - | Some n1, None -> Some n1 - | None, Some n2 -> Some n2 + | Some n, None + | None, Some n -> Some n | Some n1, Some n2 -> Some (n1+n2)) m1 m2 + let meet m1 m2 = + M.merge + (fun _ n1 n2 -> match n1, n2 with + | None, None -> assert false + | Some n, None | None, Some n -> Some n + | Some n1, Some n2 -> Some (Pervasives.max n1 n2)) + m1 m2 + let intersection m1 m2 = M.merge (fun x n1 n2 -> match n1, n2 with diff --git a/core/CCMultiSet.mli b/core/CCMultiSet.mli index 4c994901..b11d0385 100644 --- a/core/CCMultiSet.mli +++ b/core/CCMultiSet.mli @@ -51,6 +51,8 @@ module type S = sig val union : t -> t -> t + val meet : t -> t -> t + val intersection : t -> t -> t val diff : t -> t -> t