PolynomialHash 1.0.0

dotnet add package PolynomialHash --version 1.0.0
                    
NuGet\Install-Package PolynomialHash -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PolynomialHash" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PolynomialHash" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PolynomialHash" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PolynomialHash --version 1.0.0
                    
#r "nuget: PolynomialHash, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PolynomialHash@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PolynomialHash&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PolynomialHash&version=1.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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