Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Repository files navigation

Pure.HashCodes

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

.NET build & test Benchmarks Build and Deploy NuGet License: 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

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

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:

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 });

About

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

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Generated from kudima03/Pure.Template
Morty Proxy This is a proxified and sanitized view of the page, visit original site.