Class ChecksumXXHash32
xxHash32 checksum algorithm implementation, providing extremely fast non-cryptographic 32-bit hashing. Based on the xxHash specification by Yann Collet (BSD 2-Clause License).
Implements
Inherited Members
Namespace: Scylla.Core.Util.Checksum
Assembly: ScyllaCore.dll
Syntax
public sealed class ChecksumXXHash32 : IChecksum
Remarks
Algorithm details:
- Output width: 32 bits.
- Block size: 16 bytes, processed by four parallel 32-bit accumulators.
- Remaining data (<16 bytes) is processed as 4-byte chunks, then byte-by-byte.
- A final avalanche mixing step ensures good bit diffusion.
- Accepts an optional seed value to produce different hashes for the same input, useful for hashtable seeding to prevent collision-based DoS attacks.
Streaming support: data can be fed in multiple Update(byte[]) calls. A 16-byte internal buffer accumulates partial blocks between calls.
Performance: xxHash32 regularly benchmarks faster than CRC-32 and Adler-32 while providing significantly better hash distribution. It is one of the fastest general-purpose hash algorithms available in pure C#.
Common use cases:
- Hash table keys where excellent avalanche distribution is required.
- Fast file checksums and bulk content comparison.
- Content-addressable storage identifiers.
- High-throughput data processing pipelines on 32-bit platforms.
Security note: xxHash32 is NOT cryptographically secure. For security-sensitive hashing use the Scylla Crypto module instead.
Constructors
ChecksumXXHash32(uint)
Initializes a new instance of ChecksumXXHash32 with an optional seed value and resets all accumulators to their seed-derived initial states.
Declaration
public ChecksumXXHash32(uint seed = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | seed | An optional 32-bit seed that alters the initial accumulator values, causing the
same input data to produce a different hash. Use different seeds to create
independent hash families (e.g. for hash-table seeding). Defaults to |
Properties
Value
Gets the current xxHash32 value computed from all data supplied so far.
Declaration
public long Value { get; }
Property Value
| Type | Description |
|---|---|
| long | A |
Methods
Reset()
Resets the xxHash32 to its seed-derived initial state, discarding all previously processed data and clearing the internal buffer.
Declaration
public void Reset()
Remarks
After calling Reset, the four accumulators are reinitialised from
_seed using the standard xxHash32 formulas
(acc1 = seed + PRIME1 + PRIME2, etc.), and both _totalLength and
_bufferSize are zeroed. The seed itself is preserved, so the next
computation uses the same seed as the original construction.
Update(byte[])
Updates the xxHash32 by incorporating all bytes in buffer.
Declaration
public void Update(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The byte array to process. If |
Update(byte[], int, int)
Updates the xxHash32 by incorporating count bytes from
buffer starting at offset.
Declaration
public void Update(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The source byte array. If |
| int | offset | Zero-based index of the first byte to read in |
| int | count | Number of bytes to process. Must not cause |
Remarks
If bytes are left in the internal 16-byte buffer from a previous call, incoming bytes are first used to fill that buffer. Once complete, the buffer is consumed by the four accumulators and cleared. Then any full 16-byte blocks in the input are processed directly. Any remaining bytes are stored in the buffer for the next call or for finalization when Value is read.
Multiple calls accumulate into the same state; the final hash is equivalent to processing the entire concatenated input in a single call.