private int[] GetHashBuckets(byte[] b, int hashCount, int max)
        {
            var result = new int[hashCount];
            var hash1  = MurmurHash.Hash(b, 0, b.Length, 0);
            var hash2  = MurmurHash.Hash(b, 0, b.Length, hash1);

            for (var i = 0; i < hashCount; i++)
            {
                var tempMod = (int)(hash1 + i * hash2) % max;
                result[i] = Math.Abs(tempMod);
            }
            return(result);
        }
Beispiel #2
0
        public void TestPerformanceMurmurHash()
        {
            var warmupLoopCount  = 1; // 1000000;
            var measureLoopCount = 1; // 1000000000;

            // init
            string[] texts =
            {
                "joe",            "melissa",        "townhall",
                "ballpark",       "trial-by-error",
                "house",          "teamwork",
                "recommendation", "partial",
                "soccer ball"
            };
            var bytes = new byte[texts.Length][];

            for (var i = 0; i < texts.Length; i++)
            {
                bytes[i] = texts[i].GetUTF8Bytes();
            }

            // warmup
            for (var i = 0; i < warmupLoopCount; i++)
            {
                var bytearr = bytes[i % bytes.Length];
                var code    = MurmurHash.Hash(bytearr, 0, bytearr.Length, 0);
                if (code == 0)
                {
                    Console.Out.WriteLine("A zero code");
                }
            }

            // run
            // 23.3 for 1G for MurmurHash.hash
            long start = PerformanceObserver.NanoTime;

            for (var i = 0; i < measureLoopCount; i++)
            {
                var bytearr = bytes[i % bytes.Length];
                var codeOne = MurmurHash.Hash(bytearr, 0, bytearr.Length, 0);
                if (codeOne == 0)
                {
                    Console.Out.WriteLine("A zero code");
                }
            }

            var delta = PerformanceObserver.NanoTime - start;
            // Comment me in - System.out.println("Delta " + (delta / 1000000000.0));
        }
Beispiel #3
0
        public int GetHashCode(T[] a1)
        {
            if (typeof(T) == typeof(byte))
            {
                return((int)MurmurHash.Hash(a1 as byte[]));
            }
            int num = 0;

            for (int i = 0; i < a1.Length; i++)
            {
                int num2 = 8 * (i % 4);
                int num3 = a1[i].GetHashCode() << num2;
                num ^= num3;
            }
            return(num);
        }
Beispiel #4
0
        public void TestPerformanceMurmurHash()
        {
            const int warmupLoopCount  = 1; // 1000000;
            const int measureLoopCount = 1; // 1000000000;

            // init
            var texts = new string[] { "joe", "melissa", "townhall", "ballpark", "trial-by-error", "house", "teamwork", "recommendation", "partial", "soccer ball" };
            var bytes = new byte[texts.Length][];

            for (var i = 0; i < texts.Length; i++)
            {
                bytes[i] = Encoding.Unicode.GetBytes(texts[i]);
            }

            // warmup
            for (var i = 0; i < warmupLoopCount; i++)
            {
                var bytearr = bytes[i % bytes.Length];
                var code    = MurmurHash.Hash(bytearr, 0, bytearr.Length, 0);
                if (code == 0)
                {
                    Console.WriteLine("A zero code");
                }
            }

            // run
            // 23.3 for 1G for MurmurHash.hash
            var delta = PerformanceObserver.TimeNano(() =>
            {
                for (var i = 0; i < measureLoopCount; i++)
                {
                    var bytearr = bytes[i % bytes.Length];
                    var codeOne = MurmurHash.Hash(bytearr, 0, bytearr.Length, 0);
                    if (codeOne == 0)
                    {
                        Console.WriteLine("A zero code");
                    }
                }
            });
            // Comment me in - Console.WriteLine("Delta " + (delta / 1000000000.0));
        }
 /// <summary>
 /// 转为MurmurHash
 /// </summary>
 /// <param name="str">字符串</param>
 /// <returns></returns>
 public static uint ToMurmurHash(this string str)
 {
     return(MurmurHash.Hash(Encoding.UTF8.GetBytes(str)));
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Blob"/> class.
 /// </summary>
 /// <param name="data">The data.</param>
 public Blob(byte[] data)
 {
     _data = data;
     _hash = MurmurHash.Hash(data, 0, data.Length, 0);
 }