vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.76k stars 196 forks source link

Introduce common interface for fastutil's List #258

Closed xxDark closed 2 years ago

xxDark commented 3 years ago

Hello. I wonder if it is possible to introduce common interface for Lists, that might include:

void getElements(int from, Object a[], int offset, int length);
void removeElements(int from, int to);
void addElements(int index, K a[]);
void addElements(int index, K a[], int offset, int length);

and so on. Thanks in advance.

vigna commented 3 years ago

Those are methods that are very specific to array-based lists. It is however possible to add such methods using default methods. Wanna try a PR?

incaseoftrouble commented 3 years ago

void getElements(int from, Object a[], int offset, int length);

This is equivalent to List.subList(from, from + length) and copying into a, right? (with the minimal overhead of creating a ListView object).

void removeElements(int from, int to);

I propose removeAll(int from, int to) as name (consistency)

void addElements(int index, K a[]);
void addElements(int index, K a[], int offset, int length);

Instead of passing arrays, it would be better to wrap the arrays as a List, Arrays.asList etc. (very cheap, much cheaper than inserting in the middle of an array). Then you can use the standard method addAll(int index, Collection<K> collection). That implementation can then specifically handle arrays lists.

vigna commented 2 years ago

Well, those methods are already in the list interface.