Some checks are pending
docs / build-and-deploy (push) Waiting to run
Add `long`, a 64-bit signed integer primitive (i64), threaded through codegen: llty; int<->long coercion (coerce_code/to_long) at let/assign/ return/call-args; i64 arithmetic + comparison promotion in emit_bin; unary negate/~; print via %lld and str()/interpolation via @fn_long_str. Editor vocabulary (syntax header, TextMate grammar, formatter, LSP) synced; check-vocabulary green. Numeric literals stay i32 — build large values by widening (documented on the type page). Complete the Hash.* namespace (issue #17) with both 32- and 64-bit algorithms: Hash.of/fnv1a/crc32/mix/combine (32-bit) and Hash.of64/fnv1a_64/mix64 (64-bit, returning long). Deterministic and C-free; CRC-32 (poly 0xEDB88320) and FNV vectors verified against reference implementations. Tests: selfhost/tests/{hash,long}.ludic. Docs: docs/language/hash/*, type-long.md. Seed reseeded; C-free bootstrap fixpoint holds; 23 selfhost + 45 regression + 29 tooling checks green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
26 lines
1 KiB
Markdown
26 lines
1 KiB
Markdown
---
|
|
id: hash-fnv1a
|
|
name: Hash.fnv1a
|
|
category: hash
|
|
kind: namespace-method
|
|
tokens: Hash.fnv1a
|
|
sig: Hash.fnv1a(s) -> int
|
|
tip: FNV-1a 32-bit, named explicitly.
|
|
order: 2
|
|
ns: Hash
|
|
member: fnv1a
|
|
---
|
|
|
|
The <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function">FNV-1a</a> hash of a string's bytes, as an explicit 32-bit algorithm. It starts from the standard offset basis <code>0x811c9dc5</code> and, for each byte, XORs the byte in and multiplies by the FNV prime <code>0x01000193</code>. Small, allocation-free, and well-distributed for short strings — ideal for map keys and content ids. This is the same function <a href="hash-of"><code>Hash.of</code></a> currently delegates to; call <code>Hash.fnv1a</code> when you want to pin the algorithm by name so the value stays fixed even if the default changes.
|
|
|
|
Parameters:
|
|
- `s` — the string to hash
|
|
|
|
```ludic
|
|
program Fnv {
|
|
entry {
|
|
print(Hash.fnv1a("")) # the empty string -> the offset basis
|
|
print(Hash.fnv1a("grass_tile"))
|
|
}
|
|
}
|
|
```
|