Esempio n. 1
0
        static ulong ByteArrayGetHashCode(byte[] x, int offset, int count)
        {
#if NETSTANDARD
            // FarmHash https://github.com/google/farmhash
            if (x == null || x.Length == 0 || count == 0)
            {
                return(0);
            }

            if (Is32Bit)
            {
                return((ulong)FarmHash.Hash32(x, offset, count));
            }
            else
            {
                return(FarmHash.Hash64(x, offset, count));
            }
#else
            // FNV1-1a 32bit https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
            uint hash = 0;
            if (x != null)
            {
                var max = offset + count;

                hash = 2166136261;
                for (int i = offset; i < max; i++)
                {
                    hash = unchecked ((x[i] ^ hash) * 16777619);
                }
            }

            return((ulong)hash);
#endif
        }
Esempio n. 2
0
 public static int GetHashCode(byte[] bytes, int offset, int count)
 {
     if (Is32Bit)
     {
         return(unchecked ((int)FarmHash.Hash32(bytes, offset, count)));
     }
     else
     {
         return(unchecked ((int)FarmHash.Hash64(bytes, offset, count)));
     }
 }