Std.MultiKeyMap.MultiKeyMap
1 declaration
type
MultiKeyMapThis declaration introduces a public type.
What it does
A map keyed by two things, which can also be asked about either one alone.
The composite key by itself is not why this exists: Map[(A, B), V] already
works, because the runtime's order handles tuples, and a caller wanting only
"the value under this pair" should write that and stop here.
What a pair-keyed Map cannot do is answer about part of the key. Every
permission for one user, whatever the resource; every reading from one
sensor, whatever the hour; every override for one environment, whatever the
setting. Against Map[(A, B), V] each of those reads every entry and throws
most of them away, and the map gets slower at exactly the rate the data
grows.
So this keeps two indexes beside the entries — one grouping the pairs by
their first part, one by their second — and a partial lookup reads the group
it wants instead of the whole map. That is the cost too: three structures
updated on every write, in exchange for the two questions. A caller who never
asks a partial question is paying for indexes they do not read, and should
use a pair-keyed Map instead. This is written on the module because it is
the whole decision of whether to reach for it.
Read the signature
- This declaration has no value signature because it introduces a type or trait.
