- All Implemented Interfaces:
Iterable<Integer>,Collection<Integer>,Deque<Integer>,Queue<Integer>,SequencedCollection<Integer>,IntDeque,IntSequencedCollection
A
int-valued deque backed by a primitive array.- Author:
- Werner Randelshofer
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with an initial capacity for 8 elements.IntArrayDeque(int capacity) Creates a new instance with the specified initial capacity rounded up to the next strictly positive power of two. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFirstAsInt(int e) voidaddFirstAsIntBranchless(int e, boolean reallyAdd) Adds first using branch-less code that takes advantage of the out-of-order execution unit in the CPU.voidaddLastAllAsInt(int[] array) voidaddLastAllAsInt(int[] array, int offset, int length) voidaddLastAsInt(int e) voidaddLastAsIntBranchless(int e, boolean reallyAdd) Adds last using branch-less code that takes advantage of the out-of-order execution unit in the CPU.voidclear()Clears the deque in O(1).booleanbooleanintfirstIndexOfAsInt(int o) Returns the first index of the specified element or -1 if this deque does not contain the element.intgetAsInt(int index) intintinthashCode()booleanisEmpty()Returns true if this deque is empty.iterator()intlastIndexOfAsInt(int o) Returns the last index of the specified element or -1 if this deque does not contain the element.voidremoveAt(int i) Removes an element at the given array index.intbooleanremoveFirstOccurrenceAsInt(int o) intbooleanremoveLastOccurrenceAsInt(int o) reversed()intsize()toString()Methods inherited from class java.util.AbstractCollection
add, addAll, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
containsAll, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArrayMethods inherited from interface org.jhotdraw8.collection.primitive.IntDeque
add, addFirst, addLast, element, getFirst, getLast, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, popAsInt, push, pushAsInt, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence
-
Constructor Details
-
IntArrayDeque
public IntArrayDeque()Creates a new instance with an initial capacity for 8 elements. -
IntArrayDeque
public IntArrayDeque(int capacity) Creates a new instance with the specified initial capacity rounded up to the next strictly positive power of two.- Parameters:
capacity- initial capacity
-
-
Method Details
-
addFirstAsInt
public void addFirstAsInt(int e) - Specified by:
addFirstAsIntin interfaceIntDeque- Specified by:
addFirstAsIntin interfaceIntSequencedCollection- See Also:
-
addFirstAsIntBranchless
public void addFirstAsIntBranchless(int e, boolean reallyAdd) Adds first using branch-less code that takes advantage of the out-of-order execution unit in the CPU.- Parameters:
e- an elementreallyAdd- true if this element should really be added
-
addLastAllAsInt
public void addLastAllAsInt(int[] array) - Specified by:
addLastAllAsIntin interfaceIntSequencedCollection
-
addLastAllAsInt
public void addLastAllAsInt(int[] array, int offset, int length) - Specified by:
addLastAllAsIntin interfaceIntSequencedCollection
-
addLastAsInt
public void addLastAsInt(int e) - Specified by:
addLastAsIntin interfaceIntDeque- Specified by:
addLastAsIntin interfaceIntSequencedCollection- See Also:
-
addLastAsIntBranchless
public void addLastAsIntBranchless(int e, boolean reallyAdd) Adds last using branch-less code that takes advantage of the out-of-order execution unit in the CPU.- Parameters:
e- an elementreallyAdd- true if this element should really be added
-
clear
public void clear()Clears the deque in O(1).- Specified by:
clearin interfaceCollection<Integer>- Overrides:
clearin classAbstractCollection<Integer>
-
descendingIterator
- Specified by:
descendingIteratorin interfaceDeque<Integer>
-
equals
- Specified by:
equalsin interfaceCollection<Integer>- Overrides:
equalsin classObject
-
firstIndexOfAsInt
public int firstIndexOfAsInt(int o) Returns the first index of the specified element or -1 if this deque does not contain the element.- Parameters:
o- the element- Returns:
- the first index of the element
-
getFirstAsInt
public int getFirstAsInt()- Specified by:
getFirstAsIntin interfaceIntDeque- Specified by:
getFirstAsIntin interfaceIntSequencedCollection- See Also:
-
getAsInt
public int getAsInt(int index) -
getLastAsInt
public int getLastAsInt()- Specified by:
getLastAsIntin interfaceIntDeque- Specified by:
getLastAsIntin interfaceIntSequencedCollection- See Also:
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Integer>- Overrides:
hashCodein classObject
-
isEmpty
public boolean isEmpty()Returns true if this deque is empty.- Specified by:
isEmptyin interfaceCollection<Integer>- Overrides:
isEmptyin classAbstractCollection<Integer>- Returns:
trueif this deque contains no elements
-
reversed
-
iterator
-
lastIndexOfAsInt
public int lastIndexOfAsInt(int o) Returns the last index of the specified element or -1 if this deque does not contain the element.- Parameters:
o- the element- Returns:
- the last index of the element
-
removeAt
public void removeAt(int i) Removes an element at the given array index.- Parameters:
i- an array index
-
removeFirstAsInt
public int removeFirstAsInt()- Specified by:
removeFirstAsIntin interfaceIntDeque- Specified by:
removeFirstAsIntin interfaceIntSequencedCollection- See Also:
-
removeFirstOccurrenceAsInt
public boolean removeFirstOccurrenceAsInt(int o) - Specified by:
removeFirstOccurrenceAsIntin interfaceIntDeque- See Also:
-
removeLastOccurrenceAsInt
public boolean removeLastOccurrenceAsInt(int o) - Specified by:
removeLastOccurrenceAsIntin interfaceIntDeque- See Also:
-
removeLastAsInt
public int removeLastAsInt()- Specified by:
removeLastAsIntin interfaceIntDeque- Specified by:
removeLastAsIntin interfaceIntSequencedCollection- See Also:
-
contains
- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceDeque<Integer>- Overrides:
containsin classAbstractCollection<Integer>
-
size
public int size()- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceDeque<Integer>- Specified by:
sizein classAbstractCollection<Integer>
-
toString
- Overrides:
toStringin classAbstractCollection<Integer>
-