3 ms·
The standard library shouldn’t optimize for the case that somebody is using a lot of empty sets. This more indicates to me that there is a design problem.
by Ididntdothis 7y ago
The standard library shouldn’t optimize for the case that somebody is using a lot of empty sets. This more indicates to me that there is a design problem.
- asveikau 7y agoI didn't have Java figured for this much, but I know there are a lot of languages where it's idiomatic to have lots of small hash tables. It is reasonable for a standard library to not make that case suffer too much.
- Ididntdothis 7y agoSmall is fine but empty would be a bad default in my view.
- asveikau 7y agoBut isn't resizing from 0 to n pretty much the same as allocating a fresh one of size n? (Not talking about the typical "resizing for n inserts one-at-a-time" approach, just going from zero to something.) I mean, you have conditionals in the insert instead of unconditional allocation at the start, so maybe a little worse for things like branch predictors, but ...
- Ididntdothis 7y agoYou have a point there. In sum you would probably get the same performance. The only difference would be that the first insert would be slower vs the constructor as it is now.