budul.HashExtensions
3.0.0
dotnet add package budul.HashExtensions --version 3.0.0
NuGet\Install-Package budul.HashExtensions -Version 3.0.0
<PackageReference Include="budul.HashExtensions" Version="3.0.0" />
<PackageVersion Include="budul.HashExtensions" Version="3.0.0" />
<PackageReference Include="budul.HashExtensions" />
paket add budul.HashExtensions --version 3.0.0
#r "nuget: budul.HashExtensions, 3.0.0"
#:package budul.HashExtensions@3.0.0
#addin nuget:?package=budul.HashExtensions&version=3.0.0
#tool nuget:?package=budul.HashExtensions&version=3.0.0
HashExtensions
HashExtensions is a C# library providing flexible and efficient hashing utilities for sequences, collections, and strings. It targets .NET 10.
Features
- Sequence Hashing: Compute hashes for sequences, collections, or arrays, with support for:
- Order-sensitive, order-insensitive, and direction-insensitive hashing
- Hashing based on specific properties or multiple properties
- Static Hash Generation: Generate fixed-length numeric or alphanumeric hashes from strings or collections of strings. The results are stable across processes, machines, and runs
- Customizable Hash Length: Control the length of generated hashes (1 to 12 digits/characters)
- Optimized Performance: Single enumeration, span-based hashing, and allocation-free hashing of short strings
Installation
dotnet add package budul.HashExtensions
Usage
Sequence Hashing
Sequence hashes are based on System.HashCode. They are consistent within a process, but not stable across processes. Do not persist them.
using HashExtensions;
// Hash a sequence of objects
int hash = Extensions.GetSequenceHash(item1, item2, item3);
// Hash a collection with a property selector
int hash = myList.GetSequenceHash(x => x.Id);
// Hash a collection with multiple property selectors
int hash = myList.GetSequenceHash(x => x.Id, x => x.Name);
// Order-insensitive hash (items do not need to be comparable)
int hash = myList.GetSequenceHashOrdered();
// Direction-insensitive hash
int hash = myList.GetSequenceHashDirected();
Static Hash Generation
Static hashes are derived from SHA-256 and always return the same result for the same input.
using HashExtensions;
// Numeric hash from strings
ulong numHash = Extensions.GetStaticHashNumber("foo", "bar");
// Alphanumeric hash from strings
string textHash = Extensions.GetStaticHashText("foo", "bar");
// Control hash length (1 to 12)
ulong shortHash = "example".GetStaticHashNumber(length: 6);
string shortTextHash = "example".GetStaticHashText(length: 8);
Collections of strings are hashed value by value, including the length of each value. ["a\nb"] and ["a", "b"] therefore produce different hashes. Null and empty inputs result in 0 (numeric) or an empty string (text).
API Reference
See HashExtensions/Extensions.cs for full documentation and XML comments.
Target Frameworks
- .NET 10
Migration to 3.0
- Only .NET 10 is supported. Older target frameworks (.NET Standard 2.1, .NET 6/7/8) were dropped.
- The values of
GetStaticHashNumberandGetStaticHashTextchanged (new hash derivation and collection hashing). Re-calculate stored hashes. GetSequenceHash<T>(params Func<T, object>[])was removed. It hashed the delegates, not the values.GetSequenceHashOrderedno longer requires comparable items.
License
MIT
Contributing
Contributions, issues, and feature requests are welcome!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.