public void TestHash32Span() { var data = new byte[] { 1 }; Span <byte> sp = data; var expected = Farmhash.Hash32(data, data.Length); Assert.Equal(Farmhash.Hash32(sp), expected); }
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); }
public unsafe void TestHash32(String str, uint expected) { var bytes = Encoding.ASCII.GetBytes(str); Assert.Equal(Farmhash.Hash32(bytes, bytes.Length), expected); fixed(byte *ptr = bytes) { Assert.Equal(Farmhash.Hash32(ptr, bytes.Length), expected); } var strBytes = Encoding.Unicode.GetBytes(str); Assert.Equal(Farmhash.Hash32(strBytes, strBytes.Length), Farmhash.Hash32(str)); #if NETCOREAPP2_1 Span <byte> sp = bytes; Assert.Equal(Farmhash.Hash32(sp), expected); #endif }
public ulong FarmHash() => Farmhash.Hash64(data, data.Length);
public void TestHash64(String str, ulong expected) { var bytes = Encoding.ASCII.GetBytes(str); Assert.Equal(Farmhash.Hash64(bytes, bytes.Length), expected); }
public uint FarmHash() => Farmhash.Hash32(data, data.Length);