Skip to content

Commit 8e8ea1b

Browse files
xoofxstephentoub
andauthored
Add XxHash128 (#77944)
* Add XxHash128 * Optimize XxHash128 * Missing optimization * Fix warnings * Optimize the 129 To 240 bytes case * Fix warnings * Add missing namespace for tests * Split strings in XxHash128 test * Try to fix tests on CI * Add XxHash128 to ref * Fix compilation errors on non .NET 7 platforms * Fix compilation errors on net472 * Update src/libraries/System.IO.Hashing/tests/XxHash64Tests.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/tests/XxHash3Tests.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/tests/XxHash128Tests.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHashShared.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash3.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Fix usage of var * Fix comment XXH3 -> XXH128 * Rename WriteCanonical128 to WriteBigEndian128 * Fix remaining issues - Assert constants - Move prime constants to shared * Add tests for XxHash128.HashToUInt128 and GetCurrentHashAsUInt128 * Remove spaces * Add new methods to ref * Try to fix ref file * Fix ref for .NET 7 * Split ref files * Fix ref after merge * Update src/libraries/System.IO.Hashing/ref/System.IO.Hashing.netcoreapp.cs Co-authored-by: Stephen Toub <[email protected]> * Update src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHash128.cs Co-authored-by: Stephen Toub <[email protected]> * Remove System.Linq Linq * Use PascalCast for local const * Remove XorShift64 from XxHash128 * Remove duplicated Multiply32To64 * Improve HashLength129To240 * Reverting System.Linq for XxHash3 and XxHash128 Co-authored-by: Stephen Toub <[email protected]>
1 parent 9d7ffb5 commit 8e8ea1b

11 files changed

+3044
-737
lines changed

src/libraries/System.IO.Hashing/ref/System.IO.Hashing.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ protected virtual void GetHashAndResetCore(System.Span<byte> destination) { }
5959
public bool TryGetCurrentHash(System.Span<byte> destination, out int bytesWritten) { throw null; }
6060
public bool TryGetHashAndReset(System.Span<byte> destination, out int bytesWritten) { throw null; }
6161
}
62+
public sealed partial class XxHash128 : System.IO.Hashing.NonCryptographicHashAlgorithm
63+
{
64+
public XxHash128() : base (default(int)) { }
65+
public XxHash128(long seed) : base (default(int)) { }
66+
public override void Append(System.ReadOnlySpan<byte> source) { }
67+
protected override void GetCurrentHashCore(System.Span<byte> destination) { }
68+
public static byte[] Hash(byte[] source) { throw null; }
69+
public static byte[] Hash(byte[] source, long seed) { throw null; }
70+
public static byte[] Hash(System.ReadOnlySpan<byte> source, long seed = (long)0) { throw null; }
71+
public static int Hash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, long seed = (long)0) { throw null; }
72+
public override void Reset() { }
73+
public static bool TryHash(System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten, long seed = (long)0) { throw null; }
74+
}
6275
public sealed partial class XxHash3 : System.IO.Hashing.NonCryptographicHashAlgorithm
6376
{
6477
public XxHash3() : base (default(int)) { }

src/libraries/System.IO.Hashing/ref/System.IO.Hashing.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<Compile Include="System.IO.Hashing.cs" />
99
</ItemGroup>
1010

11+
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
12+
<Compile Include="System.IO.Hashing.netcoreapp.cs" />
13+
</ItemGroup>
14+
1115
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
1216
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
1317
</ItemGroup>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// ------------------------------------------------------------------------------
4+
// Changes to this file must follow the https://aka.ms/api-review process.
5+
// ------------------------------------------------------------------------------
6+
7+
namespace System.IO.Hashing
8+
{
9+
public sealed partial class XxHash128 : System.IO.Hashing.NonCryptographicHashAlgorithm
10+
{
11+
[System.CLSCompliantAttribute(false)]
12+
public System.UInt128 GetCurrentHashAsUInt128() { throw null; }
13+
[System.CLSCompliantAttribute(false)]
14+
public static System.UInt128 HashToUInt128(System.ReadOnlySpan<byte> source, long seed = 0) { throw null; }
15+
}
16+
}

src/libraries/System.IO.Hashing/src/System.IO.Hashing.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ System.IO.Hashing.XxHash32</PackageDescription>
1515
<Compile Include="System\IO\Hashing\Crc32.Table.cs" />
1616
<Compile Include="System\IO\Hashing\Crc64.cs" />
1717
<Compile Include="System\IO\Hashing\Crc64.Table.cs" />
18+
<Compile Include="System\IO\Hashing\XxHash128.cs" />
1819
<Compile Include="System\IO\Hashing\XxHash3.cs" />
1920
<Compile Include="System\IO\Hashing\XxHash32.cs" />
2021
<Compile Include="System\IO\Hashing\XxHash32.State.cs" />
2122
<Compile Include="System\IO\Hashing\XxHash64.cs" />
2223
<Compile Include="System\IO\Hashing\XxHash64.State.cs" />
24+
<Compile Include="System\IO\Hashing\XxHashShared.cs" />
2325
<Compile Include="System\IO\Hashing\NonCryptographicHashAlgorithm.cs" />
2426
<Compile Include="$(CommonPath)System\Numerics\Crc32ReflectedTable.cs">
2527
<Link>Common\System\Numerics\Crc32ReflectedTable.cs</Link>

0 commit comments

Comments
 (0)