/// <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 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 byte[] GetBytes(string data) { // Compute the hash return(Murmur32.GetBytes( Encoding.UTF8.GetBytes(data) )); }
/// <summary> /// Constructs the state object. /// </summary> static EmitterStatus() { try { // Prepare the datastructure Default = new EmitterStatus(); Default.Network = new EmitterStatusNetwork(); // Use the provider and get the external ip Address = EmitterConfig.Default.Cluster.BroadcastEndpoint.ToString(); // Hash both values into one integer NodeIdentifier = Murmur32.GetHash(Address); } catch (Exception ex) { // Log the exception here Service.Logger.Log(ex); } }
/// <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)); }
/// <summary> /// Gets the node identifier from the endpoint. /// </summary> /// <param name="ep">The endpoint to convert.</param> /// <returns></returns> internal static int ToIdentifier(this IPEndPoint ep) { return(Murmur32.GetHash(ep.ToString())); }
/// <summary> /// Gets the murmur hash code for the type. /// </summary> /// <param name="source"></param> /// <returns></returns> public static int ToIdentifier(this Type source) { return(Murmur32.GetHash(source.FullName)); }