示例#1
0
        public void TestHash64Span()
        {
            var         data     = new byte[] { 1 };
            Span <byte> sp       = data;
            var         expected = Farmhash.Hash64(data, data.Length);

            Assert.Equal(Farmhash.Hash64(sp), expected);
        }
示例#2
0
        public void TestStringEncodingChangesOutput()
        {
            const string payload     = "Hellø";
            var          windows1252 = CodePagesEncodingProvider.Instance.GetEncoding(1252);
            var          winBytes    = windows1252.GetBytes(payload);
            var          utf8Bytes   = Encoding.UTF8.GetBytes(payload);
            var          utf16Bytes  = Encoding.Unicode.GetBytes(payload);

            Assert.NotEqual(winBytes, utf8Bytes);
            Assert.NotEqual(utf8Bytes, utf16Bytes);
            Assert.NotEqual(winBytes, utf16Bytes);

            var hashStr   = Farmhash.Hash64(payload);
            var hashUtf16 = Farmhash.Hash64(utf16Bytes, utf16Bytes.Length);

            Assert.Equal(hashStr, hashUtf16);
        }
示例#3
0
        public unsafe void TestHash64(String str, ulong expected)
        {
            var bytes = Encoding.ASCII.GetBytes(str);

            Assert.Equal(Farmhash.Hash64(bytes, bytes.Length), expected);
            fixed(byte *ptr = bytes)
            {
                Assert.Equal(Farmhash.Hash64(ptr, bytes.Length), expected);
            }

            var strBytes = Encoding.Unicode.GetBytes(str);

            Assert.Equal(Farmhash.Hash64(strBytes, strBytes.Length), Farmhash.Hash64(str));

#if NETCOREAPP2_1
            Span <byte> sp = bytes;
            Assert.Equal(Farmhash.Hash64(sp), expected);
#endif
        }
 public ulong FarmHash() => Farmhash.Hash64(data, data.Length);
示例#5
0
        public void TestHash64(String str, ulong expected)
        {
            var bytes = Encoding.ASCII.GetBytes(str);

            Assert.Equal(Farmhash.Hash64(bytes, bytes.Length), expected);
        }