@Generated(date="2018-01-02T13:19:08+0000", value="HPPC generated from: LongArrayDeque.java") public class LongArrayDeque extends java.lang.Object implements LongDeque, java.lang.Cloneable
ArraySizingStrategy
and may be expensive if they move around really large chunks of memory.
See ObjectArrayDeque
class for API similarities and differences against Java
Collections.
Modifier and Type | Field and Description |
---|---|
long[] |
buffer
Internal array for storing elements.
|
static int |
DEFAULT_CAPACITY
Default capacity if no other capacity is given in the constructor.
|
int |
head
The index of the element at the head of the deque or an
arbitrary number equal to tail if the deque is empty.
|
protected ArraySizingStrategy |
resizer
Buffer resizing strategy.
|
int |
tail
The index at which the next element would be added to the tail
of the deque.
|
Constructor and Description |
---|
LongArrayDeque()
Create with default sizing strategy and initial capacity for storing
5 elements.
|
LongArrayDeque(int initialCapacity)
Create with default sizing strategy and the given initial capacity.
|
LongArrayDeque(int initialCapacity,
ArraySizingStrategy resizer)
Create with a custom buffer resizing strategy.
|
LongArrayDeque(LongContainer container)
Creates a new deque from elements of another container, appending them
at the end of this deque.
|
Modifier and Type | Method and Description |
---|---|
int |
addFirst(java.lang.Iterable<? extends LongCursor> iterable)
Inserts all elements from the given iterable to the front of this deque.
|
void |
addFirst(long... elements)
Vararg-signature method for adding elements at the front of this deque.
|
void |
addFirst(long e1)
Inserts the specified element at the front of this deque.
|
int |
addFirst(LongContainer container)
Inserts all elements from the given container to the front of this deque.
|
int |
addLast(java.lang.Iterable<? extends LongCursor> iterable)
Inserts all elements from the given iterable to the end of this deque.
|
void |
addLast(long... elements)
Vararg-signature method for adding elements at the end of this deque.
|
void |
addLast(long e1)
Inserts the specified element at the end of this deque.
|
int |
addLast(LongContainer container)
Inserts all elements from the given container to the end of this deque.
|
int |
bufferIndexOf(long e1)
Return the index of the first (counting from head) element equal to
e1 . |
void |
clear()
Removes all elements from this collection.
|
LongArrayDeque |
clone()
Clone this object.
|
boolean |
contains(long e)
Lookup a given element in the container.
|
<T extends LongPredicate> |
descendingForEach(T predicate)
Applies a
predicate to container elements as long, as the predicate
returns true . |
<T extends LongProcedure> |
descendingForEach(T procedure)
Applies
procedure to all elements of this deque, tail to head. |
java.util.Iterator<LongCursor> |
descendingIterator()
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 store
expectedAdditions . |
boolean |
equals(java.lang.Object obj)
Compares the specified object with this deque for equality.
|
<T extends LongPredicate> |
forEach(T predicate)
Applies a
predicate to container elements as long, as the predicate
returns true . |
<T extends LongProcedure> |
forEach(T procedure)
Applies a
procedure to all container elements. |
static LongArrayDeque |
from(long... elements)
Create a new deque by pushing a variable number of arguments to the end of it.
|
static LongArrayDeque |
from(LongArrayDeque container)
Create a new deque by pushing a variable number of arguments to the end of it.
|
long |
getFirst()
Retrieves, but does not remove, the first element of this deque.
|
long |
getLast()
Retrieves, but does not remove, the last element of this deque.
|
int |
hashCode() |
boolean |
isEmpty()
Shortcut for
size() == 0 . |
java.util.Iterator<LongCursor> |
iterator()
Returns a cursor over the values of this deque (in head to tail order).
|
int |
lastBufferIndexOf(long e1)
Return the index of the last (counting from tail) element equal to
e1 . |
static LongArrayDeque |
newInstance()
Returns a new object of this class with no need to declare generic type (shortcut
instead of using a constructor).
|
static LongArrayDeque |
newInstanceWithCapacity(int initialCapacity)
Returns a new object of this class with no need to declare generic type (shortcut
instead of using a constructor).
|
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 the smallest buffer possible.
|
int |
removeAll(LongLookupContainer c)
Default implementation uses a predicate for removal.
|
int |
removeAll(LongPredicate predicate)
Removes all elements in this collection for which the
given predicate returns
true . |
int |
removeAllOccurrences(long e1)
Removes all occurrences of
e from this collection. |
void |
removeAtBufferIndex(int index)
Removes the element at
index in the internal
{#link buffer } array, returning its value. |
long |
removeFirst()
Retrieves and removes the first element of this deque.
|
int |
removeFirstOccurrence(long e1)
Removes the first element that equals
e1 , returning its
deleted position or -1 if the element was not found. |
long |
removeLast()
Retrieves and removes the last element of this deque.
|
int |
removeLastOccurrence(long e1)
Removes the last element that equals
e1 , returning its
deleted position or -1 if the element was not found. |
int |
retainAll(LongLookupContainer c)
Default implementation uses a predicate for retaining.
|
int |
retainAll(LongPredicate predicate)
Default implementation redirects to
LongCollection.removeAll(LongPredicate)
and negates the predicate. |
int |
size()
Return the current number of elements in this container.
|
long[] |
toArray()
Default implementation of copying to an array.
|
long[] |
toArray(long[] target)
Copies elements of this deque to an array.
|
java.lang.String |
toString()
Convert the contents of this container to a human-friendly string.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
removeAll, retainAll, retainAll
public static final int DEFAULT_CAPACITY
public long[] buffer
public int head
public int tail
protected final ArraySizingStrategy resizer
public LongArrayDeque()
BoundedProportionalArraySizingStrategy
public LongArrayDeque(int initialCapacity)
BoundedProportionalArraySizingStrategy
public LongArrayDeque(int initialCapacity, ArraySizingStrategy resizer)
public LongArrayDeque(LongContainer container)
public void addFirst(long e1)
public void addFirst(long... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
public int addFirst(LongContainer container)
public int addFirst(java.lang.Iterable<? extends LongCursor> iterable)
public void addLast(long e1)
public void addLast(long... elements)
This method is handy, but costly if used in tight loops (anonymous array passing)
public int addLast(LongContainer container)
public int addLast(java.lang.Iterable<? extends LongCursor> iterable)
public long removeFirst()
removeFirst
in interface LongDeque
public long removeLast()
removeLast
in interface LongDeque
public long getFirst()
public long getLast()
public int removeFirstOccurrence(long e1)
e1
, returning its
deleted position or -1
if the element was not found.removeFirstOccurrence
in interface LongDeque
public int bufferIndexOf(long e1)
e1
. The index points to the buffer
array.e1
- The element to look for.e1
or -1
if not found.public int removeLastOccurrence(long e1)
e1
, returning its
deleted position or -1
if the element was not found.removeLastOccurrence
in interface LongDeque
public int lastBufferIndexOf(long e1)
e1
. The index points to the buffer
array.e1
- The element to look for.e1
or -1
if not found.public int removeAllOccurrences(long e1)
e
from this collection.removeAllOccurrences
in interface LongCollection
e1
- Element to be removed from this collection, if present.public void removeAtBufferIndex(int index)
index
in the internal
{#link buffer
} array, returning its value.public boolean isEmpty()
size() == 0
.isEmpty
in interface LongContainer
public int size()
O(n)
time, although implementing classes
should try to maintain the current size and return in constant time.size
in interface LongContainer
public void clear()
The internal array buffers are not released as a result of this call.
clear
in interface LongCollection
release()
public void release()
protected void ensureBufferSpace(int expectedAdditions)
expectedAdditions
. Increases internal buffer size if needed.public long[] toArray()
toArray
in interface LongContainer
public long[] toArray(long[] target)
target
array is filled from index 0 (head of the queue) to index size() - 1
(tail of the queue).target
- The target array must be large enough to hold all elements.public LongArrayDeque clone()
clone
in class java.lang.Object
protected static int oneLeft(int index, int modulus)
protected static int oneRight(int index, int modulus)
public java.util.Iterator<LongCursor> iterator()
Iterator.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); }
iterator
in interface LongContainer
iterator
in interface java.lang.Iterable<LongCursor>
public java.util.Iterator<LongCursor> descendingIterator()
Iterator.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 (Iteratori = intDeque.descendingIterator(); i.hasNext(); ) { final IntCursor c = i.next(); System.out.println("buffer index=" + c.index + " value=" + c.value); }
descendingIterator
in interface LongDeque
public <T extends LongProcedure> T forEach(T procedure)
procedure
to all container elements. Returns the argument (any
subclass of LongProcedure
. 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;
forEach
in interface LongContainer
public <T extends LongPredicate> T forEach(T predicate)
predicate
to container elements as long, as the predicate
returns true
. The iteration is interrupted otherwise.forEach
in interface LongContainer
public <T extends LongProcedure> T descendingForEach(T procedure)
procedure
to all elements of this deque, tail to head.descendingForEach
in interface LongDeque
public <T extends LongPredicate> T descendingForEach(T predicate)
predicate
to container elements as long, as the predicate
returns true
. The iteration is interrupted otherwise.descendingForEach
in interface LongDeque
public int removeAll(LongPredicate predicate)
true
.removeAll
in interface LongCollection
public boolean contains(long e)
contains
in interface LongContainer
true
if this container has an element
equal to e
.public int hashCode()
hashCode
in interface LongDeque
hashCode
in class java.lang.Object
List.hashCode()
(should be implemented
with the same algorithm), replacing forward index loop with a forward iterator
loop.public boolean equals(java.lang.Object obj)
ObjectDeque
, and all corresponding
pairs of elements acquired from forward iterators are the same. In other words, two indexed
containers are defined to be equal if they contain the same elements in the same
order of iteration.
Note that, unlike in List
, deques may be of different types and still
return true
from LongDeque.equals(java.lang.Object)
. This may be dangerous if you use
different hash functions in two containers, but don't override the default
implementation of LongDeque.equals(java.lang.Object)
. It is the programmer's responsibility to
enforcing these contracts properly.
public static LongArrayDeque newInstance()
public static LongArrayDeque newInstanceWithCapacity(int initialCapacity)
public static LongArrayDeque from(long... elements)
public static LongArrayDeque from(LongArrayDeque container)
public int removeAll(LongLookupContainer c)
removeAll
in interface LongCollection
public int retainAll(LongLookupContainer c)
retainAll
in interface LongCollection
public int retainAll(LongPredicate predicate)
LongCollection.removeAll(LongPredicate)
and negates the predicate.retainAll
in interface LongCollection
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018 Carrot Search s.c.. All rights reserved.