Skip to content

Repository files navigation

Pure.HashCodes

Deterministic hash code generation for the Pure ecosystem — stable, byte-enumerable hashes over immutable primitive types.

.NET build & testBenchmarksBuild and DeployNuGetLicense: MIT

Overview

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.

API

DeterminedHash is a sealed record implementing IDeterminedHash : IEnumerable<byte>.

Constructors

ConstructorInput 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

Design Principles

  • Deterministic — identical inputs always produce identical byte sequences, regardless of runtime or process lifetime.
  • Abstraction-driven — works exclusively with Pure.Primitives.Abstractions interfaces, not concrete types.
  • Composable — multiple DeterminedHash values can be aggregated into a single compound hash via IEnumerable<IDeterminedHash>.
  • AOT-compatible — the library is fully compatible with Native AOT compilation.

Dependencies

Target Frameworks

  • .NET 7
  • .NET 8
  • .NET 9
  • .NET 10

Installation

dotnet add package Pure.HashCodes

Usage

Hash a single primitive:

usingPure.HashCodes;usingPure.Primitives.Number;INumber<int>id=newInt(42);IEnumerable<byte>hashBytes=newDeterminedHash(id);

Combine multiple fields into a compound hash:

usingPure.HashCodes;usingPure.HashCodes.Abstractions;IDeterminedHashnameHash=newDeterminedHash(name);IDeterminedHashdateHash=newDeterminedHash(birthDate);IEnumerable<byte>compound=newDeterminedHash(new[]{nameHash,dateHash});

About

Deterministic hash code generation for the Pure ecosystem — stable, byte-enumerable hashes over immutable primitive types via DeterminedHash.

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Generated from kudima03/Pure.Template