Table of Contents

SuperFastHash Class

Definition

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

Computes a 32-bit non-cryptographic hash using Paul Hsieh's SuperFastHash algorithm, intended for hash-table keying. This class cannot be inherited.

public sealed class SuperFastHash : NonCryptographicHashAlgorithm, IDisposable
Inheritance
SuperFastHash
Implements
Inherited Members
Extension Methods

Remarks

The algorithm seeds the running hash with the total length of the input and therefore requires the entire payload to be visible before finalization. Appended bytes are accumulated in an internal buffer and the full compute is executed each time the current hash is requested. The finalized 32-bit value is written to the output buffer in little-endian byte order.

Because the implementation buffers its input, memory use grows linearly with the total number of bytes appended between calls to Reset(). The algorithm is well suited to short keys - its intended use case - but should be avoided for very large streams where a block-oriented, fixed-memory hash would be more appropriate.

When to choose SuperFastHash. SuperFastHash predates MurmurHash and was designed by Paul Hsieh for in-memory hash tables of short keys (32-byte block sums and similar). It has been superseded by the MurmurHash3 / CityHash / xxHash generation, which beat it on every measurable axis - pick it only when reproducing a digest from existing SuperFastHash-based code. For new work on short keys prefer MurmurHash3_32 or Fnv1a32; for streaming and very large inputs prefer CityHash64 or a CRC variant via Crc.

Instances are not thread-safe; share behind explicit synchronization.

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;

// Suited to short keys; avoid for multi-megabyte streams (the input is fully buffered).
var sfh = new SuperFastHash();
byte[] digest = sfh.ComputeHash(System.Text.Encoding.UTF8.GetBytes("short-key"));

Constructors

SuperFastHash()

Initializes a new instance of the SuperFastHash class.

public SuperFastHash()

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.

Dispose()

Releases the unmanaged resources used by the SuperFastHash instance and clears its buffered input state.

public void Dispose()

Remarks

Subsequent calls to Append(ReadOnlySpan<byte>), Reset(), or GetCurrentHashCore(Span<byte>) throw ObjectDisposedException. Calling Dispose() multiple times is safe and has no effect after the first invocation.

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