Exemplo n.º 1
0
        public void TestBuzHashSlide()
        {
            BuzHashFunction h = new BuzHashFunction();
            byte[] bytes = { 2, 2, 2, 5, 7, 9 };
            uint hash = h.Hash(bytes, 3, 3);

            uint newHash = h.Hash(bytes, 0, 3);

            for (int i = 1; i < bytes.Length - 2; i++)
            {
                newHash = h.UpdateHash(newHash, bytes[i + 2], bytes[i - 1], 3);
            }
            Assert.AreEqual(hash, newHash);
        }
Exemplo n.º 2
0
        public void TestBuzHashSlideQueue()
        {
            int windowSize = 4;
            Queue<byte> queue = new Queue<byte>(windowSize);
            BuzHashFunction h = new BuzHashFunction();
            byte[] bytes = { 2, 2, 2, 5, 7, 9,10 };
            uint hash = h.Hash(bytes, bytes.Length - windowSize, windowSize);

            uint newHash = h.Hash(bytes, 0, windowSize);
            for (int i = 0; i < windowSize; i++)
                queue.Enqueue(bytes[i]);

            for (int i = windowSize; i < bytes.Length; i++)
            {
                newHash = h.UpdateHash(newHash, bytes[i], queue.Dequeue(), windowSize);
                queue.Enqueue(bytes[i]);
            }
            Assert.AreEqual(hash, newHash);
        }
Exemplo n.º 3
0
        public void TestBuzHashSlideQueueBigWindow()
        {
            Queue<byte> queue = new Queue<byte>(32);
            BuzHashFunction h = new BuzHashFunction();
            byte[] bytes = Encoding.UTF8.GetBytes("aaabbb12334567rp6ejflskxnjclzjflaksjfdlaksjlaksjdasd");
            uint hash = h.Hash(bytes, bytes.Length-32, 32);

            uint newHash = h.Hash(bytes, 0, 32);
            for (int i = 0; i < 32; i++)
            {
                queue.Enqueue(bytes[i]);
            }

            for (int i = 32; i < bytes.Length ; i++)
            {
                newHash = h.UpdateHash(newHash, bytes[i], queue.Dequeue(), 32);
                queue.Enqueue(bytes[i]);
            }
            Assert.AreEqual(hash, newHash);
        }