Skip to main content

hash_map_backing_bytes

Function hash_map_backing_bytes 

Source
fn hash_map_backing_bytes(capacity: usize) -> usize
Expand description

Conservative backing estimate for Rust 1.98.1’s insert-only HashMap (hashbrown 0.17.1). Bucket count follows its 7/8 load factor; entries, one control byte per bucket and the 16-byte control-group tail are counted. This models requested table storage, not allocator slack. An upper bound on the bytes the group index holds for capacity entries.

The table keeps its entries in a power-of-two number of buckets below 16/7 of the usable capacity, with one control byte beside each bucket. Three buckets per entry therefore covers the table whatever exact growth the map uses, which is what keeps this a bound rather than a model of one implementation: a toolchain that changes how the map grows cannot make it under-count.