rust-lang / hashbrown

Rust port of Google's SwissTable hash map
https://rust-lang.github.io/hashbrown
Apache License 2.0
2.45k stars 288 forks source link

Predictable size of allocations #589

Closed mrjbom closed 3 hours ago

mrjbom commented 4 hours ago

Is there any way to achieve predictable sizes of allocations that a hashtable can request? I'm in a no_std environment and I don't have the ability to allocate memory of arbitrary size. I can create a set of caches of a certain size, but I need to be able to define these sizes, how can I achieve this?

Amanieu commented 4 hours ago

The crate API makes no guarantees as to the internal layout of the hash table: we are free to change the size/layout of the allocation in future releases.

However if you pin to a specific hashbrown version then you could look at the layout algorithm in src/raw/mod.rs to predict what allocation sizes will be requested for different capacities.