|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javatools.util.JQueue
Implements a regular queue. The only unusual thing is you can delete things from the middle of the queue efficiently by supplying the QueueKey which is returned by put(). In terms of implementation we use a Dictionary Hashtable instead of a perhaps more traditional vector with round-robin pointers. The benefit here is efficient implementation of the remove functionality. It also happens to be a really easy way to implement queues in general. The way it works is that the dictionary is used as a sparse array. The upper and lower bounds of the sparse array keeping growing up and up towards infinity. This is ok because the key is a long and will take several million years of running before any problems arise.
Nested Class Summary | |
class |
JQueue.QueueKey
A class which can be used to pass to remove to remove something from the middle of the queue. |
Constructor Summary | |
JQueue()
|
|
JQueue(int size)
Constructor which takes an initial guesstimate of how many items we expect to store in it |
Method Summary | |
boolean |
empty()
Is the queue empty? |
java.lang.Object |
get()
Pull something out of the end of the queue and remove it from the queue. |
java.lang.Object |
peek()
Get something out of the queue without removing it. |
JQueue.QueueKey |
put(java.lang.Object o)
Push something onto the queue |
java.lang.Object |
remove(JQueue.QueueKey key)
Remove an item from anywhere in the queue. |
int |
size()
The number of elements in the queue |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JQueue(int size)
size
- Description of Parameterpublic JQueue()
Method Detail |
public java.lang.Object get()
public int size()
public java.lang.Object remove(JQueue.QueueKey key)
key
- Description of Parameter
Queue#put(Object)
public JQueue.QueueKey put(java.lang.Object o)
o
- Description of Parameter
Queue#remove(QueueKey)
public boolean empty()
public java.lang.Object peek()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |