Package net.hydromatic.morel.util
Class ArrayQueue<E>
java.lang.Object
net.hydromatic.morel.util.ArrayQueue<E>
- Type Parameters:
E- Element type
Like a list, but
poll() (equivalent to remove(0) is O(1).-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intadd(int i, int j, int modulus) voidAdds an element to the tail.asList()Returns a view of the contents as a list.private static intdec(int i, int modulus) voidCalls a consumer with each element, in order.get(int i) Returns the element at positioni.private voidgrow()Increases the capacity by 1.private static intinc(int i, int modulus) booleanisEmpty()Returns whether this queue is empty.@Nullable Epoll()Removes the element at the head of this queue, or returns null.remove(int i) Removes elementifrom the queue in O(1) time.Sets the element at positioni.intsize()Returns the number of elements in this queue.private static intsub(int i, int j, int modulus) toString()
-
Field Details
-
elements
-
start
private int start -
end
private int end
-
-
Constructor Details
-
ArrayQueue
public ArrayQueue()Creates an empty ArrayQueue.
-
-
Method Details
-
toString
-
poll
Removes the element at the head of this queue, or returns null. -
size
public int size()Returns the number of elements in this queue. -
isEmpty
public boolean isEmpty()Returns whether this queue is empty. (Same assize() == 0.) -
get
Returns the element at positioni. -
set
Sets the element at positioni. -
add
Adds an element to the tail. -
grow
private void grow()Increases the capacity by 1. -
asList
Returns a view of the contents as a list. -
inc
private static int inc(int i, int modulus) -
dec
private static int dec(int i, int modulus) -
add
private static int add(int i, int j, int modulus) -
sub
private static int sub(int i, int j, int modulus) -
forEach
Calls a consumer with each element, in order. -
remove
Removes elementifrom the queue in O(1) time.If
iis the first element, removes it (equivalent to callingpoll(); ifiis the last element, removes it; otherwise moves the last element into positioniand shortens the queue. -
listIterator
-