Esempio n. 1
0
        public static MultiSet <T> Difference(MultiSet <T> a, MultiSet <T> b)
        {
            Utils.ThrowException(a == null ? new ArgumentNullException("a") : null);
            Utils.ThrowException(b == null ? new ArgumentNullException("b") : null);
            MultiSet <T> c = new MultiSet <T>(a.Comparer); // *** inherits comparer from a (b is expected to have the same comparer)

            foreach (KeyValuePair <T, int> item in a)
            {
                int bCount = b.GetCount(item.Key);
                int cCount = item.Value - bCount;
                if (cCount > 0)
                {
                    c.mItems.Add(item.Key, cCount);
                }
            }
            return(c);
        }
Esempio n. 2
0
        public static MultiSet <T> Intersection(MultiSet <T> a, MultiSet <T> b)
        {
            Utils.ThrowException(a == null ? new ArgumentNullException("a") : null);
            Utils.ThrowException(b == null ? new ArgumentNullException("b") : null);
            MultiSet <T> c = new MultiSet <T>(a.Comparer); // *** inherits comparer from a (b is expected to have the same comparer)

            if (b.Count < a.Count)
            {
                MultiSet <T> tmp; tmp = a; a = b; b = tmp;
            }
            foreach (KeyValuePair <T, int> item in a)
            {
                int bCount = b.GetCount(item.Key);
                if (bCount > 0)
                {
                    c.mItems.Add(item.Key, Math.Min(item.Value, bCount));
                }
            }
            return(c);
        }
Esempio n. 3
0
 public int GetCount(T item)
 {
     return(mSet.GetCount(item));
 }