예제 #1
0
        public int GetHashCode(MultiSet <T> obj)
        {
            Utils.ThrowException(obj == null ? new ArgumentNullException("obj") : null);
            int hashCode = 0;

            foreach (KeyValuePair <T, int> item in obj)
            {
                hashCode ^= item.Key.GetHashCode() ^ item.Value.GetHashCode();
            }
            return(hashCode);
        }
예제 #2
0
 public bool Equals(MultiSet <T> .ReadOnly x, MultiSet <T> .ReadOnly y)
 {
     if (x == null && y == null)
     {
         return(true);
     }
     if (x == null || y == null)
     {
         return(false);
     }
     return(Equals(x.Inner, y.Inner));
 }
예제 #3
0
 public bool Equals(MultiSet <T> x, MultiSet <T> y)
 {
     if (x == null && y == null)
     {
         return(true);
     }
     if (x == null || y == null)
     {
         return(false);
     }
     return(x.Count == y.Count && MultiSet <T> .Difference(x, y).Count == 0);
 }
예제 #4
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
        public static double JaccardSimilarity(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   = Intersection(a, b);
            double       div = (double)(a.Count + b.Count - c.Count);

            if (div == 0)
            {
                return(1);
            }                           // *** if both sets are empty, the similarity is 1
            return((double)c.Count / div);
        }
예제 #5
0
 bool IEqualityComparer.Equals(object x, object y)
 {
     if (x is MultiSet <T> )
     {
         x = new MultiSet <T> .ReadOnly((MultiSet <T>) x);
     }
     if (y is MultiSet <T> )
     {
         y = new MultiSet <T> .ReadOnly((MultiSet <T>) y);
     }
     Utils.ThrowException((x != null && !(x is MultiSet <T> .ReadOnly)) ? new ArgumentTypeException("x") : null);
     Utils.ThrowException((y != null && !(y is MultiSet <T> .ReadOnly)) ? new ArgumentTypeException("y") : null);
     return(Equals((MultiSet <T> .ReadOnly)x, (MultiSet <T> .ReadOnly)y));
 }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
        // *** IContentEquatable<MultiSet<T>> interface implementation ***

        public bool ContentEquals(MultiSet <T> other)
        {
            if (other == null || Count != other.Count)
            {
                return(false);
            }
            foreach (KeyValuePair <T, int> item in mItems)
            {
                int count;
                if (other.mItems.TryGetValue(item.Key, out count))
                {
                    if (count != item.Value)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #9
0
 public int GetHashCode(MultiSet <T> .ReadOnly obj)
 {
     Utils.ThrowException(obj == null ? new ArgumentNullException("obj") : null);
     return(GetHashCode(obj.Inner));
 }
예제 #10
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
            // *** IContentEquatable<MultiSet<T>.ReadOnly> interface implementation ***

            public bool ContentEquals(MultiSet <T> .ReadOnly other)
            {
                return(other != null && mSet.ContentEquals(other.Inner));
            }
예제 #11
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
 public ReadOnly(BinarySerializer reader)
 {
     mSet = new MultiSet <T>(reader); // throws ArgumentNullException, serialization-related exceptions
 }
예제 #12
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
 public ReadOnly(MultiSet <T> set)
 {
     Utils.ThrowException(set == null ? new ArgumentNullException("set") : null);
     mSet = set;
 }
예제 #13
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
 public static double JaccardSimilarity(MultiSet <T> .ReadOnly a, MultiSet <T> .ReadOnly b)
 {
     Utils.ThrowException(a == null ? new ArgumentNullException("a") : null);
     Utils.ThrowException(b == null ? new ArgumentNullException("b") : null);
     return(JaccardSimilarity(a.Inner, b.Inner));
 }
예제 #14
0
파일: MultiSet.cs 프로젝트: 0000duck/latino
 public static MultiSet <T> Difference(MultiSet <T> .ReadOnly a, MultiSet <T> .ReadOnly b)
 {
     Utils.ThrowException(a == null ? new ArgumentNullException("a") : null);
     Utils.ThrowException(b == null ? new ArgumentNullException("b") : null);
     return(Difference(a.Inner, b.Inner));
 }