Every // ---- section banner dies (132 -> 0): names carry the WHAT. Narration deleted (filename restatements, run-with lines, what-the- next-line-does); every ref/hare cite, task cite, divergence, ABI/ layout contract, and ownership qualifier kept (borrowed-view lines restored where the sweep over-cut). Comment-only proven: all 442 walk-workdir .s and 32 import-probe .s byte-identical before/after; libbyteid 56-roster all-ID.
23 lines
565 B
Plaintext
23 lines
565 B
Plaintext
// Adler-32 checksum (RFC 1950).
|
|
//
|
|
// Hare ships a hash::hash-shaped streaming type backed by io::stream;
|
|
// we ship the pure-buffer subset here, same shape as lib/hash/fnv.
|
|
// `sum32(buf)` matches Hare's adler32::sum32 contract for a single
|
|
// write-then-sum: a = 1, b = 0, fold each byte, return b<<16 | a.
|
|
|
|
package adler32;
|
|
|
|
def MOD: u32 = 65521u32;
|
|
|
|
export fn sum32(buf: []u8) u32 = {
|
|
let a: u32 = 1u32;
|
|
let b: u32 = 0u32;
|
|
let i: i32 = 0;
|
|
for (i < buf.len) {
|
|
a = (a + (buf[i]: u32)) % MOD;
|
|
b = (b + a) % MOD;
|
|
i += 1;
|
|
};
|
|
return (b << 16u32) | a;
|
|
};
|