PolynomialHash 1.0.0
dotnet add package PolynomialHash --version 1.0.0
NuGet\Install-Package PolynomialHash -Version 1.0.0
<PackageReference Include="PolynomialHash" Version="1.0.0" />
<PackageVersion Include="PolynomialHash" Version="1.0.0" />
<PackageReference Include="PolynomialHash" />
paket add PolynomialHash --version 1.0.0
#r "nuget: PolynomialHash, 1.0.0"
#:package PolynomialHash@1.0.0
#addin nuget:?package=PolynomialHash&version=1.0.0
#tool nuget:?package=PolynomialHash&version=1.0.0
PolynomialHash
.NET10 Polynomial Rolling Hash Library which lets you compute a polynomial rolling hash over any IEnumerable<T> sequence with a single extension method call. It is also built for native integration, allowing you to plug it directly into standard data structures like Dictionary or HashSet to easily treat sequences as keys.
Examples
Hashing sequences
using PolynomialHash;
// Hash a string using the numeric value of each character
ulong hash = "hello world".ToUInt64PolynomialHash(c => c);
// Hash a list of integers
int hash32 = new[] { 1, 2, 3, 4, 5 }.ToInt32PolynomialHash(x => x);
// Hash a sequence of custom objects by a meaningful key
var orders = new[] { new Order(id: 1, amount: 99), new Order(id: 2, amount: 42) };
ulong orderHash = orders.ToUInt64PolynomialHash(o => o.Id);
Using as an equality comparer in collections
PolynomialHasher<T> implements IEqualityComparer<IEnumerable<T>>, which means you can plug it directly into a HashSet or Dictionary to treat sequences as keys. Two sequences with the same elements in the same order will be considered equal.
using PolynomialHash;
var comparer = new PolynomialHasher<int>(x => x);
// HashSet that deduplicates sequences by their contents
var seen = new HashSet<IEnumerable<int>>(comparer);
seen.Add(new[] { 1, 2, 3 }); // added
seen.Add(new[] { 4, 5, 6 }); // added
seen.Add(new[] { 1, 2, 3 }); // duplicate
Console.WriteLine(seen.Count); // 2
// Dictionary keyed by integer sequences
var cache = new Dictionary<IEnumerable<int>, string>(comparer);
cache[new[] { 10, 20, 30 }] = "first entry";
Console.WriteLine(cache[new[] { 10, 20, 30 }]); // "first entry"
Tuning the hash
All methods accept optional prime and mod parameters so you can adapt the hash to your performance or collision-resistance requirements:
ulong hash = mySequence.ToUInt64PolynomialHash(
valueSelector: x => x,
prime: 131,
mod: 1_000_000_007);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 100 | 4/22/2026 |