What is the load factor for `std::collections::HashTable` (and `HashSet`)

I have a hashset where I know ahead the number of elements it will contain. In a vector, I'll just use this capacity. However, hashmaps usually keep some space empty for better performance.

What is the amount of this space in Rust?

I know this should not be relied upon.

1/8.

1 Like

You don't need to manually account for that load factor though. Reserve the amount you actually want, and the implementation will pad that up and also round up to the next power of two.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.