Table of Contents

JSHash Class

Definition

Namespace
Bodu.IO.Hashing
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
JSHash.cs

Computes a 32-bit non-cryptographic hash using Justin Sobel's JSHash bitwise mixing function. This class cannot be inherited.

public sealed class JSHash : NonCryptographicHashAlgorithm
Inheritance
JSHash
Inherited Members
Extension Methods

Remarks

For each input byte, JSHash updates the running hash as hash ^= (hash << 5) + (hash >> 2) + byte, seeded with 0x4E67C6A7. The finalized hash is written to the output buffer in little-endian byte order.

When to choose JSHash. JSHash is one of the small bitwise-mix hashes - pick it when a short, dependency-free 32-bit hash is sufficient and the per-byte cost matters. Its distribution is roughly comparable to ApHash, SDBM, and Pjw32; the choice between them is usually driven by interop with an existing system. For modern hash-table workloads prefer Fnv1a32 (better avalanche, same cost) or MurmurHash3_32 (markedly better distribution on inputs longer than ~16 bytes).

Output and lifecycle. Produces a 32-bit (4-byte) digest in little-endian byte order. GetCurrentHash() is non-destructive; instances are not thread-safe.

important

This algorithm is not cryptographically secure and should not be used for password hashing, digital signatures, or integrity validation in security-sensitive applications.

using Bodu.IO.Hashing;
using Bodu.IO.Hashing.Extensions;

var js = new JSHash();
byte[] digest = js.ComputeHash(System.Text.Encoding.UTF8.GetBytes("input-key"));

Constructors

JSHash()

Initializes a new instance of the JSHash class seeded with the canonical 0x4E67C6A7 initial value.

public JSHash()

Methods

Append(ReadOnlySpan<byte>)

When overridden in a derived class, appends the contents of source to the data already processed for the current hash computation.

public override void Append(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The data to process.

GetCurrentHashCore(Span<byte>)

When overridden in a derived class, writes the computed hash value to destination without modifying accumulated state.

protected override void GetCurrentHashCore(Span<byte> destination)

Parameters

destination Span<byte>

The buffer that receives the computed hash value.

Reset()

When overridden in a derived class, resets the hash computation to the initial state.

public override void Reset()

Applies to

ProductVersions
.NET8, 10