Skip to main content

Module index_key

Module index_key 

Source
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§

FlatIndexer
Encodes multi-indices over fixed local dimensions as IndexKey values.
IndexKey
A bit-packed multi-index key.
KeyBuilder
Assembles one key by appending sub-keys at successive bit offsets.

Enums§

IndexKeyError
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.