Пример #1
0
        /// <summary>
        /// Computes MurmurHash3 on this set of bytes and returns the calculated hash value.
        /// </summary>
        /// <param name="data">The data to compute the hash of.</param>
        /// <returns>A 32bit hash value.</returns>
        public static uint GetHash(byte[] data)
        {
            // Compute the hash
            var buffer = SecurityHash.GetBytes(data);

            return((uint)
                   (buffer[0] << 24
                    | (buffer[1] << 16)
                    | (buffer[2] << 8)
                    | (buffer[3])));
        }
Пример #2
0
        /// <summary>
        /// Computes MurmurHash3 on this set of bytes and returns the calculated hash value.
        /// </summary>
        /// <param name="data">The data to compute the hash of.</param>
        /// <returns>A 32bit hash value.</returns>
        public static uint GetHash(string data)
        {
            // Compute the hash
            var buffer = SecurityHash.GetBytes(Encoding.UTF8.GetBytes(data));

            return((uint)
                   (buffer[0] << 24
                    | (buffer[1] << 16)
                    | (buffer[2] << 8)
                    | (buffer[3])));
        }
Пример #3
0
        /// <summary>
        /// Computes MurmurHash3 on this set of bytes and returns the calculated hash value.
        /// </summary>
        /// <param name="data">The data to compute the hash of.</param>
        /// <returns>A 32bit hash value.</returns>
        public static string GetHex(byte[] data)
        {
            // Compute the hash
            var bytes = SecurityHash.GetBytes(data);

            // Convert to string
            char[] chars = new char[bytes.Length * 2];
            byte   current;

            for (int y = 0, x = 0; y < bytes.Length; ++y, ++x)
            {
                current    = ((byte)(bytes[y] >> 4));
                chars[x]   = (char)(current > 9 ? current + 0x37 : current + 0x30);
                current    = ((byte)(bytes[y] & 0xF));
                chars[++x] = (char)(current > 9 ? current + 0x37 : current + 0x30);
            }

            // Get the hash of the string representation
            return(new string(chars));
        }