예제 #1
0
        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);
        }
예제 #2
0
        /// <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));
        }
예제 #3
0
        /// <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));
        }
예제 #4
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));
        }
예제 #5
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);
        }
예제 #6
0
파일: Hasher.cs 프로젝트: bmdub/AutoStat
        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);
        }
예제 #7
0
파일: MainForm.cs 프로젝트: xiaoluoji/arcdb
        //将传入的字符串通过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));
 }
예제 #10
0
        public static string GetMurmurHash(this string str)
        {
            var bytes = MurmurHash3.ComputeHash(Encoding.UTF8.GetBytes(str));

            return(bytes.GetMurmurHash());
        }