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 withSystem.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
- Integer values are hashed in machine byte order (little-endian on every platform .NET 8+ supports).
HashCodeinstances are accumulators:EqualsandGetHashCodeon the instance are deliberately unsupported.