This is maybe a generic programming question as opposed to Rust-specific, but since Rust also allows customizing the hasher function…
Use-case is wanting to use u32 as lookup ids, in three different scenarios:
Unpredictable: Hashmap makes sense since allocating a Vec or Array would need to be too huge
Predictable and within low ranges: say storing an attribute location lookup in a shader. Not sure of the exact limit, but let’s say pre-allocating an array of 1024 ints would cover it.
Unpredictable but managable: say using like an Entity Component System where each item has a u32 for an id. These get assigned at runtime - but most likely it can be easily managed with relatively few allocations by growing a Vec by a certain capacity each time, and re-using dead ids (i.e. pooling).
I’m thinking that Hashmap is the right choice for the first scenario, an Array (set to a hard but padded limit like 1024, even if I just need 256) for the second, and Vec with some housekeeping for the third.
However - it might be that there’s a super simple hasher for numbers that makes Hashmap actually the better choice for scenario #3…