zoukankan      html  css  js  c++  java
  • HashCode

    public struct HashCode
        {
            private readonly int value;
    
            private HashCode(int value)
            {
                this.value = value;
            }
    
            public static implicit operator int(HashCode hashCode)
            {
                return hashCode.value;
            }
    
            public static HashCode Of<T>(T item)
            {
                return new HashCode(GetHashCode(item));
            }
    
            public HashCode And<T>(T item)
            {
                return new HashCode(CombineHashCodes(this.value, GetHashCode(item)));
            }
    
            public HashCode AndEach<T>(IEnumerable<T> items)
            {
                if (items == null)
                {
                    return new HashCode(this.value);
                }
    
                var hashCode = items.Any() ? items.Select(GetHashCode).Aggregate(CombineHashCodes) : 0;
                return new HashCode(CombineHashCodes(this.value, hashCode));
            }
    
            private static int CombineHashCodes(int h1, int h2)
            {
                unchecked
                {
                    // Code copied from System.Tuple so it must be the best way to combine hash codes or at least a good one.
                    return ((h1 << 5) + h1) ^ h2;
                }
            }
    
            private static int GetHashCode<T>(T item)
            {
                return item == null ? 0 : item.GetHashCode();
            }
        }
    
  • 相关阅读:
    Ruby gem命令
    C语言中的static关键字
    Linux下clock计时函数学习
    open-falcon之dashboardportal说明.md
    open-falcon之graph
    open-falcon之query
    open-falcon之HBS
    open-falcon之judge
    open-falcon之transfer
    open-falcon之agent
  • 原文地址:https://www.cnblogs.com/byxxw/p/10212283.html
Copyright © 2011-2022 走看看