CityHash64 Class
Definition
Computes a 64-bit (8-byte) non-cryptographic hash using the CityHash64 variant by Google. This class cannot
be inherited.
public sealed class CityHash64 : CityHash, IDisposable
- Inheritance
-
CityHash64
- Implements
- Inherited Members
- Extension Methods
-
NonCryptographicHashAlgorithmExtensions.ComputeHash(NonCryptographicHashAlgorithm, byte[], int, int)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], byte[])NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, byte[], string)NonCryptographicHashAlgorithmExtensions.TryVerifyHash(NonCryptographicHashAlgorithm, Stream, byte[])
Remarks
CityHash64 selects one of four internal mixing paths depending on the input length: a compact path
for 0-16 bytes, a four-word path for 17-32 bytes, an eight-word path with byte-swap finalization for 33-64 bytes,
and a full iterative path that consumes 64-byte blocks using two pairs of seeded weak hash accumulators for inputs
of 65 bytes or more. All paths converge through the shared HashLen16 finalizer, which applies two rounds of
multiply-shift-XOR to distribute entropy across all output bits.
Parameters at a glance.
- Output size: 64 bits (8 bytes), little-endian.
- Variant:
CityHash64. - Length-dispatched mixing: 0-16, 17-32, 33-64, and 65+ byte paths.
- Block size on the long path: 64 bytes.
When to choose CityHash64. The general-purpose default for 64-bit non-cryptographic hashing - fingerprints, content-based sharding, deduplication keys. MurmurHash3_128 gives twice the bits at slightly lower throughput on long inputs; Fnv1a64 is preferable only for very small fixed-length keys where simplicity matters more than distribution.
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 CityHash64();
byte[] fingerprint = city.ComputeHash(blob);
Constructors
CityHash64()
Initializes a new instance of the CityHash64 class with a fixed 64-bit (8-byte) hash output size.
public CityHash64()
Methods
ComputeHashCore(ReadOnlySpan<byte>)
Computes the 64-bit CityHash of the provided input span, selecting the optimal mixing path based on input length.
protected override byte[] ComputeHashCore(ReadOnlySpan<byte> source)
Parameters
sourceReadOnlySpan<byte>The input bytes to hash.
Returns
- byte[]
An 8-byte array containing the little-endian encoded 64-bit hash value.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |