Class ChecksumXXHash64
xxHash64 checksum algorithm implementation, providing extremely fast non-cryptographic 64-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 ChecksumXXHash64 : IChecksum
Remarks
Algorithm details:
- Output width: 64 bits.
- Block size: 32 bytes, processed by four parallel 64-bit accumulators.
- Tail data (<32 bytes) is processed as 8-byte chunks, then a 4-byte chunk, then byte-by-byte.
- The xxHash64 MergeAccumulator(ulong, ulong) step (unique to xxHash64 vs. xxHash32) provides additional diffusion during accumulator merging.
- A three-step XOR-shift avalanche finalises the result.
- Accepts an optional 64-bit seed to produce different hashes for the same input.
Streaming support: data can be fed in multiple Update(byte[]) calls. A 32-byte internal buffer accumulates partial blocks between calls.
Performance: on 64-bit platforms xxHash64 is typically faster than xxHash32 for the same input size because the 64-bit accumulators process twice as many bytes per round. It is one of the fastest hashing algorithms available in pure C#.
Common use cases:
- Very large file checksums and multi-gigabyte content comparison.
- Content deduplication with an extremely low collision probability.
- Distributed systems and content-addressable storage identifiers.
- Any context where a full 64-bit hash range is needed over xxHash32's 32 bits.
Note on Value: the interface exposes long,
so the full unsigned 64-bit result is reinterpreted as a signed long.
Cast to ulong via (ulong)Value to recover the canonical unsigned value.
Security note: xxHash64 is NOT cryptographically secure. For security-sensitive hashing use the Scylla Crypto module instead.
Constructors
ChecksumXXHash64(ulong)
Initializes a new instance of ChecksumXXHash64 with an optional seed value and resets all accumulators to their seed-derived initial states.
Declaration
public ChecksumXXHash64(ulong seed = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | seed | An optional 64-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 distributed hash-table seeding). Defaults to
|
Properties
Value
Gets the current xxHash64 value computed from all data supplied so far.
Declaration
public long Value { get; }
Property Value
| Type | Description |
|---|---|
| long | The unsigned 64-bit xxHash64 result reinterpreted as a signed |
Methods
Reset()
Resets the xxHash64 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 xxHash64 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 xxHash64 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 xxHash64 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 32-byte buffer from a previous call, incoming bytes are first used to fill that buffer. Once complete, the buffer is consumed by the four 64-bit accumulators and cleared. Then any full 32-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.