Exemple #1
0
        public unsafe void TestPieces()
        {
            byte[] bufArr = new byte[BufferSize];
            for (int i = 0; i < BufferSize; ++i)
            {
                bufArr[i] = unchecked ((byte)i);
            }
            for (int i = 0; i < BufferSize; ++i)
            {
                ulong      a, b, c, d, seed1 = 1, seed2 = 2;
                SpookyHash state = new SpookyHash();

                // all as one call
                a = seed1;
                b = seed2;
                fixed(byte *buf = bufArr)
                {
                    SpookyHash.Hash128(buf, i, ref a, ref b);
                }

                // all as one piece
                c = 0xdeadbeefdeadbeef;
                d = 0xbaceba11baceba11;
                state.Init(seed1, seed2);
                fixed(byte *buf = bufArr)
                {
                    state.Update(buf, i);
                }

                state.Final(out c, out d);

                Assert.Equal(a, c);
                Assert.Equal(b, d);

                for (int j = 0; j < i; ++j)
                {
                    c = seed1;
                    d = seed2;
                    state.Init(c, d);
                    fixed(byte *buf = bufArr)
                    {
                        state.Update(buf, j);
                        state.Update(buf + j, i - j);
                    }

                    state.Final(out c, out d);
                    Assert.Equal(a, c);
                    Assert.Equal(b, d);
                }
            }
        }
Exemple #2
0
        public void ConstructorsEquivalent()
        {
            ulong      ui1       = 0xdeadcafe;
            ulong      ui2       = 0xbaceba11;
            SpookyHash fromU     = new SpookyHash(ui1, ui2);
            SpookyHash fromZeroU = new SpookyHash();

            fromZeroU.Init(ui1, ui2);
            long       l1        = unchecked ((long)ui1);
            long       l2        = unchecked ((long)ui2);
            SpookyHash fromL     = new SpookyHash(l1, l2);
            SpookyHash fromZeroL = new SpookyHash();

            fromZeroL.Init(l1, l2);
            fromU.Update(MediumLengthString);
            fromZeroU.Update(MediumLengthString);
            fromL.Update(MediumLengthString);
            fromZeroL.Update(MediumLengthString);
            HashCode128 hash = fromU.Final();

            Assert.Equal(hash, fromZeroU.Final());
            Assert.Equal(hash, fromL.Final());
            Assert.Equal(hash, fromZeroL.Final());
            Assert.Equal(hash.ToString(), fromZeroL.Final().ToString());
        }