project files added and fixed

This commit is contained in:
Timerix22 2024-01-07 20:09:53 +06:00
parent 6b20e7f7b3
commit 90ad0a9f5a
39 changed files with 178 additions and 666 deletions

View File

@ -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

View File

@ -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

292
.gitignore vendored
View File

@ -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
[Bb]in/
.bin/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
nuget/
*[-_]tmp/
# Visual Studio 2015 cache/options directory
# IDE files
.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
.vscode/
.vshistory/
.idea/
*.sln.iml
.editorconfig
*.user
# 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
#backups
.old*/
*[-_]old/

View File

@ -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

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<BenchmarkDotNet>0.13.1</BenchmarkDotNet>
<MicrosoftSdk>17.2.0</MicrosoftSdk>
<xUnit>2.4.1</xUnit>
<xUnitRunner>2.4.5</xUnitRunner>
<xUnitTool>2.3.1</xUnitTool>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNet)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTLib.XXHash\DTLib.XXHash.csproj" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,4 @@
namespace Standart.Hash.xxHash.Perf
namespace DTLib.XXHash.PerformanceTest
{
using BenchmarkDotNet.Running;

View File

@ -1,4 +1,4 @@
namespace Standart.Hash.xxHash.Perf
namespace DTLib.XXHash.PerformanceTest
{
using System;
using BenchmarkDotNet.Attributes;

View File

@ -1,4 +1,4 @@
namespace Standart.Hash.xxHash.Perf
namespace DTLib.XXHash.PerformanceTest
{
using System;
using System.IO;

View File

@ -1,24 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\deps.props" />
<PropertyGroup>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType>
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<BenchmarkDotNet>0.13.1</BenchmarkDotNet>
<MicrosoftSdk>17.2.0</MicrosoftSdk>
<xUnit>2.4.1</xUnit>
<xUnitRunner>2.4.5</xUnitRunner>
<xUnitTool>2.3.1</xUnitTool>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>false</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftSdk)" />
<PackageReference Include="xunit" Version="$(xUnit)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitRunner)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitTool)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Standart.Hash.xxHash\Standart.Hash.xxHash.csproj" />
<ProjectReference Include="..\DTLib.XXHash\DTLib.XXHash.csproj" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,4 @@
namespace Standart.Hash.xxHash.Test
namespace DTLib.XXHash.Tests
{
using System;
using Xunit;

View File

@ -2,7 +2,7 @@ using System;
using System.Text;
using Xunit;
namespace Standart.Hash.xxHash.Test
namespace DTLib.XXHash.Tests
{
public class xxHash128Test
{

View File

@ -1,6 +1,6 @@
using System.Text;
namespace Standart.Hash.xxHash.Test
namespace DTLib.XXHash.Tests
{
using System;
using System.IO;

View File

@ -2,7 +2,7 @@
using System.Text;
using Xunit;
namespace Standart.Hash.xxHash.Test
namespace DTLib.XXHash.Tests
{
public class xxHash3Test
{

View File

@ -1,6 +1,6 @@
using System.Text;
namespace Standart.Hash.xxHash.Test
namespace DTLib.XXHash.Tests
{
using System;
using System.IO;

28
DTLib.XXHash.sln Normal file
View File

@ -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

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>DTLib.XXHash</PackageId>
<VersionPrefix>1.0.0</VersionPrefix>
<Authors>Oleksandr Melnyk, Timerix22</Authors>
<PackageTags>hash;xxHash;DTLib</PackageTags>
<Description>XXHash implementation in C# using intrinsics</Description>
<PackageProjectUrl>https://github.com/Timerix22/DTLib.XXHash</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Test" />
<InternalsVisibleTo Include="$(AssemblyName).Perf" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Buffers" Version="4.5.1" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'"/>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
</Project>

View File

@ -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<byte, ulong>(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)

View File

@ -6,7 +6,7 @@
using System.Runtime.CompilerServices;
namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
public partial class xxHash32
{

View File

@ -6,7 +6,7 @@
using System.Runtime.CompilerServices;
namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
public partial class xxHash64
{

View File

@ -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
{
@ -139,3 +138,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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
{
@ -715,3 +714,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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
{
@ -18,3 +17,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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
{
@ -141,7 +140,6 @@ namespace Standart.Hash.xxHash
return UnsafeComputeHash(ptr, length, seed).ToBytes();
}
}
/// <summary>
/// Compute hash bytes for the string
/// </summary>
@ -178,3 +176,4 @@ namespace Standart.Hash.xxHash
public ulong high64;
}
}
#endif

View File

@ -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);
@ -132,3 +130,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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)
{
@ -627,3 +624,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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
{
@ -18,3 +17,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -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
{
@ -94,3 +93,4 @@ namespace Standart.Hash.xxHash
}
}
}
#endif

View File

@ -1,8 +1,8 @@
// ReSharper disable InconsistentNaming
using System.Runtime.CompilerServices;
namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
public static partial class xxHash32
{

View File

@ -1,6 +1,6 @@
// ReSharper disable InconsistentNaming

namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
using System.Runtime.CompilerServices;

View File

@ -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
/// <returns>hash</returns>
public static ulong ComputeHash(ArraySegment<byte> 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<byte>.Shared.Return(buffer);
}
}
#if NET6_0_OR_GREATER
/// <summary>
/// Compute xxHash for the data byte span
/// </summary>
@ -175,7 +174,7 @@ namespace Standart.Hash.xxHash
return UnsafeComputeHash(pData, length, seed);
}
}
#endif
/// <summary>
/// Compute xxHash for the stream
/// </summary>

View File

@ -1,8 +1,8 @@
// ReSharper disable InconsistentNaming
using System.Runtime.CompilerServices;
namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
public static partial class xxHash64
{

View File

@ -1,6 +1,6 @@
// ReSharper disable InconsistentNaming

namespace Standart.Hash.xxHash
namespace DTLib.XXHash
{
using System.Runtime.CompilerServices;

View File

@ -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
/// <param name="data">The source of data</param>
/// <param name="seed">The seed number</param>
/// <returns>hash</returns>
public static unsafe ulong ComputeHash(System.ArraySegment<byte> data, ulong seed = 0)
public static ulong ComputeHash(System.ArraySegment<byte> 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<byte>.Shared.Return(buffer);
}
}
#if NET6_0_OR_GREATER
/// <summary>
/// Compute xxHash for the data byte span
/// </summary>
@ -175,7 +173,7 @@ namespace Standart.Hash.xxHash
return UnsafeComputeHash(pData, length, seed);
}
}
#endif
/// <summary>
/// Compute xxHash for the stream
/// </summary>

131
README.md
View File

@ -1,131 +0,0 @@
<p align="center">
<a href="#" target="_blank" rel="noopener noreferrer">
<img width="550" src="https://user-images.githubusercontent.com/1567570/39971158-5b213cca-56ff-11e8-9a1e-6c717e95d092.png" alt="xxHash.st">
</a>
</p>
<p align="center">
Extremely fast non-cryptographic hash algorithm <a href="http://www.xxhash.com/" target="_blank">xxhash</a>
</p>
<br>
<p align="center">
<a href="https://www.nuget.org/packages/Standart.Hash.xxHash">
<img src="https://img.shields.io/badge/platform-x64-blue.svg?longCache=true" alt="platform"/>
</a>
<a href="https://github.com/uranium62/xxHash/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="license" />
</a>
</p>
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<byte> 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<uint> 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<byte> 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<ulong> 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<byte> 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<byte> 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<byte>(data), data.Length);
ulong h64_3 = xxHash64.ComputeHash(new ReadOnlySpan<byte>(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<byte>(data), data.Length);
uint h32_3 = xxHash32.ComputeHash(new ReadOnlySpan<byte>(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<byte>(data), data.Length);
ulong h3_3 = xxHash3.ComputeHash(new ReadOnlySpan<byte>(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<byte>(data), data.Length);
uint128 h128_3 = xxHash128.ComputeHash(new ReadOnlySpan<byte>(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<byte>(data), data.Length);
byte[] hash_bytes_3 = xxHash128.ComputeHashBytes(new ReadOnlySpan<byte>(data), data.Length);
byte[] hash_bytes_4 = xxHash128.ComputeHashBytes("veni vidi vici");
```
---
<p align="center">
Made in :beginner: Ukraine with :heart:
</p>

View File

@ -1,11 +0,0 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<BenchmarkDotNet>0.13.1</BenchmarkDotNet>
<MicrosoftSdk>17.2.0</MicrosoftSdk>
<xUnit>2.4.1</xUnit>
<xUnitRunner>2.4.5</xUnitRunner>
<xUnitTool>2.3.1</xUnitTool>
</PropertyGroup>
</Project>

View File

@ -1,14 +0,0 @@
<Project>
<Import Project="deps.props" />
<PropertyGroup>
<PackageId>Standart.Hash.xxHash</PackageId>
<VersionPrefix>4.0.5</VersionPrefix>
<AssemblyName>Standart.Hash.xxHash</AssemblyName>
<AssemblyTitle>Standart.Hash.xxHash</AssemblyTitle>
<Authors>Oleksandr Melnyk</Authors>
<PackageTags>hash;xxHash</PackageTags>
<Description>Standart.Hash.xxHash</Description>
<PackageProjectUrl>https://github.com/uranium62/xxHash</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
</Project>

View File

@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\deps.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<Optimize>false</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNet)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Standart.Hash.xxHash\Standart.Hash.xxHash.csproj" />
</ItemGroup>
</Project>

View File

@ -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

View File

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\nuget.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Test" />
<InternalsVisibleTo Include="$(AssemblyName).Perf" />
</ItemGroup>
</Project>