Table of Contents

CityHash128 Class

Definition

Namespace
Bodu.IO.Hashing
Assembly
Bodu.IO.Hashing.dll
Package
Bodu.IO.Hashing 1.0.0
Source
CityHash.128.cs

Computes a 128-bit (16-byte) non-cryptographic hash using the CityHash128 variant by Google. This class cannot be inherited.

public sealed class CityHash128 : CityHash, IDisposable
Inheritance
CityHash128
Implements
Inherited Members
Extension Methods

Remarks

CityHash128 chooses its initial 128-bit seed from the first 16 bytes of input (or from the fixed constants K0, K1 for shorter inputs), then delegates to CityHash128WithSeed. For inputs shorter than 128 bytes, CityMurmur folds the message into the seeded accumulator; for longer inputs, a main loop consumes 128-byte blocks using two pairs of seeded weak-hash accumulators before a tail pass over the remaining 0-127 bytes.

The digest is emitted as two consecutive little-endian 64-bit words (First followed by Second), matching the encoding convention used by CityHash64.

Parameters at a glance.

  • Output size: 128 bits (16 bytes), little-endian, two 64-bit words.
  • Variant: CityHash128.
  • Length-dispatched mixing: <128-byte and 128+-byte paths.
  • Block size on the long path: 128 bytes.

When to choose CityHash128. Pick CityHash128 for low-collision fingerprinting of large key spaces - content-addressed storage, deduplication, two-hash cuckoo / split-key schemes that can use the two 64-bit halves independently. MurmurHash3_128 is the closest alternative; it supports a constructor seed but is typically slightly slower on long inputs on 64-bit CPUs.

important

This algorithm is not cryptographically secure and must not be used for password hashing, digital signatures, or any application requiring adversarial collision resistance.

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

var city = new CityHash128();
byte[] fingerprint = city.ComputeHash(blob);
// fingerprint = [low 64 bits || high 64 bits], each little-endian.

Constructors

CityHash128()

Initializes a new instance of the CityHash128 class with a fixed 128-bit (16-byte) hash output size.

public CityHash128()

Methods

ComputeHashCore(ReadOnlySpan<byte>)

Computes the 128-bit CityHash of the provided input span, selecting the optimal mixing path based on input length.

protected override byte[] ComputeHashCore(ReadOnlySpan<byte> source)

Parameters

source ReadOnlySpan<byte>

The input bytes to hash.

Returns

byte[]

A 16-byte array containing the little-endian encoded 128-bit hash value.

Applies to

ProductVersions
.NET8, 10

See Also