Expand description
Bit-packed integer keys for multi-index maps. Bit-packed integer keys for multi-index maps.
A [FlatIndexer] turns a multi-index over fixed local dimensions into a
single integer key suitable for hashing. Dimension i occupies
ceil(log2(d_i)) bits at a fixed offset, so encoding is shift-and-OR with
no multiplication, and two multi-indices collide only if they are equal.
Widths up to 512 bits use fixed-width fast paths; wider index spaces fall back to a limb-backed representation with the same semantics.
The ladder stops at 512 bits because that is where a fixed-width bignum
stops paying. Measured per-dimension encode cost is 2.12 ns at U256 and
2.86 ns at U512 against 2.52–2.71 ns for limbs, while a U1024 arm cost
6.02 ns — 2.3x the limb path at the same width. A generic shift over
sixteen digits touches every digit for each component, whereas a limb write
touches the one or two the component actually spans.
These figures only hold with the placement helpers inlined; see fixed for
why that attribute is load-bearing.
Structs§
- Flat
Indexer - Encodes multi-indices over fixed local dimensions as
IndexKeyvalues. - Index
Key - A bit-packed multi-index key.
- KeyBuilder
- Assembles one key by appending sub-keys at successive bit offsets.
Enums§
- Index
KeyError - Failures from index-key construction and encoding.
Functions§
- dimension_
bits - Number of bits needed to represent the values
0..dim. - total_
bits - Total bit width of the bit-packed key for
local_dims.