/// <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 int GetHash(string data) { // Compute the hash return(BitConverter.ToInt32( Murmur32.GetBytes(Encoding.UTF8.GetBytes(data)), 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 int GetHash(byte[] data) { // Compute the hash return(BitConverter.ToInt32( Murmur32.GetBytes(data), 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 byte[] GetBytes(string data) { // Compute the hash return(Murmur32.GetBytes( Encoding.UTF8.GetBytes(data) )); }
/// <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 = Murmur32.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)); }