예제 #1
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
        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);
        }
예제 #2
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
        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);
        }
예제 #3
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
 public int GetCount(T item)
 {
     return(mSet.GetCount(item));
 }