Top Description Inners Fields Constructors Methods
com.carrotsearch.hppc

public Class ShortArrayList

extends AbstractShortCollection
implements ShortIndexedContainer, Preallocable, Cloneable, Accountable
Class Inheritance
All Implemented Interfaces
com.carrotsearch.hppc.Accountable, java.lang.Cloneable, com.carrotsearch.hppc.Preallocable, com.carrotsearch.hppc.ShortIndexedContainer, java.util.RandomAccess, com.carrotsearch.hppc.ShortCollection, com.carrotsearch.hppc.ShortContainer, java.lang.Iterable
Known Direct Subclasses
com.carrotsearch.hppc.ShortStack
Annotations
@Generated:KTypeArrayList.java
date:2024-06-04T15:20:17+0200
Static Imports
com.carrotsearch.hppc.Containers.*

An array-backed list of shorts.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
public short[]
buffer

Internal array for storing the list.

private static final BoundedProportionalArraySizingStrategy
DEFAULT_SIZING_STRATEGY

Reuse the same strategy instance.

public int
elementsCount

Current number of elements stored in buffer.

public static final short[]
EMPTY_ARRAY

An immutable empty buffer (array).

protected final ArraySizingStrategy
resizer

Buffer resizing strategy.

Constructor Summary

AccessConstructor and Description
public
ShortArrayList()

New instance with sane defaults.

public
ShortArrayList(int
The expected number of elements guaranteed not to cause buffer expansion (inclusive).
expectedElements
)

New instance with sane defaults.

public
ShortArrayList(int
The expected number of elements guaranteed not to cause buffer expansion (inclusive).
expectedElements
,
ArraySizingStrategy
Underlying buffer sizing strategy.
resizer
)

New instance with sane defaults.

public
ShortArrayList(ShortContainer container)

Creates a new list from the elements of another container in its iteration order.

Method Summary

Modifier and TypeMethod and Description
public void
add(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.add.

Adds an element to the end of this container (the last index is incremented by one).

public void
add(short e1, short e2)

Appends two elements at the end of the list.

public void
add(short[] elements, int start, int length)

Add all elements from a range of given array to the list.

public final void
add(short... elements)

Vararg-signature method for adding elements at the end of the list.

public int
addAll(ShortContainer container)

Adds all elements from another container.

public int
addAll(Iterable<? extends ShortCursor> iterable)

Adds all elements from another iterable.

public void
clear()

Implements com.carrotsearch.hppc.ShortCollection.clear.

Sets the number of stored elements to zero.

public ShortArrayList
clone()

Overrides java.lang.Object.clone.

Clone this object.

public boolean
contains(short e1)

Implements com.carrotsearch.hppc.ShortContainer.contains.

Lookup a given element in the container.

protected void
ensureBufferSpace(int expectedAdditions)

Ensures the internal buffer has enough free slots to store expectedAdditions.

public void
ensureCapacity(int
The total number of elements, inclusive.
expectedElements
)

Implements com.carrotsearch.hppc.Preallocable.ensureCapacity.

Ensure this container can hold at least the given number of elements without resizing its buffers.

protected boolean
equalElements(ShortArrayList other)

Compare index-aligned elements against another ShortIndexedContainer.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Returns true only if the other object is an instance of the same class and with the same elements.

public <T extends ShortProcedure> T
forEach(T procedure)

Implements com.carrotsearch.hppc.ShortContainer.forEach, com.carrotsearch.hppc.ShortContainer.forEach.

Applies a procedure to all container elements.

public <T extends ShortProcedure> T
forEach(T procedure, int fromIndex, final int toIndex)

Applies procedure to a slice of the list, fromIndex, inclusive, to toIndex, exclusive.

public <T extends ShortPredicate> T
forEach(T predicate)

Implements com.carrotsearch.hppc.ShortContainer.forEach, com.carrotsearch.hppc.ShortContainer.forEach.

Applies a procedure to all container elements.

public <T extends ShortPredicate> T
forEach(T predicate, int fromIndex, final int toIndex)

Applies predicate to a slice of the list, fromIndex, inclusive, to toIndex, exclusive, or until predicate returns false.

public static ShortArrayList
from(short... elements)

Create a list from a variable number of arguments or an array of short.

public short
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int
indexOf(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

public void
insert(int
The index at which the element should be inserted, shifting any existing and subsequent elements to the right.
index
,
short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.insert.

Inserts the specified element at the specified position in this list.

public boolean
isEmpty()

Implements com.carrotsearch.hppc.ShortContainer.isEmpty.

Shortcut for size() == 0.

public Iterator<ShortCursor>
iterator()

Implements com.carrotsearch.hppc.ShortContainer.iterator.

Returns an iterator to a cursor traversing the collection.

public int
lastIndexOf(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

public long
public long
ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

public void
release()

Implements com.carrotsearch.hppc.ShortCollection.release.

Sets the number of stored elements to zero and releases the internal storage array.

public int
removeAll(short
Element to be removed from this collection, if present.
e1
)

Implements com.carrotsearch.hppc.ShortCollection.removeAll.

Removes all occurrences of e from this collection.

public int
removeAll(ShortPredicate predicate)

Implements com.carrotsearch.hppc.ShortCollection.removeAll.

Removes all elements in this collection for which the given predicate returns true .

public short
removeAt(int index)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeAt.

Removes the element at the specified position in this container and returns it.

public boolean
removeElement(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeElement.

Removes the first element that equals e1, returning whether an element has been removed.

public int
removeFirst(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeFirst.

Removes the first element that equals e1, returning its deleted position or -1 if the element was not found.

public short
removeLast()

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Removes and returns the last element of this container.

public int
removeLast(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Removes the last element that equals e1, returning its deleted position or -1 if the element was not found.

public void
removeRange(int fromIndex, int toIndex)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeRange.

Removes from this container all of the elements with indexes between fromIndex, inclusive, and toIndex, exclusive.

public void
resize(int newSize)

Truncate or expand the list to the new size.

public ShortIndexedContainer
reverse()

Implements com.carrotsearch.hppc.ShortIndexedContainer.reverse.

Reverses the elements in this container and returns this container.

public short
set(int index, short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.set.

Replaces the element at the specified position in this list with the specified element.

public int
size()

Implements com.carrotsearch.hppc.ShortContainer.size.

Return the current number of elements in this container.

public ShortIndexedContainer
sort()

Implements com.carrotsearch.hppc.ShortIndexedContainer.sort.

Sorts the elements in this container and returns this container.

public short[]
toArray()

Overrides com.carrotsearch.hppc.AbstractShortCollection.toArray.

Implements com.carrotsearch.hppc.ShortContainer.toArray.

Copies all elements of this container to an array.

public void
trimToSize()

Trim the internal buffer to the current size.

Inherited from com.carrotsearch.hppc.AbstractShortCollection:
removeAllretainAllretainAlltoString

Field Detail

bufferback to summary
public short[] buffer

Internal array for storing the list. The array may be larger than the current size (size()).

DEFAULT_SIZING_STRATEGYback to summary
private static final BoundedProportionalArraySizingStrategy DEFAULT_SIZING_STRATEGY

Reuse the same strategy instance.

elementsCountback to summary
public int elementsCount

Current number of elements stored in buffer.

EMPTY_ARRAYback to summary
public static final short[] EMPTY_ARRAY

An immutable empty buffer (array).

resizerback to summary
protected final ArraySizingStrategy resizer

Buffer resizing strategy.

Constructor Detail

ShortArrayListback to summary
public ShortArrayList()

New instance with sane defaults.

ShortArrayListback to summary
public ShortArrayList(int expectedElements)

New instance with sane defaults.

Parameters
expectedElements:int

The expected number of elements guaranteed not to cause buffer expansion (inclusive).

ShortArrayListback to summary
public ShortArrayList(int expectedElements, ArraySizingStrategy resizer)

New instance with sane defaults.

Parameters
expectedElements:int

The expected number of elements guaranteed not to cause buffer expansion (inclusive).

resizer:ArraySizingStrategy

Underlying buffer sizing strategy.

ShortArrayListback to summary
public ShortArrayList(ShortContainer container)

Creates a new list from the elements of another container in its iteration order.

Method Detail

addback to summary
public void add(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.add.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.add.

Adds an element to the end of this container (the last index is incremented by one).

Annotations
@Override
addback to summary
public void add(short e1, short e2)

Appends two elements at the end of the list. To add more than two elements, use add (vararg-version) or access the buffer directly (tight loop).

addback to summary
public void add(short[] elements, int start, int length)

Add all elements from a range of given array to the list.

addback to summary
public final void add(short... 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)

addAllback to summary
public int addAll(ShortContainer container)

Adds all elements from another container.

addAllback to summary
public int addAll(Iterable<? extends ShortCursor> iterable)

Adds all elements from another iterable.

clearback to summary
public void clear()

Implements com.carrotsearch.hppc.ShortCollection.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 the elementsCount field to zero.

Annotations
@Override
cloneback to summary
public ShortArrayList clone()

Overrides java.lang.Object.clone.

Clone this object. The returned clone will reuse the same hash function and array resizing strategy.

Returns:ShortArrayList

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
containsback to summary
public boolean contains(short e1)

Implements com.carrotsearch.hppc.ShortContainer.contains.

Doc from com.carrotsearch.hppc.ShortContainer.contains.

Lookup a given element in the container. This operation has no speed guarantees (may be linear with respect to the size of this container).

Returns:boolean

Returns true if this container has an element equal to e.

Annotations
@Override
ensureBufferSpaceback to summary
protected void ensureBufferSpace(int expectedAdditions)

Ensures the internal buffer has enough free slots to store expectedAdditions. Increases internal buffer size if needed.

ensureCapacityback to summary
public void ensureCapacity(int expectedElements)

Implements com.carrotsearch.hppc.Preallocable.ensureCapacity.

Ensure this container can hold at least the given number of elements without resizing its buffers.

Parameters
expectedElements:int

The total number of elements, inclusive.

Annotations
@Override
equalElementsback to summary
protected boolean equalElements(ShortArrayList other)

Compare index-aligned elements against another ShortIndexedContainer.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Returns true only if the other object is an instance of the same class and with the same elements.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
forEachback to summary
public <T extends ShortProcedure> T forEach(T procedure)

Implements com.carrotsearch.hppc.ShortContainer.forEach, com.carrotsearch.hppc.ShortContainer.forEach.

Doc from com.carrotsearch.hppc.ShortContainer.forEach.

Applies a procedure to all container elements. Returns the argument (any subclass of ShortProcedure. This lets the caller to call methods of the argument by chaining the call (even if the argument is an anonymous type) to retrieve computed values, for example (IntContainer):

int count = container.forEach(new IntProcedure() {
  int count; // this is a field declaration in an anonymous class.

  public void apply(int value) {
    count++;
  }
}).count;
Annotations
@Override
forEachback to summary
public <T extends ShortProcedure> T forEach(T procedure, int fromIndex, final int toIndex)

Applies procedure to a slice of the list, fromIndex, inclusive, to toIndex, exclusive.

forEachback to summary
public <T extends ShortPredicate> T forEach(T predicate)

Implements com.carrotsearch.hppc.ShortContainer.forEach, com.carrotsearch.hppc.ShortContainer.forEach.

Doc from com.carrotsearch.hppc.ShortContainer.forEach.

Applies a procedure to all container elements. Returns the argument (any subclass of ShortProcedure. This lets the caller to call methods of the argument by chaining the call (even if the argument is an anonymous type) to retrieve computed values, for example (IntContainer):

int count = container.forEach(new IntProcedure() {
  int count; // this is a field declaration in an anonymous class.

  public void apply(int value) {
    count++;
  }
}).count;
Annotations
@Override
forEachback to summary
public <T extends ShortPredicate> T forEach(T predicate, int fromIndex, final int toIndex)

Applies predicate to a slice of the list, fromIndex, inclusive, to toIndex, exclusive, or until predicate returns false.

fromback to summary
public static ShortArrayList from(short... elements)

Create a list from a variable number of arguments or an array of short. The elements are copied from the argument to the internal buffer.

getback to summary
public short get(int index)

Implements com.carrotsearch.hppc.ShortIndexedContainer.get.

Returns:short

Doc from com.carrotsearch.hppc.ShortIndexedContainer.get.

Returns the element at index index from the list.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
indexOfback to summary
public int indexOf(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.indexOf.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Annotations
@Override
insertback to summary
public void insert(int index, short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.insert.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.insert.

Inserts the specified element at the specified position in this list.

Parameters
index:int

The index at which the element should be inserted, shifting any existing and subsequent elements to the right.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements com.carrotsearch.hppc.ShortContainer.isEmpty.

Doc from com.carrotsearch.hppc.ShortContainer.isEmpty.

Shortcut for size() == 0.

Annotations
@Override
iteratorback to summary
public Iterator<ShortCursor> iterator()

Implements com.carrotsearch.hppc.ShortContainer.iterator.

Doc from com.carrotsearch.hppc.ShortContainer.iterator.

Returns an iterator to a cursor traversing the collection. The order of traversal is not defined. More than one cursor may be active at a time. The behavior of iterators is undefined if structural changes are made to the underlying collection.

The iterator is implemented as a cursor and it returns the same cursor instance on every call to Iterator#next() (to avoid boxing of primitive types). To read the current list's value (or index in the list) use the cursor's public fields. An example is shown below.

for (ShortCursor<short> c : container) {
  System.out.println("index=" + c.index + " value=" + c.value);
}
Returns:Iterator<ShortCursor>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.lastIndexOf.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

Annotations
@Override
ramBytesAllocatedback to summary
public long ramBytesAllocated()

Implements com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Doc from com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Allocated memory estimation

Returns:long

Ram allocated in bytes

Annotations
@Override
ramBytesUsedback to summary
public long ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Doc from com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

Returns:long

Ram used in bytes

Annotations
@Override
releaseback to summary
public void release()

Implements com.carrotsearch.hppc.ShortCollection.release.

Sets the number of stored elements to zero and releases the internal storage array.

Annotations
@Override
removeAllback to summary
public int removeAll(short e1)

Implements com.carrotsearch.hppc.ShortCollection.removeAll.

Doc from com.carrotsearch.hppc.ShortCollection.removeAll.

Removes all occurrences of e from this collection.

Parameters
e1:short

Element to be removed from this collection, if present.

Returns:int

The number of removed elements as a result of this call.

Annotations
@Override
removeAllback to summary
public int removeAll(ShortPredicate predicate)

Implements com.carrotsearch.hppc.ShortCollection.removeAll.

Doc from com.carrotsearch.hppc.ShortCollection.removeAll.

Removes all elements in this collection for which the given predicate returns true .

Returns:int

Returns the number of removed elements.

Annotations
@Override
removeAtback to summary
public short removeAt(int index)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeAt.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeAt.

Removes the element at the specified position in this container and returns it.

Annotations
@Override
removeElementback to summary
public boolean removeElement(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeElement.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeElement.

Removes the first element that equals e1, returning whether an element has been removed.

Annotations
@Override
removeFirstback to summary
public int removeFirst(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeFirst.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeFirst.

Removes the first element that equals e1, returning its deleted position or -1 if the element was not found.

Annotations
@Override
removeLastback to summary
public short removeLast()

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Removes and returns the last element of this container. This container must not be empty.

Annotations
@Override
removeLastback to summary
public int removeLast(short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeLast.

Removes the last element that equals e1, returning its deleted position or -1 if the element was not found.

Annotations
@Override
removeRangeback to summary
public void removeRange(int fromIndex, int toIndex)

Implements com.carrotsearch.hppc.ShortIndexedContainer.removeRange.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.removeRange.

Removes from this container all of the elements with indexes between fromIndex, inclusive, and toIndex, exclusive.

Annotations
@Override
resizeback to summary
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 (use trimToSize() 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 or null values).

reverseback to summary
public ShortIndexedContainer reverse()

Implements com.carrotsearch.hppc.ShortIndexedContainer.reverse.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.reverse.

Reverses the elements in this container and returns this container.

Annotations
@Override
setback to summary
public short set(int index, short e1)

Implements com.carrotsearch.hppc.ShortIndexedContainer.set.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.set.

Replaces the element at the specified position in this list with the specified element.

Returns:short

Returns the previous value in the list.

Annotations
@Override
sizeback to summary
public int size()

Implements com.carrotsearch.hppc.ShortContainer.size.

Doc from com.carrotsearch.hppc.ShortContainer.size.

Return the current number of elements in this container. The time for calculating the container's size may take O(n) time, although implementing classes should try to maintain the current size and return in constant time.

Annotations
@Override
sortback to summary
public ShortIndexedContainer sort()

Implements com.carrotsearch.hppc.ShortIndexedContainer.sort.

Doc from com.carrotsearch.hppc.ShortIndexedContainer.sort.

Sorts the elements in this container and returns this container.

Annotations
@Override
toArrayback to summary
public short[] toArray()

Overrides com.carrotsearch.hppc.AbstractShortCollection.toArray.

Implements com.carrotsearch.hppc.ShortContainer.toArray.

Doc from com.carrotsearch.hppc.ShortContainer.toArray.

Copies all elements of this container to an array.

The returned array is always a copy, regardless of the storage used by the container.

The returned array is sized to match exactly the number of elements of the stack.

Annotations
@Override
trimToSizeback to summary
public void trimToSize()

Trim the internal buffer to the current size.

com.carrotsearch.hppc back to summary

pack-priv final Class ShortArrayList.ValueIterator

extends AbstractIterator<ShortCursor>
Class Inheritance

An iterator implementation for ShortArrayList#iterator.

Field Summary

Modifier and TypeField and Description
private final short[]
private final ShortCursor
private final int

Constructor Summary

AccessConstructor and Description
public
ValueIterator(short[] buffer, int size)

Method Summary

Modifier and TypeMethod and Description
protected ShortCursor
fetch()

Implements abstract com.carrotsearch.hppc.AbstractIterator.fetch.

Fetch next element.

Inherited from com.carrotsearch.hppc.AbstractIterator:
donehasNextnextremove

Field Detail

bufferback to summary
private final short[] buffer
cursorback to summary
private final ShortCursor cursor
sizeback to summary
private final int size

Constructor Detail

ValueIteratorback to summary
public ValueIterator(short[] buffer, int size)

Method Detail

fetchback to summary
protected ShortCursor fetch()

Implements abstract com.carrotsearch.hppc.AbstractIterator.fetch.

Doc from com.carrotsearch.hppc.AbstractIterator.fetch.

Fetch next element. The implementation must return done() when all elements have been fetched.

Returns:ShortCursor

Returns the next value for the iterator or chain-calls done().

Annotations
@Override