removeLast() and addFirst(long).
| Modifier and Type | Field and Description |
|---|---|
| protected int | head
Index of first element. |
| public int | size
Number of elements in the queue. |
| protected int | tail
Index of last element. |
| protected long[] | values
Contains the values in the queue. |
| Access | Constructor and Description |
|---|---|
| public | LongQueue()
Creates a new LongQueue which can hold 16 values without needing to resize backing array. |
| public | LongQueue(int initialSize)
Creates a new LongQueue which can hold the specified number of values without needing to resize backing array. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | |
| public void | ensureCapacity(int additional)
Increases the size of the backing array to accommodate the specified number of additional items. |
| public boolean | equals(Object o)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public long | |
| public long | |
| public int | |
| public int | Returns: An index of first occurrence of value in queue or -1 if no such value existsReturns the index of first occurrence of value in the queue, or -1 if no such value exists. |
| public boolean | |
| public long | |
| public boolean | |
| public long | |
| public long | |
| public long | |
| public boolean | Returns: true if value was found and removed, false otherwiseRemoves the first instance of the specified value in the queue. |
| protected void | |
| public String | |
| public String |
| head | back to summary |
|---|---|
| protected int head Index of first element. Logically smaller than tail. Unless empty, it points to a valid element inside queue. | |
| size | back to summary |
|---|---|
| public int size Number of elements in the queue. | |
| tail | back to summary |
|---|---|
| protected int tail Index of last element. Logically bigger than head. Usually points to an empty position, but points to the head when full (size == values.length). | |
| values | back to summary |
|---|---|
| protected long[] values Contains the values in the queue. Head and tail indices go in a circle around this array, wrapping at the end. | |
| LongQueue | back to summary |
|---|---|
| public LongQueue() Creates a new LongQueue which can hold 16 values without needing to resize backing array. | |
| LongQueue | back to summary |
|---|---|
| public LongQueue(int initialSize) Creates a new LongQueue which can hold the specified number of values without needing to resize backing array. | |
| addFirst | back to summary |
|---|---|
| public void addFirst(long value) Prepend given value to the head. (enqueue to head) Unless backing array needs resizing, operates in O(1) time.
| |
| addLast | back to summary |
|---|---|
| public void addLast(long value) Append given value to the tail. (enqueue to tail) Unless backing array needs resizing, operates in O(1) time. | |
| clear | back to summary |
|---|---|
| public void clear() Removes all values from this queue. | |
| ensureCapacity | back to summary |
|---|---|
| public void ensureCapacity(int additional) Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| first | back to summary |
|---|---|
| public long first() Returns the first (head) item in the queue (without removing it).
| |
| get | back to summary |
|---|---|
| public long get(int index) Retrieves the value in queue without removing it. Indexing is from the front to back, zero based. Therefore get(0) is the
same as
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(long value) Returns the index of first occurrence of value in the queue, or -1 if no such value exists.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns true if the queue is empty. | |
| last | back to summary |
|---|---|
| public long last() Returns the last (tail) item in the queue (without removing it).
| |
| notEmpty | back to summary |
|---|---|
| public boolean notEmpty() Returns true if the queue has one or more items. | |
| removeFirst | back to summary |
|---|---|
| public long removeFirst() Remove the first item from the queue. (dequeue from head) Always O(1).
| |
| removeIndex | back to summary |
|---|---|
| public long removeIndex(int index) Removes and returns the item at the specified index. | |
| removeLast | back to summary |
|---|---|
| public long removeLast() Remove the last item from the queue. (dequeue from tail) Always O(1).
| |
| removeValue | back to summary |
|---|---|
| public boolean removeValue(long value) Removes the first instance of the specified value in the queue.
| |
| resize | back to summary |
|---|---|
| protected void resize(int newSize) Resize backing array. newSize must be bigger than current size. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| toString | back to summary |
|---|---|
| public String toString(String separator) | |