Why is ObjectArrayList.grow( ) private?

20 views
Skip to first unread message

Ngx QuatreCentSeptanteDeux

unread,
Nov 23, 2020, 6:41:10 AM11/23/20
to fastutil

Hi

 

I don't understand why the ObjectArrayList.grow() method is private

We are facing cases where the default x2 algorithm causes a lot of harm

What is the recipe to control growth()?

From what I understand I have to override add() otherwise private method grow() is called invariably…

But this seems very awkward. Maybe I miss something

 

Thanks

Sebastiano Vigna

unread,
Nov 23, 2020, 11:56:49 AM11/23/20
to fastutil
Il giorno lunedì 23 novembre 2020 alle 12:41:10 UTC+1 ngx...@gmail.com ha scritto:

Hi

 

I don't understand why the ObjectArrayList.grow() method is private

We are facing cases where the default x2 algorithm causes a lot of harm


Frankly, you must have in mind another library--there is no "x2 algorithm" in the current version of fastutil.
 
seba

Ngx QuatreCentSeptanteDeux

unread,
Nov 23, 2020, 12:52:19 PM11/23/20
to fastutil
in version 7.2.0 and even in 8.1 which is the latest available in our corporation, the code of grow() multiplies by two:
final int newLength = (int) Math.max(Math.min(2L * a.length, it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE), capacity);

Has this changed in the latest version?

The doc of static grow() says :
If you want complete control on the array growth, you should probably use ensureCapacity() instead.

Are we supposed to instrument all the code to call ensureCapacity before calling add?
For me, making grow() private looks like a design error
Do you have code snippets which show how one controls the array growth?

Thanks

Sebastiano Vigna

unread,
Nov 23, 2020, 1:49:38 PM11/23/20
to fastutil
Yes, you're using old versions. Years-old versions. Note that java.util.ArrayList does not expose the grow() method, either.
Reply all
Reply to author
Forward
0 new messages