com.carrotsearch.hppc
Class ObjectArrayDeque<KType>
- java.lang.Object
-
- com.carrotsearch.hppc.ObjectArrayDeque<KType>
-
- All Implemented Interfaces:
- ObjectCollection<KType>, ObjectContainer<KType>, ObjectDeque<KType>, Preallocable, java.lang.Cloneable, java.lang.Iterable<ObjectCursor<KType>>
@Generated(date="2015-05-07T09:33:04+0200", value="KTypeArrayDeque.java") public class ObjectArrayDeque<KType> extends java.lang.Object implements ObjectDeque<KType>, Preallocable, java.lang.CloneableAn array-backedObjectDeque.
-
-
Field Summary
Fields Modifier and Type Field and Description java.lang.Object[]bufferInternal array for storing elements of the deque.intheadThe index of the element at the head of the deque or an arbitrary number equal to tail if the deque is empty.inttailThe index at which the next element would be added to the tail of the deque.
-
Constructor Summary
Constructors Constructor and Description ObjectArrayDeque()New instance with sane defaults.ObjectArrayDeque(int expectedElements)New instance with sane defaults.ObjectArrayDeque(int expectedElements, ArraySizingStrategy resizer)New instance with sane defaults.ObjectArrayDeque(ObjectContainer<? extends KType> container)Creates a new deque from elements of another container, appending elements at the end of the deque in the iteration order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description intaddFirst(java.lang.Iterable<? extends ObjectCursor<? extends KType>> iterable)Inserts all elements from the given iterable to the front of this deque.voidaddFirst(KType... elements)Vararg-signature method for adding elements at the front of this deque.voidaddFirst(KType e1)Inserts the specified element at the front of this deque.intaddFirst(ObjectContainer<? extends KType> container)Inserts all elements from the given container to the front of this deque.intaddLast(java.lang.Iterable<? extends ObjectCursor<? extends KType>> iterable)Inserts all elements from the given iterable to the end of this deque.voidaddLast(KType... elements)Vararg-signature method for adding elements at the end of this deque.voidaddLast(KType e1)Inserts the specified element at the end of this deque.intaddLast(ObjectContainer<? extends KType> container)Inserts all elements from the given container to the end of this deque.intbufferIndexOf(KType e1)Return the index of the first (counting from head) element equal toe1.voidclear()Removes all elements from this collection.ObjectArrayDeque<KType>clone()Clone this object.booleancontains(KType e)Lookup a given element in the container.<T extends ObjectPredicate<? super KType>>
TdescendingForEach(T predicate)Applies apredicateto container elements as long, as the predicate returnstrue.<T extends ObjectProcedure<? super KType>>
TdescendingForEach(T procedure)Appliesprocedureto all elements of this deque, tail to head.java.util.Iterator<ObjectCursor<KType>>descendingIterator()Returns a cursor over the values of this deque (in tail to head order).voidensureCapacity(int expectedElements)Ensure this container can hold at least the given number of elements without resizing its buffers.booleanequals(java.lang.Object obj)Returnstrueonly if the other object is an instance of the same class and with the same elements.<T extends ObjectPredicate<? super KType>>
TforEach(T predicate)Applies apredicateto container elements as long, as the predicate returnstrue.<T extends ObjectProcedure<? super KType>>
TforEach(T procedure)Applies aprocedureto all container elements.static <KType> ObjectArrayDeque<KType>from(KType... elements)Create a new deque by pushing a variable number of arguments to the end of it.KTypegetFirst()Retrieves the first element of this deque but does not remove it.KTypegetLast()Retrieves the last element of this deque but does not remove it.inthashCode()booleanisEmpty()Shortcut forsize() == 0.java.util.Iterator<ObjectCursor<KType>>iterator()Returns a cursor over the values of this deque (in head to tail order).intlastBufferIndexOf(KType e1)Return the index of the last (counting from tail) element equal toe1.voidrelease()Release internal buffers of this deque and reallocate with the default buffer.intremoveAll(KType e1)Removes all occurrences ofefrom this collection.intremoveAll(ObjectLookupContainer<? super KType> c)Default implementation uses a predicate for removal.intremoveAll(ObjectPredicate<? super KType> predicate)Removes all elements in this collection for which the given predicate returnstrue.voidremoveAtBufferIndex(int index)Removes the element atindexin the internal {#linkbufferarray, returning its value.KTyperemoveFirst()Retrieves and removes the first element of this deque.intremoveFirst(KType e1)Removes the first element that equalse.KTyperemoveLast()Retrieves and removes the last element of this deque.intremoveLast(KType e1)Removes the last element that equalse.intretainAll(ObjectLookupContainer<? super KType> c)Default implementation uses a predicate for retaining.intretainAll(ObjectPredicate<? super KType> predicate)Default implementation redirects toObjectCollection.removeAll(ObjectPredicate)and negates the predicate.intsize()Return the current number of elements in this container.java.lang.Object[]toArray()Default implementation of copying to an array.<T> T[]toArray(java.lang.Class<T> componentClass)Copies all elements of this container to a dynamically created array of the given component type.KType[]toArray(KType[] target)Copies elements of this deque to an array.java.lang.StringtoString()Convert the contents of this container to a human-friendly string.-
Methods inherited from interface com.carrotsearch.hppc.ObjectCollection
removeAll, retainAll, retainAll
-
Methods inherited from interface com.carrotsearch.hppc.ObjectContainer
toArray
-
-
-
-
Field Detail
-
buffer
public java.lang.Object[] buffer
Internal array for storing elements of the deque.
-
head
public 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.
-
tail
public int tail
The index at which the next element would be added to the tail of the deque.
-
-
Constructor Detail
-
ObjectArrayDeque
public ObjectArrayDeque()
New instance with sane defaults.
-
ObjectArrayDeque
public ObjectArrayDeque(int expectedElements)
New instance with sane defaults.- Parameters:
expectedElements- The expected number of elements guaranteed not to cause buffer expansion (inclusive).
-
ObjectArrayDeque
public ObjectArrayDeque(int expectedElements, ArraySizingStrategy resizer)New instance with sane defaults.- Parameters:
expectedElements- The expected number of elements guaranteed not to cause buffer expansion (inclusive).resizer- Underlying buffer sizing strategy.
-
ObjectArrayDeque
public ObjectArrayDeque(ObjectContainer<? extends KType> container)
Creates a new deque from elements of another container, appending elements at the end of the deque in the iteration order.
-
-
Method Detail
-
addFirst
public void addFirst(KType e1)
Inserts the specified element at the front of this deque.- Specified by:
addFirstin interfaceObjectDeque<KType>
-
addFirst
@SafeVarargs public final void addFirst(KType... 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
public int addFirst(ObjectContainer<? extends KType> container)
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
public int addFirst(java.lang.Iterable<? extends ObjectCursor<? extends KType>> iterable)
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(KType e1)
Inserts the specified element at the end of this deque.- Specified by:
addLastin interfaceObjectDeque<KType>
-
addLast
@SafeVarargs public final void addLast(KType... 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
public int addLast(ObjectContainer<? extends KType> container)
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
public int addLast(java.lang.Iterable<? extends ObjectCursor<? extends KType>> iterable)
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 KType removeFirst()
Retrieves and removes the first element of this deque.- Specified by:
removeFirstin interfaceObjectDeque<KType>- Returns:
- the head (first) element of this deque.
-
removeLast
public KType removeLast()
Retrieves and removes the last element of this deque.- Specified by:
removeLastin interfaceObjectDeque<KType>- Returns:
- the tail of this deque.
-
getFirst
public KType getFirst()
Retrieves the first element of this deque but does not remove it.- Specified by:
getFirstin interfaceObjectDeque<KType>- Returns:
- the head of this deque.
-
getLast
public KType getLast()
Retrieves the last element of this deque but does not remove it.- Specified by:
getLastin interfaceObjectDeque<KType>- Returns:
- the head of this deque.
-
removeFirst
public int removeFirst(KType e1)
Removes the first element that equalse.- Specified by:
removeFirstin interfaceObjectDeque<KType>- Returns:
- The deleted element's index or
-1if the element was not found.
-
bufferIndexOf
public int bufferIndexOf(KType e1)
Return the index of the first (counting from head) element equal toe1. The index points to thebufferarray.- Parameters:
e1- The element to look for.- Returns:
- Returns the index of the first element equal to
e1or-1if not found.
-
removeLast
public int removeLast(KType e1)
Removes the last element that equalse.- Specified by:
removeLastin interfaceObjectDeque<KType>- Returns:
- The deleted element's index or
-1if the element was not found.
-
lastBufferIndexOf
public int lastBufferIndexOf(KType e1)
Return the index of the last (counting from tail) element equal toe1. The index points to thebufferarray.- Parameters:
e1- The element to look for.- Returns:
- Returns the index of the first element equal to
e1or-1if not found.
-
removeAll
public int removeAll(KType e1)
Removes all occurrences ofefrom this collection.- Specified by:
removeAllin interfaceObjectCollection<KType>- 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 atindexin the internal {#linkbufferarray, returning its value.
-
isEmpty
public boolean isEmpty()
Shortcut forsize() == 0.- Specified by:
isEmptyin interfaceObjectContainer<KType>
-
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:
sizein interfaceObjectContainer<KType>
-
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:
clearin interfaceObjectCollection<KType>- See Also:
release()
-
release
public void release()
Release internal buffers of this deque and reallocate with the default buffer.- Specified by:
releasein interfaceObjectCollection<KType>- See Also:
ObjectCollection.clear()
-
ensureCapacity
public void ensureCapacity(int expectedElements)
Ensure this container can hold at least the given number of elements without resizing its buffers.- Specified by:
ensureCapacityin interfacePreallocable- Parameters:
expectedElements- The total number of elements, inclusive.
-
toArray
public java.lang.Object[] toArray()
Default implementation of copying to an array.- Specified by:
toArrayin interfaceObjectContainer<KType>
-
toArray
public KType[] toArray(KType[] target)
Copies elements of this deque to an array. The content of thetargetarray 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
public ObjectArrayDeque<KType> clone()
Clone this object. The returned clone will reuse the same hash function and array resizing strategy.- Overrides:
clonein classjava.lang.Object
-
iterator
public java.util.Iterator<ObjectCursor<KType>> 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:
iteratorin interfaceObjectContainer<KType>- Specified by:
iteratorin interfacejava.lang.Iterable<ObjectCursor<KType>>
-
descendingIterator
public java.util.Iterator<ObjectCursor<KType>> 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:
descendingIteratorin interfaceObjectDeque<KType>- Returns:
- An iterator over elements in this deque in tail-to-head order.
-
forEach
public <T extends ObjectProcedure<? super KType>> T forEach(T procedure)
Applies aprocedureto all container elements. Returns the argument (any subclass ofObjectProcedure. 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:
forEachin interfaceObjectContainer<KType>
-
forEach
public <T extends ObjectPredicate<? super KType>> T forEach(T predicate)
Applies apredicateto container elements as long, as the predicate returnstrue. The iteration is interrupted otherwise.- Specified by:
forEachin interfaceObjectContainer<KType>
-
descendingForEach
public <T extends ObjectProcedure<? super KType>> T descendingForEach(T procedure)
Appliesprocedureto all elements of this deque, tail to head.- Specified by:
descendingForEachin interfaceObjectDeque<KType>
-
descendingForEach
public <T extends ObjectPredicate<? super KType>> T descendingForEach(T predicate)
Applies apredicateto container elements as long, as the predicate returnstrue. The iteration is interrupted otherwise.- Specified by:
descendingForEachin interfaceObjectDeque<KType>
-
removeAll
public int removeAll(ObjectPredicate<? super KType> predicate)
Removes all elements in this collection for which the given predicate returnstrue.- Specified by:
removeAllin interfaceObjectCollection<KType>- Returns:
- Returns the number of removed elements.
-
contains
public boolean contains(KType 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:
containsin interfaceObjectContainer<KType>- Returns:
- Returns
trueif this container has an element equal toe.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Returnstrueonly if the other object is an instance of the same class and with the same elements. Equality comparison is performed with this object'sequals(Object, Object)method.- Overrides:
equalsin classjava.lang.Object
-
from
@SafeVarargs public static <KType> ObjectArrayDeque<KType> from(KType... elements)
Create a new deque by pushing a variable number of arguments to the end of it.
-
removeAll
public int removeAll(ObjectLookupContainer<? super KType> c)
Default implementation uses a predicate for removal.- Specified by:
removeAllin interfaceObjectCollection<KType>- Returns:
- Returns the number of removed elements.
-
retainAll
public int retainAll(ObjectLookupContainer<? super KType> c)
Default implementation uses a predicate for retaining.- Specified by:
retainAllin interfaceObjectCollection<KType>- Returns:
- Returns the number of removed elements.
-
retainAll
public int retainAll(ObjectPredicate<? super KType> predicate)
Default implementation redirects toObjectCollection.removeAll(ObjectPredicate)and negates the predicate.- Specified by:
retainAllin interfaceObjectCollection<KType>- Returns:
- Returns the number of removed elements.
-
toArray
public <T> T[] toArray(java.lang.Class<T> componentClass)
Description copied from interface:ObjectContainerCopies all elements of this container to a dynamically created array of the given component type.- Specified by:
toArrayin interfaceObjectContainer<KType>
-
toString
public java.lang.String toString()
Convert the contents of this container to a human-friendly string.- Overrides:
toStringin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG