Adler32 Class

Computes the Adler-32 checksum of RFC 1950: the checksum of zlib streams.

public static class Adler32

Remarks

The implementation uses the vector instructions of the processor (AdvSimd, AVX-512, AVX2, SSSE3) when they are available.

The vector paths sum whole blocks of w bytes (16, 32 or 64) in vector lanes. For a run of n bytes x0..x(n-1), RFC 1950 gives A = A0 + sum x and B = B0 + n A0 + sum (n - j) x_j. Split into blocks m = 0..k-1 of sums S_m, the weight of byte i of block m is w (k - 1 - m) + (w - i), so B = B0 + n A0 + w sum_m (S_0 + ... + S_(m-1)) + sum_m sum_i (w - i) x_(m,i): the lanes accumulate the block sums, their running prefix and the in-block weighted sums. Runs are short enough for 32-bit lanes (and for the 16-bit column sums of Adler32.UpdateAdvSimd); every path equals the byte-at-a-time reference (Adler32.UpdateScalar).

Methods

NameDescription
Append(uint, ReadOnlySpan<byte>)Computes the Adler-32 checksum of data that follows other data, from the checksum of the other data.
Compute(ReadOnlySpan<byte>)Computes the Adler-32 checksum of data.

Append(uint, ReadOnlySpan<byte>)

Adler32.cs

Computes the Adler-32 checksum of data that follows other data, from the checksum of the other data.

public static uint Append(uint checksum, ReadOnlySpan<byte> data)

Parameters

checksum uint
The Adler-32 checksum of the preceding data: 1 when there is none.
data ReadOnlySpan<byte>
The data that follows.

Returns

uint The Adler-32 checksum of the preceding data followed by data.

Remarks

Append(Compute(a), b) is Compute(a + b): use it to compute the checksum of data received in several parts.

Compute(ReadOnlySpan<byte>)

Adler32.cs

Computes the Adler-32 checksum of data.

public static uint Compute(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>
The data.

Returns

uint The Adler-32 checksum of data; 1 when it is empty.