{"id":22519586,"url":"https://github.com/cocowalla/wyhash-dotnet","last_synced_at":"2025-08-03T06:33:57.114Z","repository":{"id":65414043,"uuid":"182115557","full_name":"cocowalla/wyhash-dotnet","owner":"cocowalla","description":"Zero-allocation C# implementation of Wang Yi's wyhash hash algorithm and wyrand PRNG","archived":false,"fork":false,"pushed_at":"2023-06-16T11:23:57.000Z","size":74,"stargazers_count":55,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-01T01:33:38.330Z","etag":null,"topics":["hash","hashing","hashing-algorithm","wyhash"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cocowalla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-18T15:46:09.000Z","updated_at":"2024-11-03T11:42:48.000Z","dependencies_parsed_at":"2023-01-23T10:55:06.985Z","dependency_job_id":null,"html_url":"https://github.com/cocowalla/wyhash-dotnet","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cocowalla/wyhash-dotnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocowalla%2Fwyhash-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocowalla%2Fwyhash-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocowalla%2Fwyhash-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocowalla%2Fwyhash-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cocowalla","download_url":"https://codeload.github.com/cocowalla/wyhash-dotnet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocowalla%2Fwyhash-dotnet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268505377,"owners_count":24260950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hash","hashing","hashing-algorithm","wyhash"],"created_at":"2024-12-07T04:25:11.729Z","updated_at":"2025-08-03T06:33:57.066Z","avatar_url":"https://github.com/cocowalla.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"wyhash-dotnet\n=============\n[![NuGet](https://img.shields.io/nuget/v/WyHash.svg)](https://www.nuget.org/packages/WyHash)\n[![Build Status](https://ci.appveyor.com/api/projects/status/yv41pshy1xaks5ps?svg=true)](https://ci.appveyor.com/project/cocowalla/wyhash-dotnet)\n\nZero-allocation C# implementation of [Wang Yi's](https://github.com/wangyi-fudan/wyhash) 64-bit **wyhash** hash algorithm and **wyrand** PRNG.\n\nwyhash is an extremely fast, portable hashing algorithm, and passes all of the [SMHasher](https://github.com/rurban/smhasher) tests (which evaluates collision, dispersion and randomness qualities of hash functions).\n\nNote wyhash-dotnet currently implements wyhash v1. v2 will be implemented once considered \"stable\".\n\nGetting Started\n-----\n\nInstall the [WyHash](https://www.nuget.org/packages/WyHash) package from NuGet:\n\n```powershell\nInstall-Package WyHash\n```\n\nWyHash implements [HashAlgorithm](https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.hashalgorithm?view=netframework-4.7.2), so can be integrated into existing projects easily:\n\n```csharp\nvar seed = 42;\nvar hasher = WyHash64.Create(seed);\n\nvar result = hasher.ComputeHash(myData);\n```\n\nA common use case is getting the resulting hash as a 64-bit unsigned integer (`ulong`), so a static convenience method is also provided:\n\n```csharp\n// Note that if no seed is specified, it default to 0\nvar seed = 42;\nvar result = WyHash64.ComputeHash64(myData, seed);\n```\n\nThe wyrand PRNG is also implemented:\n\n```csharp\nvar rng = new WyRng(42);\n\n// Generate pseudorandom values\nulong a64BitVal = rng.NextLong();\nuint a32BitVal = rng.Next();\n\n// Fill a buffer with pseudorandom bytes\nvar buffer = new byte[256];\nrng.NextBytes(buffer);\n\n// Span is also supported\nSpan\u003cbyte\u003e spanBuffer = stackalloc byte[128];\nrng.NextBytes(spanBuffer);\n```\n\nPerformance \u0026 Future Work\n-------------------------\nNote wyhash-dotnet currently implements wyhash v1. v2 will be implemented once considered \"stable\".\n\nFuture improvements include support for `Span` and incremental hashing (useful for hashing streams).\n\nAt present (July 2019), wyhash is the fastest algorithm in the [SMHasher](https://github.com/rurban/smhasher) benchmark.\n\nOn a dev laptop with 64GB RAM and an Intel Xeon CPU E3-1545M v5 2.90GHz CPU, this implementation can process data at a rate of around 5.5GB/s on .NET Core 3, or 3.3GB/s on .NET Core 2 or the .NET Framework - this is *very* fast.\n\nThe reason for the performance improvement on .NET Core 3+ is that it supports [hardware intrinsics](https://fiigii.com/2019/03/03/Hardware-intrinsic-in-NET-Core-3-0-Introduction/), and wyhash-dotnet uses the [BMI2 `MULX`](https://www.felixcloutier.com/x86/MULX.html) instruction to achieve faster 64-bit integer multiplication (on systems where BMI2 is available). Support for intrinsics won't make it into the .NET Framework, but will also be in the newly announced .NET 5.\n\nNote that `PInvoke`ing into a native DLL built using the reference C code (see the `WyHash.Native` project) achieves around 10.8GB/s (more or less *RAM SPEED*), so there is still work to do to bridge the performance gap between C# and native - I'm very much open to suggestions here!\n\nLatest benchmarks (`DataSize` is the size of data hashed, in bytes):\n\n```ini\n\nBenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.3086/22H2/2022Update)\nAMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores\n.NET SDK=7.0.107\n  [Host]            : .NET 6.0.18 (6.0.1823.26907), X64 RyuJIT AVX2\n  ShortRun-.NET 6.0 : .NET 6.0.18 (6.0.1823.26907), X64 RyuJIT AVX2\n\nJob=ShortRun-.NET 6.0  Runtime=.NET 6.0  IterationCount=3  \nLaunchCount=1  WarmupCount=3  \n\n```\n|           Method | DataSize |      Mean |     Error |   StdDev |       Min |       Max | Ratio | Rank | Allocated | Alloc Ratio |\n|----------------- |--------- |----------:|----------:|---------:|----------:|----------:|------:|-----:|----------:|------------:|\n|       TestXxHash |      100 |  17.77 ns |  1.179 ns | 0.065 ns |  17.71 ns |  17.84 ns |  0.97 |    2 |         - |          NA |\n| TestXxHashNative |      100 |  21.89 ns |  4.087 ns | 0.224 ns |  21.75 ns |  22.14 ns |  1.19 |    4 |         - |          NA |\n| TestWyHashNative |      100 |  14.58 ns |  1.336 ns | 0.073 ns |  14.53 ns |  14.67 ns |  0.79 |    1 |         - |          NA |\n|       **TestWyHash** |      **100** |  **18.40 ns** |  **2.422 ns** | **0.133 ns** |  **18.30 ns** |  **18.55 ns** |  **1.00** |    **3** |         **-** |          **NA** |\n|                  |          |           |           |          |           |           |       |      |           |             |\n|       TestXxHash |     1024 |  89.38 ns | 10.387 ns | 0.569 ns |  88.95 ns |  90.02 ns |  0.73 |    3 |         - |          NA |\n| TestXxHashNative |     1024 |  81.17 ns |  3.474 ns | 0.190 ns |  80.98 ns |  81.36 ns |  0.67 |    2 |         - |          NA |\n| TestWyHashNative |     1024 |  64.38 ns |  2.001 ns | 0.110 ns |  64.27 ns |  64.49 ns |  0.53 |    1 |         - |          NA |\n|       **TestWyHash** |     **1024** | **121.77 ns** | **23.792 ns** | **1.304 ns** | **120.53 ns** | **123.13 ns** |  **1.00** |    **4** |         **-** |          NA |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocowalla%2Fwyhash-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocowalla%2Fwyhash-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocowalla%2Fwyhash-dotnet/lists"}