Package org.apache.lucene.internal.hppc
Class LongArrayList
- java.lang.Object
-
- org.apache.lucene.internal.hppc.LongArrayList
-
- All Implemented Interfaces:
Cloneable
,Iterable<LongCursor>
,Accountable
public class LongArrayList extends Object implements Iterable<LongCursor>, Cloneable, Accountable
An array-backed list oflong
.Mostly forked and trimmed from com.carrotsearch.hppc.LongArrayList
github: https://github.com/carrotsearch/hppc release 0.10.0
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description long[]
buffer
Internal array for storing the list.int
elementsCount
Current number of elements stored inbuffer
.static long[]
EMPTY_ARRAY
An immutable empty buffer (array).-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description LongArrayList()
New instance with sane defaults.LongArrayList(int expectedElements)
New instance with sane defaults.LongArrayList(LongArrayList list)
Creates a new list from the elements of another list in its iteration order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(long e1)
void
add(long... elements)
Vararg-signature method for adding elements at the end of the list.void
add(long[] elements, int start, int length)
Add all elements from a range of given array to the list.int
addAll(Iterable<? extends LongCursor> iterable)
Adds all elements from another iterable.int
addAll(LongArrayList list)
Adds all elements from another list.void
clear()
Sets the number of stored elements to zero.LongArrayList
clone()
Clone this object.boolean
contains(long e1)
protected void
ensureBufferSpace(int expectedAdditions)
Ensures the internal buffer has enough free slots to storeexpectedAdditions
.void
ensureCapacity(int expectedElements)
Ensure this container can hold at least the given number of elements without resizing its buffers.protected boolean
equalElements(LongArrayList other)
Compare index-aligned elements against anotherLongArrayList
.boolean
equals(Object obj)
Returnstrue
only if the other object is an instance of the same class and with the same elements.static LongArrayList
from(long... elements)
Create a list from a variable number of arguments or an array ofint
.long
get(int index)
int
hashCode()
int
indexOf(long e1)
void
insert(int index, long e1)
boolean
isEmpty()
Iterator<LongCursor>
iterator()
int
lastIndexOf(long e1)
long
ramBytesUsed()
Return the memory usage of this object in bytes.void
release()
Sets the number of stored elements to zero and releases the internal storage array.int
removeAll(long e)
Removes all occurrences ofe
from this collection.long
removeAt(int index)
Removes the element at the specified position in this container and returns it.boolean
removeElement(long e)
Removes the first element that equalse
, returning whether an element has been removed.int
removeFirst(long e1)
Removes the first element that equalse1
, returning its deleted position or-1
if the element was not found.long
removeLast()
Removes and returns the last element of this list.int
removeLast(long e1)
Removes the last element that equalse1
, returning its deleted position or-1
if the element was not found.void
removeRange(int fromIndex, int toIndex)
Removes from this list all the elements with indexes betweenfromIndex
, inclusive, andtoIndex
, exclusive.void
resize(int newSize)
Truncate or expand the list to the new size.LongArrayList
reverse()
Reverses the elements in this list and returns this list.long
set(int index, long e1)
int
size()
LongArrayList
sort()
Sorts the elements in this list and returns this list.LongStream
stream()
Returns a stream of all the elements contained in this list.long[]
toArray()
The returned array is sized to match exactly the number of elements of the stack.String
toString()
Convert the contents of this list to a human-friendly string.void
trimToSize()
Trim the internal buffer to the current size.-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final long[] EMPTY_ARRAY
An immutable empty buffer (array).
-
buffer
public long[] buffer
Internal array for storing the list. The array may be larger than the current size (size()
).
-
elementsCount
public int elementsCount
Current number of elements stored inbuffer
.
-
-
Constructor Detail
-
LongArrayList
public LongArrayList()
New instance with sane defaults.
-
LongArrayList
public LongArrayList(int expectedElements)
New instance with sane defaults.- Parameters:
expectedElements
- The expected number of elements guaranteed not to cause buffer expansion (inclusive).
-
LongArrayList
public LongArrayList(LongArrayList list)
Creates a new list from the elements of another list in its iteration order.
-
-
Method Detail
-
add
public void add(long e1)
-
add
public void add(long[] elements, int start, int length)
Add all elements from a range of given array to the list.
-
add
public final void add(long... elements)
Vararg-signature method for adding elements at the end of the list.This method is handy, but costly if used in tight loops (anonymous array passing)
-
addAll
public int addAll(LongArrayList list)
Adds all elements from another list.
-
addAll
public int addAll(Iterable<? extends LongCursor> iterable)
Adds all elements from another iterable.
-
insert
public void insert(int index, long e1)
-
get
public long get(int index)
-
set
public long set(int index, long e1)
-
removeAt
public long removeAt(int index)
Removes the element at the specified position in this container and returns it.
-
removeLast
public long removeLast()
Removes and returns the last element of this list.
-
removeRange
public void removeRange(int fromIndex, int toIndex)
Removes from this list all the elements with indexes betweenfromIndex
, inclusive, andtoIndex
, exclusive.
-
removeElement
public boolean removeElement(long e)
Removes the first element that equalse
, returning whether an element has been removed.
-
removeFirst
public int removeFirst(long e1)
Removes the first element that equalse1
, returning its deleted position or-1
if the element was not found.
-
removeLast
public int removeLast(long e1)
Removes the last element that equalse1
, returning its deleted position or-1
if the element was not found.
-
removeAll
public int removeAll(long e)
Removes all occurrences ofe
from this collection.- Parameters:
e
- Element to be removed from this collection, if present.- Returns:
- The number of removed elements as a result of this call.
-
contains
public boolean contains(long e1)
-
indexOf
public int indexOf(long e1)
-
lastIndexOf
public int lastIndexOf(long e1)
-
isEmpty
public boolean isEmpty()
-
ensureCapacity
public void ensureCapacity(int expectedElements)
Ensure this container can hold at least the given number of elements without resizing its buffers.- Parameters:
expectedElements
- The total number of elements, inclusive.
-
ensureBufferSpace
protected void ensureBufferSpace(int expectedAdditions)
Ensures the internal buffer has enough free slots to storeexpectedAdditions
. Increases internal buffer size if needed.
-
resize
public void resize(int newSize)
Truncate or expand the list to the new size. If the list is truncated, the buffer will not be reallocated (usetrimToSize()
if you need a truncated buffer), but the truncated values will be reset to the default value (zero). If the list is expanded, the elements beyond the current size are initialized with JVM-defaults (zero ornull
values).
-
size
public int size()
-
trimToSize
public void trimToSize()
Trim the internal buffer to the current size.
-
clear
public void clear()
Sets the number of stored elements to zero. Releases and initializes the internal storage array to default values. To clear the list without cleaning the buffer, simply set theelementsCount
field to zero.
-
release
public void release()
Sets the number of stored elements to zero and releases the internal storage array.
-
toArray
public long[] toArray()
The returned array is sized to match exactly the number of elements of the stack.
-
clone
public LongArrayList clone()
Clone this object. The returned clone will reuse the same hash function and array resizing strategy.
-
equals
public boolean equals(Object obj)
Returnstrue
only if the other object is an instance of the same class and with the same elements.
-
equalElements
protected boolean equalElements(LongArrayList other)
Compare index-aligned elements against anotherLongArrayList
.
-
toString
public String toString()
Convert the contents of this list to a human-friendly string.
-
ramBytesUsed
public long ramBytesUsed()
Description copied from interface:Accountable
Return the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsed
in interfaceAccountable
-
stream
public LongStream stream()
Returns a stream of all the elements contained in this list.
-
sort
public LongArrayList sort()
Sorts the elements in this list and returns this list.
-
reverse
public LongArrayList reverse()
Reverses the elements in this list and returns this list.
-
iterator
public Iterator<LongCursor> iterator()
- Specified by:
iterator
in interfaceIterable<LongCursor>
-
from
public static LongArrayList from(long... elements)
Create a list from a variable number of arguments or an array ofint
. The elements are copied from the argument to the internal buffer.
-
-