public final class LongArray extends AbstractWritableLongList
AbstractWritableLongList.WritableIndexIterator
AbstractLongList.IndexIterator, AbstractLongList.SubList
LongList.Single
LongCollector.Dummy
DUMMY
Constructor and Description |
---|
LongArray() |
LongArray(int capacity)
Constructs an empty array with the specified initial capacity.
|
LongArray(long[] hostArray)
|
LongArray(long[] hostArray,
int length)
Constructs a LongArray with the specified size
length that is backed by hostArray
See copy(long[]) , create(long...) . |
LongArray(LongIterator iterator)
Constructs a LongArray and add all elements from
iterator |
LongArray(LongList copyFrom)
Constructs a LongArray and adds all elements from
copyFrom |
Modifier and Type | Method and Description |
---|---|
void |
add(long value) |
void |
addAll(long... ints) |
void |
addAll(LongList list) |
void |
addAll(LongSet set) |
int |
addAllNotMore(LongIterable iterable,
int maxCount)
Adds elements from iterable until maxCount elements are added or iterable reaches its end.
|
int |
addAllNotMore(LongList collection,
int maxCount)
Adds first maxCount elements from collection or the whole collection if it size is less than maxCount.
|
void |
clear() |
static LongArray |
copy(long[] array) |
static LongArray |
copy(long[] array,
int length) |
static LongArray |
copy(LongIterable iterable) |
static LongArray |
create(java.util.Collection<java.lang.Long> values)
May be used to convert the collection of
Long to native long[] array:
LongArray.create(values).extractHostArray() . |
static LongArray |
create(long... values) |
void |
ensureCapacity(int expectedCapacity)
Increases the capacity of this LongArray instance, if
necessary, to ensure that it can hold at least the number of elements
specified by
expectedCapacity argument. |
boolean |
equalOrder(long[] array) |
void |
expand(int index,
int count)
Increases the list size and shifts all values to the right of
index . |
long[] |
extractHostArray()
Extracts from this array inner buffer with
long[] values and clears this array. |
long |
get(int index) |
int |
getCapacity() |
int |
getInsertionPoints(LongSizedIterable src,
int[][] points)
Finds positions for inserting elements of sorted
src into
this sorted unique array and writes them to points[0] . |
int |
indexOf(long value)
Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
|
void |
insert(int index,
long value) |
void |
insertAll(int index,
LongList collection,
int sourceIndex,
int count) |
void |
insertMultiple(int index,
long value,
int count)
Insert
value count times between indices index, index + 1 |
protected boolean |
isSorted(boolean checkUnique) |
void |
merge(LongList src)
Merges the specified sorted unique list and this sorted unique array.
|
void |
mergeWithSameLength(LongList src)
Merges the specified sorted unique list into this sorted unique array.
|
void |
mergeWithSmall(LongList src)
Merges the specified sorted list and this sorted array into this sorted unique array.
|
void |
mergeWithSmall(LongList src,
int[][] insertionPoints) |
void |
removeAllAtSorted(IntIterator indices)
Removes from this list all elements whose index is contained in the specified
IntList indices |
void |
removeRange(int from,
int to) |
boolean |
removeSorted(long value)
Removes 1 times
value from this sorted list, if this list contains value . |
void |
retain(LongList values)
removes from this array all of its elements that are not contained in
values |
void |
retainSorted(LongList values)
removes from this array all of its elements that are not contained in
values |
void |
set(int index,
long value) |
void |
setAll(int index,
LongList values,
int sourceIndex,
int count)
Replaces the elements in this list from
index to index + count
with the elements from values beginning from index sourceIndex
and ending with sourceIndex + count |
void |
setRange(int from,
int to,
long value) |
void |
shuffle(java.util.Random random)
Shuffles this array using
random as number generator. |
void |
sort(WritableLongList... sortAlso)
Sorts this list using quicksort copied from
Arrays.sort(int[]) then corrected |
void |
sortUnique()
Sorts this array using
Arrays.sort(int[]) , removes duplicates and updates size. |
void |
swap(int index1,
int index2) |
long[] |
toNativeArray(int sourceOffset,
long[] dest,
int destOffset,
int length)
Writes values to dest.
|
addAll, addSorted, apply, insertAll, insertAll, iterator, iterator, iterator, modCount, modified, remove, removeAll, removeAll, removeAll, removeAllSorted, removeAt, removeDuplicates, removeLast, reverse, setAll, size, update, updateSize, write
binarySearch, binarySearch, contains, equals, equalSortedUniqueValues, get, getLast, getNextDifferentValueIndex, hashCode, isEmpty, isSorted, isSortedUnique, subList, toList, toNativeArray, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
binarySearch, binarySearch, contains, get, getNextDifferentValueIndex, isEmpty, isSorted, isSortedUnique, subList, toList, toNativeArray
public LongArray()
public LongArray(int capacity)
public LongArray(LongList copyFrom)
copyFrom
public LongArray(LongIterator iterator)
iterator
public LongArray(long[] hostArray)
public LongArray(long[] hostArray, int length)
length
that is backed by hostArray
See copy(long[])
, create(long...)
.length
- size of the new array. If length
>= hostArray.length
new size is equal to hostArray.length
otherwise equal to length
.java.lang.IllegalArgumentException
- if length < 0
public static LongArray copy(long[] array)
long[]
arraypublic static LongArray copy(long[] array, int length)
long[]
arraypublic static LongArray copy(@Nullable LongIterable iterable)
iterable
public static LongArray create(long... values)
LongArray(long[])
, LongArray(long[], int)
.public static LongArray create(@Nullable java.util.Collection<java.lang.Long> values)
Long
to native long[] array:
LongArray.create(values).extractHostArray()
.values
public int indexOf(long value)
AbstractLongList
indexOf
in interface LongList
indexOf
in class AbstractLongList
public final long get(int index)
public long[] toNativeArray(int sourceOffset, long[] dest, int destOffset, int length)
LongList
toNativeArray
in interface LongList
toNativeArray
in class AbstractLongList
public void ensureCapacity(int expectedCapacity)
expectedCapacity
argument.expectedCapacity
- the desired minimum capacitypublic int getCapacity()
public void set(int index, long value)
set
in interface WritableLongList
set
in class AbstractWritableLongList
public void setRange(int from, int to, long value)
public void removeRange(int from, int to)
public void clear()
clear
in interface WritableLongList
clear
in class AbstractWritableLongList
public void insertMultiple(int index, long value, int count)
WritableLongList
value
count
times between indices index, index + 1
insertMultiple
in interface WritableLongList
insertMultiple
in class AbstractWritableLongList
public void expand(int index, int count)
WritableLongList
index
. The resulting "hole"
in the range [index; index + count)
contains undefined values.index
- where to insert the "hole"count
- how much size increase is needed, must be >= 0public void insert(int index, long value)
insert
in interface WritableLongList
insert
in class AbstractWritableLongList
public void add(long value)
add
in interface LongCollector
add
in class AbstractWritableLongList
public void insertAll(int index, LongList collection, int sourceIndex, int count)
insertAll
in interface WritableLongList
insertAll
in class AbstractWritableLongList
public void setAll(int index, LongList values, int sourceIndex, int count)
WritableLongList
index
to index + count
with the elements from values
beginning from index sourceIndex
and ending with sourceIndex + count
setAll
in interface WritableLongList
setAll
in class AbstractWritableLongList
public void swap(int index1, int index2)
swap
in interface WritableLongList
swap
in class AbstractWritableLongList
public void addAll(long... ints)
addAll
in interface LongCollector
addAll
in class AbstractWritableLongList
public void sort(WritableLongList... sortAlso)
AbstractWritableLongList
Arrays.sort(int[])
then correctedsort
in interface WritableLongList
sort
in class AbstractWritableLongList
sortAlso
- lists in which the order is changed as well as this listpublic void addAll(LongList list)
addAll
in interface LongCollector
addAll
in class AbstractWritableLongList
public void addAll(LongSet set)
protected boolean isSorted(boolean checkUnique)
isSorted
in class AbstractLongList
public boolean equalOrder(long[] array)
array.length
and all elements
in the specified array equal to corresponding elementspublic void sortUnique()
Arrays.sort(int[])
, removes duplicates and updates size.sortUnique
in interface WritableLongList
sortUnique
in class AbstractWritableLongList
public void retain(LongList values)
values
Complexity: O((M + N) * log(M))
, where N - size()
, M - values.size()
public void retainSorted(LongList values)
values
Complexity: O(N * log(M)
, where N - size()
, M - values.size()
values
- sorted LongList
public int addAllNotMore(LongList collection, int maxCount)
public int addAllNotMore(LongIterable iterable, int maxCount)
public boolean removeSorted(long value)
value
from this sorted list, if this list contains value
.
true
if this set contained value
. Otherwise false
.AbstractWritableLongList.removeAllSorted(long)
public void removeAllAtSorted(IntIterator indices)
IntList indices
Unlike LongCollections.removeAllAtSorted(WritableLongList, IntList)
, which in case of LongArray takes
O(N*M)
time, this method requires just O(N + M)
, where N - size()
, M - indices.size()
.
indices
- sorted IntIterable
LongCollections.removeAllAtSorted(WritableLongList, IntList)
public long[] extractHostArray()
long[]
values and clears this array.public int getInsertionPoints(LongSizedIterable src, int[][] points)
src
into
this sorted unique array and writes them to points[0]
.
points[0][idx]
will be equal to -1
if src.get(idx)
is contained in this array,
otherwise equal to index in this array where inserting src.get(idx)
keeps this array sorted unique.
this | src | return | points[0] |
---|---|---|---|
[0, 2, 4, 7, 9, 10] | [0, 4, 8, 8, 9] | 1 | [-1, -1, 4, -1, -1] |
[0, 2, 4, 7, 9, 10] | [1, 4, 6, 6, 7, 11, 12] | 4 | [1, -1, 3, -1, -1, 6, 6] |
src
- sorted iterablepoints
- container for insertion points array, not null.
If points[0] == null
or points[0].length < src.size()
, a new array will be allocated in points[0]
.
If points[0].length > src.size()
, elements in points[0]
beyond src.size()
will be ignored.src
that are not contained in this array.public void merge(LongList src)
size()
and src.size()
uses
mergeWithSmall(LongList)
or mergeWithSameLength(LongList)
.
If this array is smaller than the specified list,
it will copy the specified list and merge it with existing contents using mergeWithSmall(LongList)
.
public void mergeWithSmall(LongList src)
Merges the specified sorted list and this sorted array into this sorted unique array.
If src
is not sorted or this array is not sorted unique, result is undefined.
src
can contain duplicates.
If getCapacity() < src.size() + size()
, will do reallocation.
Complexity: O(eps(N/T, this, src) * N + T * log(N))
, where N = size()
and T = src.size()
.
eps
grows as N/T
grows.
eps
also depends on how evenly src
values are distributed in this array: it is higher when
they are uniformly distributed.
In the general case, if N/T > 4
, then on average eps < 0.5
.
Prefer to use this method over mergeWithSameLength(LongList)
If src.size()
is much smaller than size()
. If they are close
use mergeWithSameLength(LongList)
src
- sorted list.merge(LongList)
public void mergeWithSmall(LongList src, int[][] insertionPoints)
insertionPoints
- contains temporary array in the first element. If it isn't there,
it will be written theremergeWithSmall(LongList)
public void mergeWithSameLength(LongList src)
getCapacity() < src.size() + size()
, will do reallocation.O(N + T)
, where N = size()
and T = src.size()
.size()
and src.size()
are comparable.
If src.size()
is much smaller than size()
,
it's better to use mergeWithSmall(LongList)
src
- sorted list of numbers (set)public void shuffle(java.util.Random random)
random
as number generator.