Deterministic hash code generation for the Pure ecosystem — stable, byte-enumerable hashes over immutable primitive types.
Pure.HashCodes provides a single entry point — DeterminedHash — that produces a stable, ordered sequence of bytes for any value implementing a Pure.Primitives.Abstractions interface. Unlike object.GetHashCode(), the output is deterministic across processes and runtimes and can be combined from multiple fields into a single compound hash.
GetHashCode() and ToString() are intentionally unsupported on DeterminedHash and throw NotSupportedException — callers must consume the byte sequence directly.
DeterminedHash is a sealed record implementing IDeterminedHash : IEnumerable<byte>.
| Constructor | Input type |
|---|---|
DeterminedHash(IBool) |
Boolean value |
DeterminedHash(IChar) |
Single character |
DeterminedHash(IDate) |
Date (day / month / year) |
DeterminedHash(ITime) |
Time (hour / minute / second / …) |
DeterminedHash(IDateTime) |
Date + time composition |
DeterminedHash(IDayOfWeek) |
Day of week |
DeterminedHash(INumber<double>) |
64-bit floating point |
DeterminedHash(INumber<float>) |
32-bit floating point |
DeterminedHash(INumber<int>) |
Signed 32-bit integer |
DeterminedHash(INumber<uint>) |
Unsigned 32-bit integer |
DeterminedHash(INumber<ushort>) |
Unsigned 16-bit integer |
DeterminedHash(IGuid) |
GUID value |
DeterminedHash(IString) |
String value |
DeterminedHash(IEnumerable<IDeterminedHash>) |
Aggregated compound hash |
DeterminedHash(IEnumerable<byte>) |
Raw byte sequence |
- Deterministic — identical inputs always produce identical byte sequences, regardless of runtime or process lifetime.
- Abstraction-driven — works exclusively with
Pure.Primitives.Abstractionsinterfaces, not concrete types. - Composable — multiple
DeterminedHashvalues can be aggregated into a single compound hash viaIEnumerable<IDeterminedHash>. - AOT-compatible — the library is fully compatible with Native AOT compilation.
Pure.HashCodes.Abstractions— definesIDeterminedHash : IEnumerable<byte>, the core hash abstractionPure.Primitives.Abstractions— read-only interfaces for primitive types (IBool,IChar,IDate,ITime,IDateTime,IDayOfWeek,INumber<T>,IGuid,IString)
- .NET 7
- .NET 8
- .NET 9
- .NET 10
dotnet add package Pure.HashCodesHash a single primitive:
using Pure.HashCodes;
using Pure.Primitives.Number;
INumber<int> id = new Int(42);
IEnumerable<byte> hashBytes = new DeterminedHash(id);Combine multiple fields into a compound hash:
using Pure.HashCodes;
using Pure.HashCodes.Abstractions;
IDeterminedHash nameHash = new DeterminedHash(name);
IDeterminedHash dateHash = new DeterminedHash(birthDate);
IEnumerable<byte> compound = new DeterminedHash(new[] { nameHash, dateHash });