addAll for a collection of LongLists
The benefit is, that we only need one memory allocation.
This commit is contained in:
@@ -2,6 +2,7 @@ package org.lucares.collections;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Spliterator.OfLong;
|
import java.util.Spliterator.OfLong;
|
||||||
@@ -380,6 +381,21 @@ public final class LongList implements Serializable, Cloneable {
|
|||||||
size += list.size();
|
size += list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all values of the given lists.
|
||||||
|
*
|
||||||
|
* @param longLists collection of the lists
|
||||||
|
* @throws NullPointerException if the collection of {@link LongList} is null or
|
||||||
|
* contains null
|
||||||
|
*/
|
||||||
|
public void addAll(final Collection<LongList> longLists) {
|
||||||
|
final int sizeNewElements = longLists.stream().mapToInt(LongList::size).sum();
|
||||||
|
ensureCapacity(sizeNewElements);
|
||||||
|
for (final LongList longList : longLists) {
|
||||||
|
addAll(longList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes elements from the list.
|
* Removes elements from the list.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
Reference in New Issue
Block a user