예제 #1
0
        /// <inheritdoc />
        public override int GetHashCode(IImmutableSet <T> obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            int result = 0;

            foreach (T value in obj)
            {
                result ^= value.GetHashCodeNullSafe();
            }

            return(result);
        }
        /// <inheritdoc />
        public override int GetHashCode(IReadOnlyDictionary <TKey, TValue> obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            int result = 0;

            foreach (KeyValuePair <TKey, TValue> pair in obj)
            {
                result ^= this.keyComparer.GetHashCode(pair.Key);
                result ^= this.valueComparer.GetHashCode(pair.Value);
            }

            return(result);
        }
예제 #3
0
        /// <inheritdoc />
        public override int GetHashCode(BitArray obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            unchecked
            {
                int[] values = obj.CopyToIntArray();

                int hash = 13;

                foreach (int value in values)
                {
                    hash = (hash * 7) + value;
                }

                return(hash);
            }
        }
예제 #4
0
        /// <inheritdoc />
        public int GetHashCode(object obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            // if there is a comparer registered for the type then use that
            IEqualityComparer comparer;

            if (this.comparerPerType.TryGetValue(obj.GetType(), out comparer))
            {
                return(comparer.GetHashCode(obj));
            }

            // check if the type is structurally equatable, and if so pass this comparer as the structural comparer
            IStructuralEquatable structuralEquatable = obj as IStructuralEquatable;

            if (structuralEquatable != null)
            {
                return(structuralEquatable.GetHashCode(this));
            }

            // otherwise fall back on regular hashcode
            return(obj.GetHashCode());
        }
        /// <inheritdoc />
        public override int GetHashCode(T obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            return(obj.GetHashCodeByReferenceNullSafe());
        }
        /// <inheritdoc />
        public override int GetHashCode(TEnum obj)
        {
            IEqualityComparerContracts.GetHashCode(obj);

            return(this.getHashCode(obj));
        }
        /// <inheritdoc />
        public override int GetHashCode(KeyValuePair <TKey, TValue> pair)
        {
            IEqualityComparerContracts.GetHashCode(pair);

            return(pair.Key.GetHashCodeNullSafe());
        }