collections/multiset_utils library

Multi-set (bag) union/intersection/difference — roadmap #464.

Functions

multisetDifference<T>(Map<T, int> a, Map<T, int> b) Map<T, int>
Returns the multiset difference a minus b, subtracting counts and dropping any element whose remaining count falls to zero or below.
multisetIntersection<T>(Map<T, int> a, Map<T, int> b) Map<T, int>
Returns the multiset intersection of a and b, keeping each shared element with the minimum of its two counts. Elements absent from either input are omitted.
multisetUnion<T>(Map<T, int> a, Map<T, int> b) Map<T, int>
Bag: count per element. Union = max counts, intersection = min, difference = a - b (floor 0).