fastutil icon indicating copy to clipboard operation
fastutil copied to clipboard

Expose OpenHashMap#ensureCapacity

Open TheMode opened this issue 2 years ago • 2 comments

Useful to avoid unnecessary resizing on batch insertion

TheMode avatar Mar 03 '22 03:03 TheMode

Presently you can have a subclass that exposes a method using rehash(), exactly like ensureCapacity() does. putAll() will also try to increase capacity, so you should that for batch insertion.

I don't see particular reasons not to make the method public. Does anybody have a different opinion? @incaseoftrouble @techsy730 ?

vigna avatar Mar 03 '22 15:03 vigna

Presently you can have a subclass that exposes a method using rehash(), exactly like ensureCapacity() does. putAll() will also try to increase capacity, so you should that for batch insertion.

These could work, but far from being convenient in my case: https://github.com/Minestom/Minestom/blob/708307dbdec3671592fdfd3c06b4cd33a1b41cb8/src/main/java/net/minestom/server/ServerProcessImpl.java#L273-L275 as I would also need to make my own lazy Map, which may be counterproductive and add more overhead.

Having the method exposed would definitely be welcome.

TheMode avatar Mar 03 '22 15:03 TheMode

I also need such behaviour. I create the map in one class and in another class, I got collection future size before doing all puts. So I cannot init the class with the right size. Ability to set call ensureCapacity would have help me in this case.

mmadoo avatar Oct 12 '22 12:10 mmadoo

Done in 85bb33b1bfde34dac21005037951b615268f0083. Let me know if it works for you...

vigna avatar Oct 12 '22 12:10 vigna