예제 #1
0
        public void TestVectorsUnsafe()
        {
            for (int i = 0; i < MaxLength; ++i)
            {
                byte[] data = new byte[i];
                for (int j = 0; j < i; j++)
                {
                    data[j] = (byte)j;
                }

                ulong k0, k1;
                Utilities.ToULongs(_key, out k0, out k1);

                unsafe
                {
                    fixed(byte *ptr = data)
                    {
                        ulong result   = SipHash64Unsafe.ComputeHash(ptr, data.Length, k0, k1);
                        ulong expected = BitConverter.ToUInt64(_vectors[i], 0);

                        Assert.Equal(expected, result);
                    }
                }
            }
        }
예제 #2
0
        public void CheckReferenceResultsUnsafe()
        {
            unsafe
            {
                fixed(byte *ptr = _testData)
                {
                    //DJBHash32
                    uint r1 = DJBHash32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(DJBHash32)], 0), r1);

                    //Farmhash32
                    uint r2 = FarmHash32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(FarmHash32)], 0), r2);

                    //Farmhash64
                    ulong r3 = FarmHash64Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt64(_testResults[typeof(FarmHash64)], 0), r3);

                    //FNV1A32
                    uint r4 = FNV1A32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(FNV1A32)], 0), r4);

                    //MurmurHash32
                    uint r5 = MurmurHash32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(MurmurHash32)], 0), r5);

                    //MurmurHash128
                    byte[] r6 = MurmurHash128Unsafe.ComputeHash(ptr, _testData.Length);
                    Assert.True(_testResults[typeof(MurmurHash128)].SequenceEqual(r6));

                    //SipHash64
                    ulong r7 = SipHash64Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt64(_testResults[typeof(SipHash64)], 0), r7);

                    //SuperFastHash32
                    uint r8 = SuperFastHash32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(SuperFastHash32)], 0), r8);

                    //xxHash32
                    uint r9 = xxHash32Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt32(_testResults[typeof(xxHash32)], 0), r9);

                    //xxHash64
                    ulong r10 = xxHash64Unsafe.ComputeHash(ptr, _testData.Length);

                    Assert.Equal(BitConverter.ToUInt64(_testResults[typeof(xxHash64)], 0), r10);
                }
            }
        }
예제 #3
0
 public unsafe ulong SipHash64UnsafeTest()
 {
     return(SipHash64Unsafe.ComputeHash(_unsafePtr, _testData.Length));
 }