public static ulong ComputeHash64(this Murmur128 murmur, byte[] data) { var hash128 = murmur.ComputeHash(data); var hash64 = BitConverter.ToUInt64(hash128, 0); // take first 64 bits of 128 bit hash return(hash64); }
/// <summary> /// 获取节点 /// </summary> /// <param name="k"></param> /// <returns></returns> public StoreNode GetPrimary(byte[] k) { Murmur128 murmur = MurmurHashFactory.MurmurHash.Create128((uint)Environment.TickCount); byte[] digest = murmur.ComputeHash(k); ulong key = MurmurHashFactory.Hash(digest); return(GetNodeForKey(key)); }
/// <summary> /// Get file hash from string /// </summary> /// <param name="value"></param> /// <returns>hash</returns> public long GetFileHash(string value) { if (!value.EndsWith("\0")) { value = value + "\0"; } return(BitConverter.ToInt64(Hasher.ComputeHash(Encoding.ASCII.GetBytes(value)), 0)); }
public ulong Hash(string key, uint seed) { Murmur128 murmur128 = MurmurHash.Create128(seed: seed, preference: AlgorithmPreference.X64); byte[] keyToBytes = Encoding.ASCII.GetBytes(key); byte[] seedResult = murmur128.ComputeHash(keyToBytes); return(BitConverter.ToUInt64(seedResult, 0)); }
public void AddValue(ulong keyHash, T value) { ulong hash = 1; if (value != null) { var bytes = _byteConverter.ToByteArray(value); byte[] result = _murmurHash.ComputeHash(bytes); hash = BitConverter.ToUInt64(result, 0); } AddHash(hash); }
public ulong GetHash(T value) { ulong hash = 1; if (value != null) { var bytes = _byteConverter.ToByteArray(value); byte[] result = _murmurHash.ComputeHash(bytes); hash = BitConverter.ToUInt64(result, 0); } return(hash); }
//将传入的字符串通过murmurhash函数生成32位长的字符串 private static string GetHashAsString(string stringToHash) { Murmur128 urlHash = MurmurHash.Create128(managed: false); byte[] urlbyte = System.Text.Encoding.UTF8.GetBytes(stringToHash); byte[] hash = urlHash.ComputeHash(urlbyte); //以下代码也可以用 BitConverter.ToString(hash)代替 var builder = new StringBuilder(16); for (int i = 0; i < hash.Length; i++) { builder.Append(hash[i].ToString("x2")); } return(builder.ToString()); }
private long GetRingPosition(long key) { using (Murmur128 hashAlgorithm = MurmurHash.Create128()) { byte[] hash = hashAlgorithm.ComputeHash(BitConverter.GetBytes(key)); long total = 0; for (int startIndex = 0; startIndex < hash.Length; startIndex += 8) { unchecked { total += BitConverter.ToInt64(hash, startIndex); } } return(total); } }
public ulong GetHashCode(byte[] bytes) { return(BitConverter.ToUInt64(murmurHash.ComputeHash(bytes), 0)); }
public static string GetMurmurHash(this string str) { var bytes = MurmurHash3.ComputeHash(Encoding.UTF8.GetBytes(str)); return(bytes.GetMurmurHash()); }