Ejemplo n.º 1
0
 static void AssertCompareEqual(IEqualityComparer<NameAndNumber> comparer, NameAndNumber x, NameAndNumber y)
 {
     Assert.IsTrue(comparer.Equals(x, y));
     Assert.IsTrue(comparer.Equals(y, x));
     if (x != null && y != null)
     {
         Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
     }
 }
 internal int GetHashCode(TInputOutput element)
 {
     return
         ((HashCodeMask &
           (element == null ? NULL_ELEMENT_HASH_CODE : (_elementComparer?.GetHashCode(element) ?? element.GetHashCode())))
          % _distributionMod);
 }
 internal int GetHashCode(THashKey key)
 {
     return
         ((HashCodeMask &
           (key == null ? NULL_ELEMENT_HASH_CODE : (_keyComparer?.GetHashCode(key) ?? key.GetHashCode())))
          % _distributionMod);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a HashCode for the given type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">The object.</param>
        /// <param name="comparer">The comparer.</param>
        /// <returns></returns>
        public HashCode Hash <T>(T obj, IEqualityComparer <T> comparer = null)
        {
            var h = 0;

            // ReSharper disable once CompareNonConstrainedGenericWithNull
            if (obj != null)
            {
                h = comparer?.GetHashCode(obj) ?? obj.GetHashCode();
            }
            unchecked { h += GetHashCode() * MultiperPrime; }
            return(new HashCode(h));
        }
Ejemplo n.º 5
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + IsOk.GetHashCode();
         if (IsOk)
         {
             hash = hash * 23 + _valueComparer.GetHashCode(_value);
         }
         else
         {
             hash = hash * 23 + _errorComparer?.GetHashCode(_error) ?? 1;
         }
         return(hash);
     }
 }
 private void CheckEquality(Expression a, Expression b)
 {
     Assert.AreEqual(equalityComparer.GetHashCode(a), equalityComparer.GetHashCode(b));
     Assert.IsTrue(equalityComparer.Equals(a, b));
 }
 public static int GetSequenceHashCode <T>(this IEnumerable <T> source, IEqualityComparer <T> comparer)
 {
     return(source.Aggregate(23, (code, item) => code * 31 + (item == null ? 0 : comparer.GetHashCode(item))));
 }
 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
 {
     return(CombineHashCodes(CombineHashCodes(comparer.GetHashCode(this.QueryName), comparer.GetHashCode(this.Query)), typeof(NamedClause).GetHashCode()));
 }
 public int GetHashCode(IEqualityComparer comparer)
 {
     return comparer.GetHashCode(this);
 }
Ejemplo n.º 10
0
 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
     object obj;
     if (TryGetObject(out obj)) {
         return comparer.GetHashCode(obj);
     }
     return comparer.GetHashCode(null);
 }
        int IEqualityComparer <T> .GetHashCode(T obj)
        {
            var obj1 = _get(obj);

            return(_equalityComparer.GetHashCode(obj1));
        }
Ejemplo n.º 12
0
 uint Hash(TKey key)
 {
     return((uint)comparer.GetHashCode(key));
 }
Ejemplo n.º 13
0
        public FilePath(string rawPath)
        {
            (PathWithoutExtension, Extension) = SeparateExtension(NormalizedPath = NormalizePath(rawPath));

            hash = PathComparer.GetHashCode(NormalizedPath);
        }
Ejemplo n.º 14
0
 /// <inheritdoc />
 public int GetHashCode(Elem obj)
 {
     return((int)obj.alignment + chunkComparer.GetHashCode(obj.chunk));
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Invokes the method if this is something that the LazyInitializer can handle
        /// without the underlying proxied object being instantiated.
        /// </summary>
        /// <param name="method">The name of the method/property to Invoke.</param>
        /// <param name="args">The arguments to pass the method/property.</param>
        /// <param name="proxy">The proxy object that the method is being invoked on.</param>
        /// <returns>
        /// The result of the Invoke if the underlying proxied object is not needed.  If the
        /// underlying proxied object is needed then it returns the result <see cref="AbstractLazyInitializer.InvokeImplementation"/>
        /// which indicates that the Proxy will need to forward to the real implementation.
        /// </returns>
        public virtual object Invoke(MethodInfo method, object[] args, object proxy)
        {
            string methodName = method.Name;
            int    paramCount = method.GetParameters().Length;

            if (paramCount == 0)
            {
                if (!overridesEquals && methodName == "GetHashCode")
                {
                    return(IdentityEqualityComparer.GetHashCode(proxy));
                }
                else if (IsUninitialized && IsEqualToIdentifierMethod(method))
                {
                    return(Identifier);
                }
                else if (methodName == "Dispose")
                {
                    return(null);
                }
                else if ("get_HibernateLazyInitializer".Equals(methodName))
                {
                    return(this);
                }
            }
            else if (paramCount == 1)
            {
                if (!overridesEquals && methodName == "Equals")
                {
                    return(IdentityEqualityComparer.Equals(args[0], proxy));
                }
                else if (setIdentifierMethod != null && method.Equals(setIdentifierMethod))
                {
                    Initialize();
                    Identifier = args[0];
                    return(InvokeImplementation);
                }
            }
            else if (paramCount == 2)
            {
                // if the Proxy Engine delegates the call of GetObjectData to the Initializer
                // then we need to handle it.  Castle.DynamicProxy takes care of serializing
                // proxies for us, but other providers might not.
                if (methodName == "GetObjectData")
                {
                    SerializationInfo info    = (SerializationInfo)args[0];
                    StreamingContext  context = (StreamingContext)args[1];                    // not used !?!

                    if (Target == null & Session != null)
                    {
                        EntityKey key    = new EntityKey(Identifier, Session.Factory.GetEntityPersister(EntityName), Session.EntityMode);
                        object    entity = Session.PersistenceContext.GetEntity(key);
                        if (entity != null)
                        {
                            SetImplementation(entity);
                        }
                    }

                    // let the specific ILazyInitializer write its requirements for deserialization
                    // into the stream.
                    AddSerializationInfo(info, context);

                    // don't need a return value for proxy.
                    return(null);
                }
            }

            //if it is a property of an embedded component, invoke on the "identifier"
            if (componentIdType != null && componentIdType.IsMethodOf(method))
            {
                return(method.Invoke(Identifier, args));
            }

            return(InvokeImplementation);
        }
Ejemplo n.º 16
0
 public override int GetHashCode()
 {
     return(_comparer.GetHashCode(_key));
 }
Ejemplo n.º 17
0
 public int GetHashCode(IEqualityComparer comparer)
 {
     return(comparer.GetHashCode(_val));
 }
Ejemplo n.º 18
0
 public int GetHashCode(TKey obj) => _comparer.GetHashCode(obj);
 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
 {
     return(CombineHashCodes(comparer.GetHashCode(this.Query), typeof(PlainTextClause).GetHashCode()));
 }
Ejemplo n.º 20
0
 public override int GetHashCode()
 {
     return(FirstComparer.GetHashCode(first) * 37 +
            SecondComparer.GetHashCode(second));
 }
Ejemplo n.º 21
0
        public HashCodeCombiner Add <TValue>(TValue value, IEqualityComparer <TValue> comparer)
        {
            var hashCode = value != null?comparer.GetHashCode(value) : 0;

            return(Add(hashCode));
        }
Ejemplo n.º 22
0
        public void Add <TValue>(TValue value, IEqualityComparer <TValue> comparer)
        {
            int hashCode = value != null?comparer.GetHashCode(value) : 0;

            Add(hashCode);
        }
Ejemplo n.º 23
0
 public int GetHashCode(T obj)
 {
     return(_comparer.GetHashCode(_keySelector(obj)));
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Add helper that works over a single set of buckets.  Used for
        /// both the normal add case as well as the resize case.
        /// </summary>
        private bool Add(Bucket[] buckets, AnalysisValue key) {
            int hc = _comparer.GetHashCode(key) & Int32.MaxValue;

            return AddOne(buckets, key, hc);
        }
Ejemplo n.º 25
0
 public override int GetHashCode()
 {
     return(keyEqualityComparer.GetHashCode());
 }
Ejemplo n.º 26
0
 public int ValueGetHashCode() => ValueComparer.GetHashCode(this);
Ejemplo n.º 27
0
 /// <summary>
 /// Utility method to perform appropriate comparisons with the given comparer.
 /// For all tests:
 /// A10 == A10
 /// B15 == B15
 /// A10 != B15
 /// A10 != null
 /// B15 != null
 /// A10 might equal B10, and A10 might equal A15, depending on the comparer -
 /// this is in each individual test.
 /// </summary>
 static void TestComparisons(IEqualityComparer<NameAndNumber> comparer)
 {
     AssertCompareEqual(comparer, A10, A10);
     AssertCompareEqual(comparer, B15, B15);
     AssertCompareEqual(comparer, null, null);
     AssertCompareNotEqual(comparer, A10, B15);
     AssertCompareNotEqual(comparer, A10, null);
     AssertCompareNotEqual(comparer, B15, null);
     AssertCompareNotEqual(comparer, null, B15);
     AssertCompareNotEqual(comparer, null, A10);
     try
     {
         comparer.GetHashCode(null);
     }
     catch (ArgumentNullException)
     {
         // Expected
     }
 }
Ejemplo n.º 28
0
 int IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
     if (!_fHasHash) {
         object refObj = _target.Target;
         GC.KeepAlive(this);
         _hashVal = comparer.GetHashCode(refObj);
         _fHasHash = true;
     }
     return _hashVal;
 }
Ejemplo n.º 29
0
 public int GetHashCode(KeyValuePair <TKey, TValue> obj)
 {
     return(keyComparer.GetHashCode(obj.Key) ^ valueComparer.GetHashCode(obj.Value));
 }
Ejemplo n.º 30
0
 public void Add <T>(T value, IEqualityComparer <T>?comparer)
 {
     Add(comparer?.GetHashCode(value) ?? (value?.GetHashCode() ?? 0));
 }
Ejemplo n.º 31
0
 public int GetHashCode(DiffElement <T> obj)
 {
     return(_Comparer.GetHashCode(GetElement(obj)));
 }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 int IEqualityComparer <KeyValuePair <TKey, TValue> > .GetHashCode(KeyValuePair <TKey, TValue> obj)
 {
     return(_keyComparer.GetHashCode(obj.Key));
 }
Ejemplo n.º 33
0
 public int GetHashCode(T obj)
 {
     return(_wrapped.GetHashCode(obj));
 }
Ejemplo n.º 34
0
 public void Add <T>(T value, IEqualityComparer <T>?comparer)
 {
     Add(value is null ? 0 : (comparer?.GetHashCode(value) ?? value.GetHashCode()));
 }
Ejemplo n.º 35
0
 public int GetHashCode(ObservableGroupingView <TKey, TElement> obj)
 {
     return(obj == null ? 0 : keyComparer.GetHashCode(obj.Key));
 }