std.hash
Provides the hashers and the checksums of common formats and protocols.
DefaultHasher is SipHash-1-3 under a key the system draws once per process: a Map hashes
with it, its order differs from run to run, and no input from outside can aim collisions at
it. FixedHasher is the same under a zero key, for what must hash alike in every run;
Fnv1a64 is fast and keyless, for trusted input. All three implement Hasher. The checksums
are crc32, crc32c and adler32.
Examples
import std.io { println };
import std.hash { crc32, FixedHasher };
println(crc32("hello".bytes()));
var a = FixedHasher.new();
"hello".hash(&a);
var b = FixedHasher.new();
"hello".hash(&b);
println(a.finish() == b.finish());
907060870
true
Types
Functions
pub fn crc32(bytes: Slice<uint8>, running: uint32 = 0): uint32
Returns the CRC-32 (ISO-HDLC, as in zip, gzip and PNG) of bytes, continued from running.
running is the checksum of what came before, 0 at the start, so the checksum of the whole
is that of its pieces, one after the other. crc32("123456789".bytes()) is 0xCBF43926.
pub fn crc32c(bytes: Slice<uint8>, running: uint32 = 0): uint32
Returns the CRC-32C (the Castagnoli polynomial, as in iSCSI, RFC 3720) of bytes, continued
from running.
running is the checksum of what came before, 0 at the start.
crc32c("123456789".bytes()) is 0xE3069283.
pub fn adler32(bytes: Slice<uint8>, running: uint32 = 1): uint32
Returns the Adler-32 (RFC 1950) of bytes, continued from running.
running is the checksum of what came before, 1 at the start.
adler32("Wikipedia".bytes()) is 0x11E60398.