Deterministic HashCode

Pineapple.Common.HashCode combines values into a 32-bit xxHash that is identical across processes, machines, and restarts. Use it when a hash must be stored or shared — cache keys, partition/shard keys, change detection — where System.HashCode (randomized per process) is unsuitable.

using HashCode = Pineapple.Common.HashCode;

int key = HashCode.Combine(tenantId, "orders", orderDate);   // up to 7 values

var hc = new HashCode();
foreach (var line in order.Lines)
{
    hc.Add(line.Sku);
    hc.Add(line.Quantity);
}
int linesHash = hc.ToHashCode();

Alias the type (using HashCode = Pineapple.Common.HashCode;) to avoid a clash with System.HashCode.

Supported value types

string (UTF-8), bool, char, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, DateTime (by ticks), their nullable forms, and null. Other types throw NotSupportedException — hash their stable fields instead.

Notes

Last reviewed October 13, 2026 · Pineapple 2.0.0