Skip to content

Commit

Permalink
Add XxHash3 to System.IO.Hashing (#76641)
Browse files Browse the repository at this point in the history
* Add XxHash3

* Add more XxHash3 test cases

* Cull back volume of test cases, and line wrap to help editor performance

* Address PR feedback

Co-authored-by: Eugene Sirkiza <esirkiza@microsoft.com>
  • Loading branch information
stephentoub and Eugene Sirkiza committed Oct 27, 2022
1 parent fc0af10 commit 1adda68
Show file tree
Hide file tree
Showing 12 changed files with 2,089 additions and 47 deletions.
48 changes: 28 additions & 20 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -602,30 +602,38 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License notice for xxHash
-------------------------

xxHash Library
Copyright (c) 2012-2014, Yann Collet
All rights reserved.
xxHash - Extremely Fast Hash algorithm
Header File
Copyright (C) 2012-2021 Yann Collet

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You can contact the author at:
- xxHash homepage: https://www.xxhash.com
- xxHash source repository: https://github.com/Cyan4973/xxHash

License notice for Berkeley SoftFloat Release 3e
------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ System.IO.Hashing.XxHash32</PackageDescription>
<Compile Include="System\IO\Hashing\Crc32.Table.cs" />
<Compile Include="System\IO\Hashing\Crc64.cs" />
<Compile Include="System\IO\Hashing\Crc64.Table.cs" />
<Compile Include="System\IO\Hashing\XxHash3.cs" />
<Compile Include="System\IO\Hashing\XxHash32.cs" />
<Compile Include="System\IO\Hashing\XxHash32.State.cs" />
<Compile Include="System\IO\Hashing\XxHash64.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public static bool TryHash(ReadOnlySpan<byte> source, Span<byte> destination, ou
public static int Hash(ReadOnlySpan<byte> source, Span<byte> destination)
{
if (destination.Length < Size)
throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
{
ThrowDestinationTooShort();
}

return StaticHash(source, destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public static bool TryHash(ReadOnlySpan<byte> source, Span<byte> destination, ou
public static int Hash(ReadOnlySpan<byte> source, Span<byte> destination)
{
if (destination.Length < Size)
throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
{
ThrowDestinationTooShort();
}

return StaticHash(source, destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Buffers;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -226,7 +227,7 @@ public int GetCurrentHash(Span<byte> destination)
{
if (destination.Length < HashLengthInBytes)
{
throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
ThrowDestinationTooShort();
}

GetCurrentHashCore(destination.Slice(0, HashLengthInBytes));
Expand Down Expand Up @@ -288,7 +289,7 @@ public int GetHashAndReset(Span<byte> destination)
{
if (destination.Length < HashLengthInBytes)
{
throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination));
ThrowDestinationTooShort();
}

GetHashAndResetCore(destination.Slice(0, HashLengthInBytes));
Expand Down Expand Up @@ -341,5 +342,9 @@ public override int GetHashCode()
{
throw new NotSupportedException(SR.NotSupported_GetHashCode);
}

[DoesNotReturn]
private protected static void ThrowDestinationTooShort() =>
throw new ArgumentException(SR.Argument_DestinationTooShort, "destination");
}
}

0 comments on commit 1adda68

Please sign in to comment.