|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mines.jtk.util.ArrayQueue<E>
public class ArrayQueue<E>
A first-in-first-out (FIFO) queue implemented with an array.
This array-based implementation is optimized for performance. Entries
can be added/removed to/from the queue in amortized constant time.
The cost of adding/removing N entries to/from the queue is O(N), and
the constant factor is less than that for an implementation based on
LinkedList.
For queues that contain at least a small number of entries, the length
of the array used to implement the queue is less than twice the maximum
number of entries in the queue. Furthermore, this length is always less
than three times the number of entries in the queue.
Therefore, this implementation requires less memory than one based on
LinkedList.
| Constructor Summary | |
|---|---|
ArrayQueue()
Constructs a queue with default capacity. |
|
ArrayQueue(int capacity)
Constructs a queue with the specified initial capacity. |
|
| Method Summary | |
|---|---|
void |
add(E e)
Adds the specified entry to the back of the queue. |
void |
ensureCapacity(int capacity)
Ensures that the capacity of the queue is not less than the specified value. |
E |
first()
Returns (but does not remove) the entry from the front of the queue. |
boolean |
isEmpty()
Determines whether the queue is empty. |
E |
remove()
Removes and returns the entry from the front of the queue. |
int |
size()
Returns the number of entries in the queue. |
void |
trimToSize()
Sets the capacity of the queue equal to its current size. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ArrayQueue()
public ArrayQueue(int capacity)
This constructor may be used to reduce the cost of adding a large number of entries to the queue, when that number of entries is known in advance.
capacity - the initial capacity.| Method Detail |
|---|
public void add(E e)
e - the entry.public E first()
public E remove()
public boolean isEmpty()
public void ensureCapacity(int capacity)
This method may be used to reduce the cost of adding a large number of entries to the queue, when that number of entries is known in advance.
capacity - the capacity.public int size()
public void trimToSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||