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>
29 lines
1 KiB
Markdown
29 lines
1 KiB
Markdown
---
|
|
id: hash-mix
|
|
name: Hash.mix
|
|
category: hash
|
|
kind: namespace-method
|
|
tokens: Hash.mix
|
|
sig: Hash.mix(x) -> int
|
|
tip: Avalanche one integer into a well-scrambled value.
|
|
order: 4
|
|
ns: Hash
|
|
member: mix
|
|
---
|
|
|
|
Scrambles a single integer so its bits are thoroughly mixed — the <a href="https://en.wikipedia.org/wiki/MurmurHash">MurmurHash3</a> <code>fmix32</code> finalizer (shift/multiply/shift). Nearby inputs like <code>0</code>, <code>1</code>, <code>2</code> map to values that look unrelated, which is exactly what you want when turning a counter, entity id, or frame number into a random-looking seed. It is deterministic and self-inverse-free: the same input always gives the same output. <code>Hash.mix(0)</code> is <code>0</code>. For folding several numbers together use <a href="hash-combine"><code>Hash.combine</code></a>.
|
|
|
|
Parameters:
|
|
- `x` — the integer to avalanche
|
|
|
|
```ludic
|
|
program Seeds {
|
|
entry {
|
|
var i = 0
|
|
while i < 4 {
|
|
print(Hash.mix(i)) # consecutive counters -> unrelated-looking seeds
|
|
i = i + 1
|
|
}
|
|
}
|
|
}
|
|
```
|