Expand description
A hash for keys that are already numbers.
Everything this compiler keys a map by is a small integer or two: a
Span is a pair of byte offsets, a definition is an index
into a table. The standard library hashes with SipHash, which is chosen to
survive an attacker choosing the keys. Nothing here has that problem: the
keys come out of a file the compiler was handed, and a file that could pick
its own spans could do far worse than make a hash map slow.
Measured before it was written, because that is the rule. Reading a name
was the most expensive small thing in the language and it is two lookups,
one from the span where the name is written to what it refers to and one
from that to the value. crates/deed-driver/examples/interpreting.rs says
what a name costs and what it costs now.
The mixing is one multiply and one shift, the same shape as the hash used by every compiler that has had this problem, and it is written out here rather than depended on because it is nine lines.
Structs§
- Number
Hasher - Mixes whatever it is given into one word.
Type Aliases§
- ByNumber
- A
BuildHasherfor maps keyed by numbers.