Axle v0.14.1
Package

std/text/checksum

std/checksum — non-cryptographic data integrity checks.

CRC32 follows the IEEE 802.3 polynomial (same as zlib / gzip).
Adler-32 is RFC 1950 (zlib's other hash). Both are streaming-
friendly : pass the previous result as the seed to extend an
existing checksum without re-hashing.

Use std/hashing for HashMap keys; std/crypto for
security-relevant integrity. These are for "did the file arrive
intact" / "is the cache stale" checks.

Implemented in pure Axle.

Free functions

TypeMethod and description
i64
crc32Update(seed : i64, data : string) : i64 IEEE 802.3 CRC32, reflected form.
POLY = 0xEDB88320, mask = 0xFFFFFFFF.
Table-less inner loop : 8 polynomial divisions per byte. Slower
than a 256-entry lookup, but the algorithm is exact.
i64
crc32(data : string) : i64 Convenience seed-0 entry point: the CRC32 of data on its own.
i64
adler32Update(seed : i64, data : string) : i64 Adler-32 (RFC 1950).
a = 1, b = 0 initially.
per byte : a = (a + byte) % MOD ; b = (b + a) % MOD.
result = (b << 16) | a.
i64
adler32(data : string) : i64 Convenience seed-0 entry point: the Adler-32 of data on its own.

Method detail

#crc32Update

crc32Update(seed : i64, data : string) : i64

IEEE 802.3 CRC32, reflected form.
POLY = 0xEDB88320, mask = 0xFFFFFFFF.
Table-less inner loop : 8 polynomial divisions per byte. Slower
than a 256-entry lookup, but the algorithm is exact.

Parameters
seed previous CRC32 result to extend (0 to start fresh)
data bytes to fold into the running checksum

#crc32

crc32(data : string) : i64

Convenience seed-0 entry point: the CRC32 of data on its own.

Parameters
data bytes to checksum

#adler32Update

adler32Update(seed : i64, data : string) : i64

Adler-32 (RFC 1950).
a = 1, b = 0 initially.
per byte : a = (a + byte) % MOD ; b = (b + a) % MOD.
result = (b << 16) | a.

Parameters
seed previous Adler-32 result to extend (0 to start fresh)
data bytes to fold into the running sums a and b

#adler32

adler32(data : string) : i64

Convenience seed-0 entry point: the Adler-32 of data on its own.

Parameters
data bytes to checksum