Embed std.hash with four ordinary safe byte functions: FNV-1a 64 and Castagnoli CRC-32C, each with fresh and numeric continuation forms. Specify exact constants, empty/chunk semantics, arbitrary continuation states, target-independent numeric results and explicit serialization. No heap allocation, authority, AIR, verifier or runtime change. Propose the next U64Map<V> contract: exact key equality, bounded insert, returned replacement/full ownership, tombstones, moving drain and failure-preserving peak-charged rehash. Keep general HashMap<K,V> key hash/equality policy open as Q-037. A checked slot prerequisite confirms read-only Copy key/state fields over Option<V>, with explicit accounting for both tags and owning payload cleanup; no map module is registered. Validation: unit tests, 797 full conformance cases, 12 new fixtures; all 11 hash cases with per-instruction collection and 12 schedule seeds across four quanta, plus owning slot collection; 84 source/AIR, package and hosted CLI checks; independent forward-polynomial CRC and arbitrary precision FNV oracles for 286 inputs / 1144 results; 95/95 source coverage; Zig formatting, whitespace and reference generation. Published vectors come from RFC 9923 and RFC 3720, with explicit numeric/wire conventions. Reference cost: source excluding AIR 53,993 -> 55,281 cl100k (+2.4%); Quick Reference 7,747 -> 7,806 (+0.8%); AIR remains 175,736 bytes. Map design remains outside both bundles. No empirical MCC or native throughput claim; CRC initially uses eight bit steps per byte.
29 lines
2.3 KiB
Rust
29 lines
2.3 KiB
Rust
// expect: run
|
|
// result: 42
|
|
// fuel: 2000000
|
|
// phase: 6
|
|
// spec: docs/spec/16-standard-library.md §2.12
|
|
module test.hash
|
|
import std.hash;
|
|
|
|
fn fixture(data: slice<u8>, fnv: u64, crc: u32, extended_fnv: u64, extended_crc: u32) -> void effects [] {
|
|
assert(std.hash.fnv1a64(data) == fnv);
|
|
assert(std.hash.crc32c(data) == crc);
|
|
assert(std.hash.fnv1a64_extend(0xffffffffffffffffu64, data) == extended_fnv);
|
|
assert(std.hash.crc32c_extend(0x12345678u32, data) == extended_crc);
|
|
}
|
|
fn main() -> u64 effects [] {
|
|
var empty: [u8; 1] = zero;
|
|
fixture(ref empty[0..0], 0xcbf29ce484222325u64, 0x00000000u32, 0xffffffffffffffffu64, 0x12345678u32);
|
|
fixture(ref b"\x61", 0xaf63dc4c8601ec8cu64, 0xc1d04330u32, 0xffff9dffffff597au64, 0x3a837ba4u32);
|
|
fixture(ref b"\x66\x6f\x6f\x62\x61\x72", 0x85944171f73967e8u64, 0x0d5f5c7fu32, 0x84b5fbfdea9d3fc6u64, 0x741fe86fu32);
|
|
fixture(ref b"\x48\x65\x6c\x6c\x6f\x21\x01\xff\xed", 0xbd51ea7094ee6fa1u64, 0x49651a38u32, 0x7b119b056ee0c82fu64, 0x8dbbf3d1u32);
|
|
fixture(ref b"\x31\x32\x33\x34\x35\x36\x37\x38\x39", 0x06d5573923c6cdfcu64, 0xe3069283u32, 0x7d1c37bcffcdcb42u64, 0x27d87b6au32);
|
|
fixture(ref b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 0x0c8210784d8af5a5u64, 0x8a9136aau32, 0xfaa74d195d09bf7fu64, 0x90c2769du32);
|
|
fixture(ref b"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 0x9ac5e12119fd3f85u64, 0x62a8ab43u32, 0x62c2a7593aa53b5fu64, 0x78fbeb74u32);
|
|
fixture(ref b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 0xe6cb594c1a148ac5u64, 0x46dd794eu32, 0xc3af98b6b870ba7fu64, 0x5c8e3979u32);
|
|
fixture(ref b"\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 0x1996adfc65ca0fe5u64, 0x113fdb5cu32, 0xa4c71b3c7cc556dfu64, 0x0b6c9b6bu32);
|
|
fixture(ref b"\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 0x604415443fea059au64, 0xd9963a56u32, 0x137db44d06632ba8u64, 0xa3572cccu32);
|
|
return 42;
|
|
}
|