Hi

I used ArrayUtils.getNextSize recently to expand an array to a new size.
When I read the documentation (the inline in the method), I saw this:

"The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ..."

I'm not sure if I'm misunderstanding the comment, or if there is a bug in
the implementation. The way I understand it, the method will always return
0, 4, 8, 16 ... values, such that if I pass 9-15 I'll always get 16. But
then I noticed that if I pass 15, I get back 22 (which is the result of the
computation). Is it a bug?

Also, while on that subject - why don't we return the closest power of 2?
I'm not familiar with that expansion policy, and I don't know how it will
behave for large values. I guess a pure "closest power of 2" is not too good
since for very large values it will return twice the size which is not too
good, but we can have a smarter impl. which checks the value passed and
returns a new number in chunks of let's say 1K, when the passed in number is
very large (let's say 1M).

If you think that's useful, I can open an issue and either change the method
impl, or add a new one getNextPower2Size.

Shai

Reply via email to