Package com.carrotsearch.hppc
Class DoubleArrayDeque
java.lang.Object
com.carrotsearch.hppc.AbstractDoubleCollection
com.carrotsearch.hppc.DoubleArrayDeque
- All Implemented Interfaces:
DoubleCollection
,DoubleContainer
,DoubleDeque
,Preallocable
,Cloneable
,Iterable<DoubleCursor>
@Generated(date="2023-09-14T00:00:00+0000",
value="KTypeArrayDeque.java")
public class DoubleArrayDeque
extends AbstractDoubleCollection
implements DoubleDeque, Preallocable, Cloneable
An array-backed
DoubleDeque
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
An iterator implementation forObjectArrayDeque.descendingIterator()
.private final class
An iterator implementation forObjectArrayDeque.iterator()
. -
Field Summary
FieldsModifier and TypeFieldDescriptiondouble[]
Internal array for storing elements of the deque.int
The index of the element at the head of the deque or an arbitrary number equal to tail if the deque is empty.protected final ArraySizingStrategy
Buffer resizing strategy.int
The index at which the next element would be added to the tail of the deque. -
Constructor Summary
ConstructorsConstructorDescriptionNew instance with sane defaults.DoubleArrayDeque
(int expectedElements) New instance with sane defaults.DoubleArrayDeque
(int expectedElements, ArraySizingStrategy resizer) New instance with sane defaults.DoubleArrayDeque
(DoubleContainer container) Creates a new deque from elements of another container, appending elements at the end of the deque in the iteration order. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFirst
(double e1) Inserts the specified element at the front of this deque.final void
addFirst
(double... elements) Vararg-signature method for adding elements at the front of this deque.int
addFirst
(DoubleContainer container) Inserts all elements from the given container to the front of this deque.int
addFirst
(Iterable<? extends DoubleCursor> iterable) Inserts all elements from the given iterable to the front of this deque.void
addLast
(double e1) Inserts the specified element at the end of this deque.final void
addLast
(double... elements) Vararg-signature method for adding elements at the end of this deque.int
addLast
(DoubleContainer container) Inserts all elements from the given container to the end of this deque.int
addLast
(Iterable<? extends DoubleCursor> iterable) Inserts all elements from the given iterable to the end of this deque.int
bufferIndexOf
(double e1) Return the index of the first (counting from head) element equal toe1
.void
clear()
Removes all elements from this collection.clone()
Clone this object.boolean
contains
(double e) Lookup a given element in the container.private void
descendingForEach
(DoublePredicate predicate, int fromIndex, int toIndex) Appliespredicate
to a slice of the deque,toIndex
, exclusive, down tofromIndex
, inclusive or until the predicate returnsfalse
.private void
descendingForEach
(DoubleProcedure procedure, int fromIndex, int toIndex) Appliesprocedure
to a slice of the deque,toIndex
, exclusive, down tofromIndex
, inclusive.<T extends DoubleProcedure>
TdescendingForEach
(T procedure) Appliesprocedure
to all elements of this deque, tail to head.Returns a cursor over the values of this deque (in tail to head order).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
(DoubleArrayDeque other) Compare order-aligned elements against anotherDoubleDeque
.boolean
Returnstrue
only if the other object is an instance of the same class and with the same elements.private void
forEach
(DoubleProcedure procedure, int fromIndex, int toIndex) Appliesprocedure
to a slice of the deque,fromIndex
, inclusive, totoIndex
, exclusive.<T extends DoubleProcedure>
TforEach
(T procedure) Applies aprocedure
to all container elements.static DoubleArrayDeque
from
(double... elements) Create a new deque by pushing a variable number of arguments to the end of it.double
getFirst()
Retrieves the first element of this deque but does not remove it.double
getLast()
Retrieves the last element of this deque but does not remove it.int
hashCode()
boolean
isEmpty()
Shortcut forsize() == 0
.iterator()
Returns a cursor over the values of this deque (in head to tail order).int
lastBufferIndexOf
(double e1) Return the index of the last (counting from tail) element equal toe1
.protected static int
oneLeft
(int index, int modulus) Move one index to the left, wrapping around buffer.protected static int
oneRight
(int index, int modulus) Move one index to the right, wrapping around buffer.void
release()
Release internal buffers of this deque and reallocate with the default buffer.int
removeAll
(double e1) Removes all occurrences ofe
from this collection.int
removeAll
(DoublePredicate predicate) Removes all elements in this collection for which the given predicate returnstrue
.void
removeAtBufferIndex
(int index) Removes the element atindex
in the internal {#linkbuffer
array, returning its value.double
Retrieves and removes the first element of this deque.int
removeFirst
(double e1) Removes the first element that equalse
.double
Retrieves and removes the last element of this deque.int
removeLast
(double e1) Removes the last element that equalse
.int
size()
Return the current number of elements in this container.double[]
toArray()
Default implementation of copying to an array.double[]
toArray
(double[] target) Copies elements of this deque to an array.Methods inherited from class com.carrotsearch.hppc.AbstractDoubleCollection
removeAll, retainAll, retainAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.carrotsearch.hppc.DoubleCollection
removeAll, retainAll, retainAll
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
buffer
public double[] bufferInternal array for storing elements of the deque. -
head
public int headThe index of the element at the head of the deque or an arbitrary number equal to tail if the deque is empty. -
tail
public int tailThe index at which the next element would be added to the tail of the deque. -
resizer
Buffer resizing strategy.
-
-
Constructor Details
-
DoubleArrayDeque
public DoubleArrayDeque()New instance with sane defaults. -
DoubleArrayDeque
public DoubleArrayDeque(int expectedElements) New instance with sane defaults.- Parameters:
expectedElements
- The expected number of elements guaranteed not to cause buffer expansion (inclusive).
-
DoubleArrayDeque
New instance with sane defaults.- Parameters:
expectedElements
- The expected number of elements guaranteed not to cause buffer expansion (inclusive).resizer
- Underlying buffer sizing strategy.
-
DoubleArrayDeque
Creates a new deque from elements of another container, appending elements at the end of the deque in the iteration order.
-
-
Method Details
-
addFirst
public void addFirst(double e1) Inserts the specified element at the front of this deque.- Specified by:
addFirst
in interfaceDoubleDeque
-
addFirst
public final void addFirst(double... elements) Vararg-signature method for adding elements at the front of this deque.This method is handy, but costly if used in tight loops (anonymous array passing)
- Parameters:
elements
- The elements to add.
-
addFirst
Inserts all elements from the given container to the front of this deque.- Parameters:
container
- The container to iterate over.- Returns:
- Returns the number of elements actually added as a result of this call.
-
addFirst
Inserts all elements from the given iterable to the front of this deque.- Parameters:
iterable
- The iterable to iterate over.- Returns:
- Returns the number of elements actually added as a result of this call.
-
addLast
public void addLast(double e1) Inserts the specified element at the end of this deque.- Specified by:
addLast
in interfaceDoubleDeque
-
addLast
public final void addLast(double... elements) Vararg-signature method for adding elements at the end of this deque.This method is handy, but costly if used in tight loops (anonymous array passing)
- Parameters:
elements
- The elements to iterate over.
-
addLast
Inserts all elements from the given container to the end of this deque.- Parameters:
container
- The container to iterate over.- Returns:
- Returns the number of elements actually added as a result of this call.
-
addLast
Inserts all elements from the given iterable to the end of this deque.- Parameters:
iterable
- The iterable to iterate over.- Returns:
- Returns the number of elements actually added as a result of this call.
-
removeFirst
public double removeFirst()Retrieves and removes the first element of this deque.- Specified by:
removeFirst
in interfaceDoubleDeque
- Returns:
- the head (first) element of this deque.
-
removeLast
public double removeLast()Retrieves and removes the last element of this deque.- Specified by:
removeLast
in interfaceDoubleDeque
- Returns:
- the tail of this deque.
-
getFirst
public double getFirst()Retrieves the first element of this deque but does not remove it.- Specified by:
getFirst
in interfaceDoubleDeque
- Returns:
- the head of this deque.
-
getLast
public double getLast()Retrieves the last element of this deque but does not remove it.- Specified by:
getLast
in interfaceDoubleDeque
- Returns:
- the head of this deque.
-
removeFirst
public int removeFirst(double e1) Removes the first element that equalse
.- Specified by:
removeFirst
in interfaceDoubleDeque
- Returns:
- The deleted element's index or
-1
if the element was not found.
-
bufferIndexOf
public int bufferIndexOf(double e1) Return the index of the first (counting from head) element equal toe1
. The index points to thebuffer
array.- Parameters:
e1
- The element to look for.- Returns:
- Returns the index of the first element equal to
e1
or-1
if not found.
-
removeLast
public int removeLast(double e1) Removes the last element that equalse
.- Specified by:
removeLast
in interfaceDoubleDeque
- Returns:
- The deleted element's index or
-1
if the element was not found.
-
lastBufferIndexOf
public int lastBufferIndexOf(double e1) Return the index of the last (counting from tail) element equal toe1
. The index points to thebuffer
array.- Parameters:
e1
- The element to look for.- Returns:
- Returns the index of the first element equal to
e1
or-1
if not found.
-
removeAll
public int removeAll(double e1) Removes all occurrences ofe
from this collection.- Specified by:
removeAll
in interfaceDoubleCollection
- Parameters:
e1
- Element to be removed from this collection, if present.- Returns:
- The number of removed elements as a result of this call.
-
removeAtBufferIndex
public void removeAtBufferIndex(int index) Removes the element atindex
in the internal {#linkbuffer
array, returning its value. -
isEmpty
public boolean isEmpty()Shortcut forsize() == 0
.- Specified by:
isEmpty
in interfaceDoubleContainer
-
size
public int size()Return the current number of elements in this container. The time for calculating the container's size may takeO(n)
time, although implementing classes should try to maintain the current size and return in constant time.- Specified by:
size
in interfaceDoubleContainer
-
clear
public void clear()Removes all elements from this collection.The internal array buffers are not released as a result of this call.
- Specified by:
clear
in interfaceDoubleCollection
- See Also:
-
release
public void release()Release internal buffers of this deque and reallocate with the default buffer.- Specified by:
release
in interfaceDoubleCollection
- See Also:
-
ensureCapacity
public void ensureCapacity(int expectedElements) Ensure this container can hold at least the given number of elements without resizing its buffers.- Specified by:
ensureCapacity
in interfacePreallocable
- 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. -
toArray
public double[] toArray()Default implementation of copying to an array.- Specified by:
toArray
in interfaceDoubleContainer
- Overrides:
toArray
in classAbstractDoubleCollection
-
toArray
public double[] toArray(double[] target) Copies elements of this deque to an array. The content of thetarget
array is filled from index 0 (head of the queue) to indexsize() - 1
(tail of the queue).- Parameters:
target
- The target array must be large enough to hold all elements.- Returns:
- Returns the target argument for chaining.
-
clone
Clone this object. The returned clone will reuse the same hash function and array resizing strategy. -
oneLeft
protected static int oneLeft(int index, int modulus) Move one index to the left, wrapping around buffer. -
oneRight
protected static int oneRight(int index, int modulus) Move one index to the right, wrapping around buffer. -
iterator
Returns a cursor over the values of this deque (in head to tail order). The iterator is implemented as a cursor and it returns the same cursor instance on every call toIterator.next()
(to avoid boxing of primitive types). To read the current value (or index in the deque's buffer) use the cursor's public fields. An example is shown below.for (IntValueCursor c : intDeque) { System.out.println("buffer index=" + c.index + " value=" + c.value); }
- Specified by:
iterator
in interfaceDoubleContainer
- Specified by:
iterator
in interfaceIterable<DoubleCursor>
-
descendingIterator
Returns a cursor over the values of this deque (in tail to head order). The iterator is implemented as a cursor and it returns the same cursor instance on every call toIterator.next()
(to avoid boxing of primitive types). To read the current value (or index in the deque's buffer) use the cursor's public fields. An example is shown below.for (Iterator<IntCursor> i = intDeque.descendingIterator(); i.hasNext();) { final IntCursor c = i.next(); System.out.println("buffer index=" + c.index + " value=" + c.value); }
- Specified by:
descendingIterator
in interfaceDoubleDeque
- Returns:
- An iterator over elements in this deque in tail-to-head order.
-
forEach
Applies aprocedure
to all container elements. Returns the argument (any subclass ofDoubleProcedure
. 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;
- Specified by:
forEach
in interfaceDoubleContainer
-
forEach
Appliesprocedure
to a slice of the deque,fromIndex
, inclusive, totoIndex
, exclusive. -
forEach
Applies apredicate
to container elements as long, as the predicate returnstrue
. The iteration is interrupted otherwise.- Specified by:
forEach
in interfaceDoubleContainer
-
descendingForEach
Appliesprocedure
to all elements of this deque, tail to head.- Specified by:
descendingForEach
in interfaceDoubleDeque
-
descendingForEach
Appliesprocedure
to a slice of the deque,toIndex
, exclusive, down tofromIndex
, inclusive. -
descendingForEach
Applies apredicate
to container elements as long, as the predicate returnstrue
. The iteration is interrupted otherwise.- Specified by:
descendingForEach
in interfaceDoubleDeque
-
descendingForEach
Appliespredicate
to a slice of the deque,toIndex
, exclusive, down tofromIndex
, inclusive or until the predicate returnsfalse
. -
removeAll
Removes all elements in this collection for which the given predicate returnstrue
.- Specified by:
removeAll
in interfaceDoubleCollection
- Returns:
- Returns the number of removed elements.
-
contains
public boolean contains(double e) Lookup a given element in the container. This operation has no speed guarantees (may be linear with respect to the size of this container).- Specified by:
contains
in interfaceDoubleContainer
- Returns:
- Returns
true
if this container has an element equal toe
.
-
hashCode
public int hashCode() -
equals
Returnstrue
only if the other object is an instance of the same class and with the same elements. -
equalElements
Compare order-aligned elements against anotherDoubleDeque
. -
from
Create a new deque by pushing a variable number of arguments to the end of it.
-