diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 5ef1650..0000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: .NET - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v2 - with: - dotnet-version: 6.0.x - - name: Restore dependencies - run: dotnet restore ./src - - name: Build - run: dotnet build ./src --no-restore - - name: Test - run: dotnet test ./src --no-build --verbosity normal diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ffb36ca..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Release to NuGet - -on: - workflow_dispatch: - inputs: - version: - description: Bump Version - default: v1.0.0 - required: true - release: - types: [published] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v2 - with: - dotnet-version: 6.0.x - - name: Build - run: dotnet build ./src -c Release - - name: Test - run: dotnet test ./src -c Release --no-build - - name: Pack nugets - run: dotnet pack ./src/Standart.Hash.xxHash -c Release --no-build --output . - - name: Push to NuGet - run: dotnet nuget push "*.nupkg" --api-key ${{secrets.nuget_api_key}} --source https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 940794e..8f79b0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,288 +1,24 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ -**/Properties/launchSettings.json - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Typescript v1 declaration files -typings/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs +# Build results +[Bb]in/ +.bin/ +[Dd]ebug/ +[Rr]elease/ +[Rr]eleases/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ +nuget/ +*[-_]tmp/ + +# IDE files +.vs/ +.vscode/ +.vshistory/ +.idea/ +.editorconfig +*.user + +#backups +.old*/ +*[-_]old/ diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 753bc55..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# 2022-07-17 -- Improve perfomance for XXH32 & XXH64 -- Improve perfomance for XXH128 & XXH3 -# 2022-06-13 -- Added xxHash3 -# 2022-06-05 -- Added SIMD support for xxHash128 -- Inlined all method calls for xxHash128 -# 2022-06-03 -- Added xxHash128 -- Migrated to net6 -# 2019-02-16 -- Migrated to net core v.3.1 -- Added bit operation utils -# 2019-12-15 -- Added support for ArraySegment (thanks ksmith3036) -# 2018-03-11 -- Added API for ReadOnlySpan -- Added support for the async calls with cancelation tokens \ No newline at end of file diff --git a/DTLib.XXHash.PerformanceTest/DTLib.XXHash.PerformanceTest.csproj b/DTLib.XXHash.PerformanceTest/DTLib.XXHash.PerformanceTest.csproj new file mode 100644 index 0000000..e84ced4 --- /dev/null +++ b/DTLib.XXHash.PerformanceTest/DTLib.XXHash.PerformanceTest.csproj @@ -0,0 +1,18 @@ + + + Exe + net48;net6.0;net8.0 + 12 + 0.13.1 + 17.2.0 + 2.4.1 + 2.4.5 + 2.3.1 + + + + + + + + \ No newline at end of file diff --git a/src/Standart.Hash.xxHash.Perf/Program.cs b/DTLib.XXHash.PerformanceTest/Program.cs similarity index 82% rename from src/Standart.Hash.xxHash.Perf/Program.cs rename to DTLib.XXHash.PerformanceTest/Program.cs index d1dadc4..55f90fe 100644 --- a/src/Standart.Hash.xxHash.Perf/Program.cs +++ b/DTLib.XXHash.PerformanceTest/Program.cs @@ -1,4 +1,4 @@ -namespace Standart.Hash.xxHash.Perf +namespace DTLib.XXHash.PerformanceTest { using BenchmarkDotNet.Running; diff --git a/src/Standart.Hash.xxHash.Perf/UtilsBenchmark.cs b/DTLib.XXHash.PerformanceTest/UtilsBenchmark.cs similarity index 90% rename from src/Standart.Hash.xxHash.Perf/UtilsBenchmark.cs rename to DTLib.XXHash.PerformanceTest/UtilsBenchmark.cs index 4ccf391..b1c4b2b 100644 --- a/src/Standart.Hash.xxHash.Perf/UtilsBenchmark.cs +++ b/DTLib.XXHash.PerformanceTest/UtilsBenchmark.cs @@ -1,4 +1,4 @@ -namespace Standart.Hash.xxHash.Perf +namespace DTLib.XXHash.PerformanceTest { using System; using BenchmarkDotNet.Attributes; diff --git a/src/Standart.Hash.xxHash.Perf/xxHashBenchmark.cs b/DTLib.XXHash.PerformanceTest/xxHashBenchmark.cs similarity index 94% rename from src/Standart.Hash.xxHash.Perf/xxHashBenchmark.cs rename to DTLib.XXHash.PerformanceTest/xxHashBenchmark.cs index a94da32..befa369 100644 --- a/src/Standart.Hash.xxHash.Perf/xxHashBenchmark.cs +++ b/DTLib.XXHash.PerformanceTest/xxHashBenchmark.cs @@ -1,4 +1,4 @@ -namespace Standart.Hash.xxHash.Perf +namespace DTLib.XXHash.PerformanceTest { using System; using System.IO; diff --git a/src/Standart.Hash.xxHash.Test/Standart.Hash.xxHash.Test.csproj b/DTLib.XXHash.Tests/DTLib.XXHash.Tests.csproj similarity index 50% rename from src/Standart.Hash.xxHash.Test/Standart.Hash.xxHash.Test.csproj rename to DTLib.XXHash.Tests/DTLib.XXHash.Tests.csproj index 928cfbc..bf4902f 100644 --- a/src/Standart.Hash.xxHash.Test/Standart.Hash.xxHash.Test.csproj +++ b/DTLib.XXHash.Tests/DTLib.XXHash.Tests.csproj @@ -1,24 +1,24 @@  - false full + net48;net6.0;net8.0 + 12 + 0.13.1 + 17.2.0 + 2.4.1 + 2.4.5 + 2.3.1 - - true - x64 - - - false - AnyCPU - + + - + \ No newline at end of file diff --git a/src/Standart.Hash.xxHash.Test/UtilsTest.cs b/DTLib.XXHash.Tests/UtilsTest.cs similarity index 94% rename from src/Standart.Hash.xxHash.Test/UtilsTest.cs rename to DTLib.XXHash.Tests/UtilsTest.cs index 7515fcf..d2de679 100644 --- a/src/Standart.Hash.xxHash.Test/UtilsTest.cs +++ b/DTLib.XXHash.Tests/UtilsTest.cs @@ -1,4 +1,4 @@ -namespace Standart.Hash.xxHash.Test +namespace DTLib.XXHash.Tests { using System; using Xunit; diff --git a/src/Standart.Hash.xxHash.Test/xxHash128Test.cs b/DTLib.XXHash.Tests/xxHash128Test.cs similarity index 98% rename from src/Standart.Hash.xxHash.Test/xxHash128Test.cs rename to DTLib.XXHash.Tests/xxHash128Test.cs index 015b2c4..14701e7 100644 --- a/src/Standart.Hash.xxHash.Test/xxHash128Test.cs +++ b/DTLib.XXHash.Tests/xxHash128Test.cs @@ -2,7 +2,7 @@ using System; using System.Text; using Xunit; -namespace Standart.Hash.xxHash.Test +namespace DTLib.XXHash.Tests { public class xxHash128Test { diff --git a/src/Standart.Hash.xxHash.Test/xxHash32Test.cs b/DTLib.XXHash.Tests/xxHash32Test.cs similarity index 96% rename from src/Standart.Hash.xxHash.Test/xxHash32Test.cs rename to DTLib.XXHash.Tests/xxHash32Test.cs index 9009649..d3a6ce4 100644 --- a/src/Standart.Hash.xxHash.Test/xxHash32Test.cs +++ b/DTLib.XXHash.Tests/xxHash32Test.cs @@ -1,6 +1,6 @@ using System.Text; -namespace Standart.Hash.xxHash.Test +namespace DTLib.XXHash.Tests { using System; using System.IO; diff --git a/src/Standart.Hash.xxHash.Test/xxHash3Test.cs b/DTLib.XXHash.Tests/xxHash3Test.cs similarity index 98% rename from src/Standart.Hash.xxHash.Test/xxHash3Test.cs rename to DTLib.XXHash.Tests/xxHash3Test.cs index 3d44c97..451408a 100644 --- a/src/Standart.Hash.xxHash.Test/xxHash3Test.cs +++ b/DTLib.XXHash.Tests/xxHash3Test.cs @@ -2,7 +2,7 @@ using System.Text; using Xunit; -namespace Standart.Hash.xxHash.Test +namespace DTLib.XXHash.Tests { public class xxHash3Test { diff --git a/src/Standart.Hash.xxHash.Test/xxHash64Test.cs b/DTLib.XXHash.Tests/xxHash64Test.cs similarity index 96% rename from src/Standart.Hash.xxHash.Test/xxHash64Test.cs rename to DTLib.XXHash.Tests/xxHash64Test.cs index eed097b..9a4304e 100644 --- a/src/Standart.Hash.xxHash.Test/xxHash64Test.cs +++ b/DTLib.XXHash.Tests/xxHash64Test.cs @@ -1,6 +1,6 @@ using System.Text; -namespace Standart.Hash.xxHash.Test +namespace DTLib.XXHash.Tests { using System; using System.IO; diff --git a/DTLib.XXHash.sln b/DTLib.XXHash.sln new file mode 100644 index 0000000..0ddcd44 --- /dev/null +++ b/DTLib.XXHash.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib.XXHash", "DTLib.XXHash\DTLib.XXHash.csproj", "{7462108E-0FAE-49B1-9DDE-2996E09DFFD2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib.XXHash.PerformanceTest", "DTLib.XXHash.PerformanceTest\DTLib.XXHash.PerformanceTest.csproj", "{E5EFBB2E-ABC7-4FE8-AA2E-B62B4D6B9B5D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTLib.XXHash.Tests", "DTLib.XXHash.Tests\DTLib.XXHash.Tests.csproj", "{F3CC0F6B-D5BC-40FD-94EC-AF1A9534177F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7462108E-0FAE-49B1-9DDE-2996E09DFFD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7462108E-0FAE-49B1-9DDE-2996E09DFFD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7462108E-0FAE-49B1-9DDE-2996E09DFFD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7462108E-0FAE-49B1-9DDE-2996E09DFFD2}.Release|Any CPU.Build.0 = Release|Any CPU + {E5EFBB2E-ABC7-4FE8-AA2E-B62B4D6B9B5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5EFBB2E-ABC7-4FE8-AA2E-B62B4D6B9B5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5EFBB2E-ABC7-4FE8-AA2E-B62B4D6B9B5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5EFBB2E-ABC7-4FE8-AA2E-B62B4D6B9B5D}.Release|Any CPU.Build.0 = Release|Any CPU + {F3CC0F6B-D5BC-40FD-94EC-AF1A9534177F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3CC0F6B-D5BC-40FD-94EC-AF1A9534177F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3CC0F6B-D5BC-40FD-94EC-AF1A9534177F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3CC0F6B-D5BC-40FD-94EC-AF1A9534177F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/DTLib.XXHash/DTLib.XXHash.csproj b/DTLib.XXHash/DTLib.XXHash.csproj new file mode 100644 index 0000000..c33a92f --- /dev/null +++ b/DTLib.XXHash/DTLib.XXHash.csproj @@ -0,0 +1,26 @@ + + + DTLib.XXHash + 1.0.0 + Oleksandr Melnyk, Timerix22 + hash;xxHash;DTLib + XXHash implementation in C# using intrinsics + https://github.com/Timerix22/DTLib.XXHash + MIT + + netstandard2.0;net6.0;net7.0;net8.0 + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/Utils.cs b/DTLib.XXHash/Utils.cs similarity index 99% rename from src/Standart.Hash.xxHash/Utils.cs rename to DTLib.XXHash/Utils.cs index 7168007..0d67a36 100644 --- a/src/Standart.Hash.xxHash/Utils.cs +++ b/DTLib.XXHash/Utils.cs @@ -1,11 +1,14 @@ +#if NET6_0_OR_GREATER using System; +#endif using System.Diagnostics; using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static class Utils { +#if NET6_0_OR_GREATER public static Guid ToGuid(this uint128 value) { var a = (Int32) (value.low64); @@ -32,6 +35,7 @@ namespace Standart.Hash.xxHash Unsafe.As(ref bytes[8]) = value.high64; return bytes; } +#endif [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static unsafe void BlockCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) diff --git a/src/Standart.Hash.xxHash/__inline__xxHash32.cs b/DTLib.XXHash/__inline__xxHash32.cs similarity index 99% rename from src/Standart.Hash.xxHash/__inline__xxHash32.cs rename to DTLib.XXHash/__inline__xxHash32.cs index 078f8c0..de55198 100644 --- a/src/Standart.Hash.xxHash/__inline__xxHash32.cs +++ b/DTLib.XXHash/__inline__xxHash32.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public partial class xxHash32 { diff --git a/src/Standart.Hash.xxHash/__inline__xxHash64.cs b/DTLib.XXHash/__inline__xxHash64.cs similarity index 99% rename from src/Standart.Hash.xxHash/__inline__xxHash64.cs rename to DTLib.XXHash/__inline__xxHash64.cs index 451dbf4..4c4f73b 100644 --- a/src/Standart.Hash.xxHash/__inline__xxHash64.cs +++ b/DTLib.XXHash/__inline__xxHash64.cs @@ -6,7 +6,7 @@ using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public partial class xxHash64 { diff --git a/src/Standart.Hash.xxHash/xxHash128.XXH.cs b/DTLib.XXHash/xxHash128.XXH.cs similarity index 98% rename from src/Standart.Hash.xxHash/xxHash128.XXH.cs rename to DTLib.XXHash/xxHash128.XXH.cs index c1bb5a7..abe8665 100644 --- a/src/Standart.Hash.xxHash/xxHash128.XXH.cs +++ b/DTLib.XXHash/xxHash128.XXH.cs @@ -1,10 +1,9 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash128 { @@ -138,4 +137,5 @@ namespace Standart.Hash.xxHash *(ulong*) dst = v64; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash128.XXH3.cs b/DTLib.XXHash/xxHash128.XXH3.cs similarity index 99% rename from src/Standart.Hash.xxHash/xxHash128.XXH3.cs rename to DTLib.XXHash/xxHash128.XXH3.cs index ff559a9..493cbef 100644 --- a/src/Standart.Hash.xxHash/xxHash128.XXH3.cs +++ b/DTLib.XXHash/xxHash128.XXH3.cs @@ -1,11 +1,10 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash128 { @@ -714,4 +713,5 @@ namespace Standart.Hash.xxHash } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash128.XXH64.cs b/DTLib.XXHash/xxHash128.XXH64.cs similarity index 85% rename from src/Standart.Hash.xxHash/xxHash128.XXH64.cs rename to DTLib.XXHash/xxHash128.XXH64.cs index 31349bf..4954d23 100644 --- a/src/Standart.Hash.xxHash/xxHash128.XXH64.cs +++ b/DTLib.XXHash/xxHash128.XXH64.cs @@ -1,8 +1,7 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash128 { @@ -17,4 +16,5 @@ namespace Standart.Hash.xxHash return hash; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash128.cs b/DTLib.XXHash/xxHash128.cs similarity index 98% rename from src/Standart.Hash.xxHash/xxHash128.cs rename to DTLib.XXHash/xxHash128.cs index bf6c06d..9d46bac 100644 --- a/src/Standart.Hash.xxHash/xxHash128.cs +++ b/DTLib.XXHash/xxHash128.cs @@ -1,11 +1,10 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash128 { @@ -27,7 +26,7 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(ptr, length, seed); } } - + /// /// Compute xxHash for the data byte span /// @@ -65,7 +64,7 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(ptr, length, seed); } } - + /// /// Compute xxHash for the string /// @@ -103,7 +102,7 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(ptr, length, seed).ToBytes(); } } - + /// /// Compute hash bytes for the span /// @@ -141,7 +140,6 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(ptr, length, seed).ToBytes(); } } - /// /// Compute hash bytes for the string /// @@ -177,4 +175,5 @@ namespace Standart.Hash.xxHash public ulong low64; public ulong high64; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash3.XXH.cs b/DTLib.XXHash/xxHash3.XXH.cs similarity index 97% rename from src/Standart.Hash.xxHash/xxHash3.XXH.cs rename to DTLib.XXHash/xxHash3.XXH.cs index 71f210d..b2fff29 100644 --- a/src/Standart.Hash.xxHash/xxHash3.XXH.cs +++ b/DTLib.XXHash/xxHash3.XXH.cs @@ -1,10 +1,9 @@ -// ReSharper disable InconsistentNaming - -using System.Runtime.CompilerServices; +#if NET6_0_OR_GREATER using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; +using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash3 { @@ -92,11 +91,10 @@ namespace Standart.Hash.xxHash { *(ulong*) dst = v64; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint128 XXH_mult64to128(ulong lhs, ulong rhs) { - if (Bmi2.IsSupported) + if (Bmi2.X64.IsSupported) return XXH_mult64to128_bmi2(lhs, rhs); return XXH_mult64to128_scalar(lhs, rhs); @@ -131,4 +129,5 @@ namespace Standart.Hash.xxHash return r128; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash3.XXH3.cs b/DTLib.XXHash/xxHash3.XXH3.cs similarity index 99% rename from src/Standart.Hash.xxHash/xxHash3.XXH3.cs rename to DTLib.XXHash/xxHash3.XXH3.cs index 74a1ef6..b61ec26 100644 --- a/src/Standart.Hash.xxHash/xxHash3.XXH3.cs +++ b/DTLib.XXHash/xxHash3.XXH3.cs @@ -1,10 +1,9 @@ -// ReSharper disable InconsistentNaming - using System.Runtime.CompilerServices; +#if NET6_0_OR_GREATER using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash3 { @@ -75,14 +74,12 @@ namespace Standart.Hash.xxHash + XXH3_mul128_fold64(input_lo, input_hi); return XXH3_avalanche(acc); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong XXH3_mul128_fold64(ulong lhs, ulong rhs) { uint128 product = XXH_mult64to128(lhs, rhs); return product.low64 ^ product.high64; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static ulong XXH3_avalanche(ulong h64) { @@ -626,4 +623,5 @@ namespace Standart.Hash.xxHash xacc[lane] = acc64; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash3.XXH64.cs b/DTLib.XXHash/xxHash3.XXH64.cs similarity index 85% rename from src/Standart.Hash.xxHash/xxHash3.XXH64.cs rename to DTLib.XXHash/xxHash3.XXH64.cs index 4450c06..ac837bb 100644 --- a/src/Standart.Hash.xxHash/xxHash3.XXH64.cs +++ b/DTLib.XXHash/xxHash3.XXH64.cs @@ -1,8 +1,7 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash3 { @@ -17,4 +16,5 @@ namespace Standart.Hash.xxHash return hash; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash3.cs b/DTLib.XXHash/xxHash3.cs similarity index 97% rename from src/Standart.Hash.xxHash/xxHash3.cs rename to DTLib.XXHash/xxHash3.cs index 6f27344..4962112 100644 --- a/src/Standart.Hash.xxHash/xxHash3.cs +++ b/DTLib.XXHash/xxHash3.cs @@ -1,10 +1,9 @@ -// ReSharper disable InconsistentNaming - +#if NET6_0_OR_GREATER using System; using System.Diagnostics; using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash3 { @@ -93,4 +92,5 @@ namespace Standart.Hash.xxHash } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Standart.Hash.xxHash/xxHash32.XXH.cs b/DTLib.XXHash/xxHash32.XXH.cs similarity index 89% rename from src/Standart.Hash.xxHash/xxHash32.XXH.cs rename to DTLib.XXHash/xxHash32.XXH.cs index 631fd74..710d25c 100644 --- a/src/Standart.Hash.xxHash/xxHash32.XXH.cs +++ b/DTLib.XXHash/xxHash32.XXH.cs @@ -1,8 +1,8 @@ -// ReSharper disable InconsistentNaming + using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash32 { diff --git a/src/Standart.Hash.xxHash/xxHash32.XXH32.cs b/DTLib.XXHash/xxHash32.XXH32.cs similarity index 97% rename from src/Standart.Hash.xxHash/xxHash32.XXH32.cs rename to DTLib.XXHash/xxHash32.XXH32.cs index 1ca5c9c..9c7b7f5 100644 --- a/src/Standart.Hash.xxHash/xxHash32.XXH32.cs +++ b/DTLib.XXHash/xxHash32.XXH32.cs @@ -1,6 +1,6 @@ -// ReSharper disable InconsistentNaming + -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { using System.Runtime.CompilerServices; diff --git a/src/Standart.Hash.xxHash/xxHash32.cs b/DTLib.XXHash/xxHash32.cs similarity index 98% rename from src/Standart.Hash.xxHash/xxHash32.cs rename to DTLib.XXHash/xxHash32.cs index e0c4653..c04c30b 100644 --- a/src/Standart.Hash.xxHash/xxHash32.cs +++ b/DTLib.XXHash/xxHash32.cs @@ -1,15 +1,16 @@ -// ReSharper disable InconsistentNaming using System; using System.Buffers; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +#if NET6_0_OR_GREATER using System.Runtime.InteropServices; +#endif using System.Threading; using System.Threading.Tasks; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash32 { @@ -61,8 +62,6 @@ namespace Standart.Hash.xxHash /// hash public static ulong ComputeHash(ArraySegment data, uint seed = 0) { - Debug.Assert(data != null); - return ComputeHash(data.Array, data.Offset, data.Count, seed); } @@ -137,7 +136,7 @@ namespace Standart.Hash.xxHash ArrayPool.Shared.Return(buffer); } } - +#if NET6_0_OR_GREATER /// /// Compute xxHash for the data byte span /// @@ -175,7 +174,7 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(pData, length, seed); } } - +#endif /// /// Compute xxHash for the stream /// diff --git a/src/Standart.Hash.xxHash/xxHash64.XXH.cs b/DTLib.XXHash/xxHash64.XXH.cs similarity index 90% rename from src/Standart.Hash.xxHash/xxHash64.XXH.cs rename to DTLib.XXHash/xxHash64.XXH.cs index dafbed8..08abb01 100644 --- a/src/Standart.Hash.xxHash/xxHash64.XXH.cs +++ b/DTLib.XXHash/xxHash64.XXH.cs @@ -1,8 +1,8 @@ -// ReSharper disable InconsistentNaming + using System.Runtime.CompilerServices; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash64 { diff --git a/src/Standart.Hash.xxHash/xxHash64.XXH64.cs b/DTLib.XXHash/xxHash64.XXH64.cs similarity index 97% rename from src/Standart.Hash.xxHash/xxHash64.XXH64.cs rename to DTLib.XXHash/xxHash64.XXH64.cs index 5c04f8f..1405400 100644 --- a/src/Standart.Hash.xxHash/xxHash64.XXH64.cs +++ b/DTLib.XXHash/xxHash64.XXH64.cs @@ -1,6 +1,6 @@ -// ReSharper disable InconsistentNaming + -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { using System.Runtime.CompilerServices; diff --git a/src/Standart.Hash.xxHash/xxHash64.cs b/DTLib.XXHash/xxHash64.cs similarity index 97% rename from src/Standart.Hash.xxHash/xxHash64.cs rename to DTLib.XXHash/xxHash64.cs index 08c31dc..09dd474 100644 --- a/src/Standart.Hash.xxHash/xxHash64.cs +++ b/DTLib.XXHash/xxHash64.cs @@ -1,15 +1,15 @@ -// ReSharper disable InconsistentNaming - -using System; using System.Buffers; using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +#if NET6_0_OR_GREATER +using System; using System.Runtime.InteropServices; +#endif using System.Threading; using System.Threading.Tasks; -namespace Standart.Hash.xxHash +namespace DTLib.XXHash { public static partial class xxHash64 { @@ -58,10 +58,8 @@ namespace Standart.Hash.xxHash /// The source of data /// The seed number /// hash - public static unsafe ulong ComputeHash(System.ArraySegment data, ulong seed = 0) + public static ulong ComputeHash(System.ArraySegment data, ulong seed = 0) { - Debug.Assert(data != null); - return ComputeHash(data.Array, data.Offset, data.Count, seed); } @@ -137,7 +135,7 @@ namespace Standart.Hash.xxHash ArrayPool.Shared.Return(buffer); } } - +#if NET6_0_OR_GREATER /// /// Compute xxHash for the data byte span /// @@ -175,7 +173,7 @@ namespace Standart.Hash.xxHash return UnsafeComputeHash(pData, length, seed); } } - +#endif /// /// Compute xxHash for the stream /// diff --git a/README.md b/README.md deleted file mode 100644 index b55ddab..0000000 --- a/README.md +++ /dev/null @@ -1,131 +0,0 @@ -

- - xxHash.st - -

-

- Extremely fast non-cryptographic hash algorithm xxhash -

-
-

- - platform - - - license - -

- -xxHash is an Extremely fast Hash algorithm, running at RAM speed limits. It successfully completes the **SMHasher** test suite which evaluates collision, dispersion and randomness qualities of hash functions. - -## Instalation -``` -PM> Install-Package Standart.Hash.xxHash -``` - -## Benchmarks -This benchmark was launched on a **Windows 10.0.19044.1706 (21H2)**. The reference system uses a **AMD Ryzen 7 2700, 1 CPU, 16 logical and 8 physical cores** -``` -BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1706 (21H2) -AMD Ryzen 7 2700, 1 CPU, 16 logical and 8 physical cores -.NET SDK=6.0.300 - [Host] : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT - Job-HQVLOG : .NET 6.0.5 (6.0.522.21309), X64 RyuJIT -Runtime=.NET 6.0 -``` - -| Method | x64 | -|:---------------|-----------:| -| Hash32 Array | 6.65 GB/s | -| Hash64 Array | 12.28 GB/s | -| Hash128 Array | 12.04 GB/s | -| Hash3 Array | 12.08 GB/s | -| Hash32 Span | 6.65 GB/s | -| Hash64 Span | 12.28 GB/s | -| Hash128 Span | 12.04 GB/s | -| Hash3 Span | 12.08 GB/s | -| Hash32 Stream | 3.22 GB/s | -| Hash64 Stream | 4.81 GB/s | - -## Comparison between С# and C implementation - -| Method | Platform | Language | 1KB Time | 1MB Time | 1GB Time | Speed | -|:-------------------|---------:|---------:|----------:|----------:|----------:|-----------:| -| Hash32 | x64 | C# | 138.0 ns | 130.2 us | 150.3 ms | 6.65 GB/s | -| Hash32 | x64 | C | 140.2 ns | 129.6 us | 150.3 ms | 6.65 GB/s | -| Hash64 | x64 | C# | 73.9 ns | 64.6 us | 81.4 ms | 12.28 GB/s | -| Hash64 | x64 | C | 75.5 ns | 65.2 us | 84.5 ms | 11.83 GB/s | -| Hash128 (SSE2/AVX2)| x64 | C# | 84.95 ns | 56.9 us | 73.2 ms | 13.66 GB/s | -| Hash128 (SSE2/AVX2)| x64 | C | 84.35 ns | 38.1 us | 57.2 ms | 17.48 GB/s | -| Hash3 (SSE2/AVX2)| x64 | C# | 75.8 ns | 56.6 us | 74.6 ms | 13.40 GB/s | -| Hash3 (SSE2/AVX2)| x64 | C | 74.1 ns | 42.1 us | 59.5 ms | 16.80 GB/s | - - -## Api -```cs -public static uint ComputeHash(byte[] data, int length, uint seed = 0) { throw null; } -public static uint ComputeHash(Span data, int length, uint seed = 0) { throw null; } -public static uint ComputeHash(Stream stream, int bufferSize = 4096, uint seed = 0) { throw null; } -public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize = 4096, uint seed = 0) { throw null; } -public static uint ComputeHash(string str, uint seed = 0) { throw null; } - - -public static ulong ComputeHash(byte[] data, int length, ulong seed = 0) { throw null; } -public static ulong ComputeHash(Span data, int length, ulong seed = 0) { throw null; } -public static ulong ComputeHash(Stream stream, int bufferSize = 8192, ulong seed = 0) { throw null; } -public static async ValueTask ComputeHashAsync(Stream stream, int bufferSize = 8192, ulong seed = 0) { throw null; } -public static ulong ComputeHash(string str, uint seed = 0) { throw null; } - -public static uint128 ComputeHash(byte[] data, int length, uint seed = 0) { throw null; } -public static uint128 ComputeHash(Span data, int length, uint seed = 0) { throw null; } -public static uint128 ComputeHash(string str, uint seed = 0) { throw null; } - -// allocations -public static byte[] ComputeHashBytes(byte[] data, int length, uint seed = 0) { throw null; } -public static byte[] ComputeHashBytes(Span data, int length, uint seed = 0) { throw null; } -public static byte[] ComputeHashBytes(string str, uint seed = 0) { throw null; } - -``` - -## Examples -A few examples of how to use api -```cs -byte[] data = Encoding.UTF8.GetBytes("veni vidi vici"); - -ulong h64_1 = xxHash64.ComputeHash(data, data.Length); -ulong h64_2 = xxHash64.ComputeHash(new Span(data), data.Length); -ulong h64_3 = xxHash64.ComputeHash(new ReadOnlySpan(data), data.Length); -ulong h64_4 = xxHash64.ComputeHash(new MemoryStream(data)); -ulong h64_5 = await xxHash64.ComputeHashAsync(new MemoryStream(data)); -ulong h64_6 = xxHash64.ComputeHash("veni vidi vici"); - -uint h32_1 = xxHash32.ComputeHash(data, data.Length); -uint h32_2 = xxHash32.ComputeHash(new Span(data), data.Length); -uint h32_3 = xxHash32.ComputeHash(new ReadOnlySpan(data), data.Length); -uint h32_4 = xxHash32.ComputeHash(new MemoryStream(data)); -uint h32_5 = await xxHash32.ComputeHashAsync(new MemoryStream(data)); -uint h32_6 = xxHash32.ComputeHash("veni vidi vici"); - -ulong h3_1 = xxHash3.ComputeHash(data, data.Length); -ulong h3_2 = xxHash3.ComputeHash(new Span(data), data.Length); -ulong h3_3 = xxHash3.ComputeHash(new ReadOnlySpan(data), data.Length); -ulong h3_4 = xxHash3.ComputeHash("veni vidi vici"); - -uint128 h128_1 = xxHash128.ComputeHash(data, data.Length); -uint128 h128_2 = xxHash128.ComputeHash(new Span(data), data.Length); -uint128 h128_3 = xxHash128.ComputeHash(new ReadOnlySpan(data), data.Length); -uint128 h128_4 = xxHash128.ComputeHash("veni vidi vici"); - -Guid guid = h128_1.ToGuid(); -byte[] bytes = h128_1.ToBytes(); - -byte[] hash_bytes_1 = xxHash128.ComputeHashBytes(data, data.Length); -byte[] hash_bytes_2 = xxHash128.ComputeHashBytes(new Span(data), data.Length); -byte[] hash_bytes_3 = xxHash128.ComputeHashBytes(new ReadOnlySpan(data), data.Length); -byte[] hash_bytes_4 = xxHash128.ComputeHashBytes("veni vidi vici"); - -``` ---- -

-Made in :beginner: Ukraine with :heart: -

diff --git a/deps.props b/deps.props deleted file mode 100644 index c5ff158..0000000 --- a/deps.props +++ /dev/null @@ -1,11 +0,0 @@ - - - net5.0;net6.0 - 9.0 - 0.13.1 - 17.2.0 - 2.4.1 - 2.4.5 - 2.3.1 - - \ No newline at end of file diff --git a/nuget.props b/nuget.props deleted file mode 100644 index 2edde0c..0000000 --- a/nuget.props +++ /dev/null @@ -1,14 +0,0 @@ - - - - Standart.Hash.xxHash - 4.0.5 - Standart.Hash.xxHash - Standart.Hash.xxHash - Oleksandr Melnyk - hash;xxHash - Standart.Hash.xxHash - https://github.com/uranium62/xxHash - MIT - - \ No newline at end of file diff --git a/src/Standart.Hash.xxHash.Perf/Standart.Hash.xxHash.Perf.csproj b/src/Standart.Hash.xxHash.Perf/Standart.Hash.xxHash.Perf.csproj deleted file mode 100644 index e0e03f3..0000000 --- a/src/Standart.Hash.xxHash.Perf/Standart.Hash.xxHash.Perf.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - - - true - x64 - - - false - AnyCPU - - - - - - - - \ No newline at end of file diff --git a/src/Standart.Hash.xxHash.sln b/src/Standart.Hash.xxHash.sln deleted file mode 100644 index 7a6119a..0000000 --- a/src/Standart.Hash.xxHash.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Standart.Hash.xxHash", "Standart.Hash.xxHash\Standart.Hash.xxHash.csproj", "{E468CD00-D581-46DD-ADE6-71EFA74AD62E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Standart.Hash.xxHash.Perf", "Standart.Hash.xxHash.Perf\Standart.Hash.xxHash.Perf.csproj", "{7B80269B-1EC4-40B5-8E19-F0A68C4404E5}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Standart.Hash.xxHash.Test", "Standart.Hash.xxHash.Test\Standart.Hash.xxHash.Test.csproj", "{0D9506CC-A6A1-4C0C-8827-9AB958942895}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E468CD00-D581-46DD-ADE6-71EFA74AD62E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E468CD00-D581-46DD-ADE6-71EFA74AD62E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E468CD00-D581-46DD-ADE6-71EFA74AD62E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E468CD00-D581-46DD-ADE6-71EFA74AD62E}.Release|Any CPU.Build.0 = Release|Any CPU - {7B80269B-1EC4-40B5-8E19-F0A68C4404E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7B80269B-1EC4-40B5-8E19-F0A68C4404E5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7B80269B-1EC4-40B5-8E19-F0A68C4404E5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7B80269B-1EC4-40B5-8E19-F0A68C4404E5}.Release|Any CPU.Build.0 = Release|Any CPU - {0D9506CC-A6A1-4C0C-8827-9AB958942895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D9506CC-A6A1-4C0C-8827-9AB958942895}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D9506CC-A6A1-4C0C-8827-9AB958942895}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D9506CC-A6A1-4C0C-8827-9AB958942895}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/src/Standart.Hash.xxHash/Standart.Hash.xxHash.csproj b/src/Standart.Hash.xxHash/Standart.Hash.xxHash.csproj deleted file mode 100644 index 00d92f3..0000000 --- a/src/Standart.Hash.xxHash/Standart.Hash.xxHash.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - true - - - - - - - - \ No newline at end of file