|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinf.util.ArrayOfHashedListsIntPriorityQueue<E>
E
- the element type for elements queuedpublic class ArrayOfHashedListsIntPriorityQueue<E>
This class represents a priority queue, that is a queue in which elements can
be held and from which they can be retrieved by priority. For this purpose,
each object has a priority associated with it that determines when in
relation to the other elements in the queue this element should be retrieved.
Priorities are int
s here. Note, however, that priority values
must not be negative.
The implementation of this priority queue is achieved by maintaining the elements in an array for low priorities and a sorted tree for higher values. The order is determined by the priority and each array entry or tree node contains a HashedList of all the nodes with the same priority. In this way a reasonably efficient execution of all the operations provided can be guaranteed even for very long queues. The removal of elements from this queue and the contains-test with a given priority are supported. However, it also means that queued elements must not be null and no two equal elements can be stored at the same priority.
Nested Class Summary | |
---|---|
(package private) class |
ArrayOfHashedListsIntPriorityQueue.ArrayOfHashedListsIntPriorityQueueIterator<T>
This class represents an iterator for the elements in an ArrayOfListsIntPriorityQueue. |
Field Summary | |
---|---|
protected HashedList<E>[] |
pArray
the data structure that contains an array of lists of nodes |
protected IntKeyTreeMap<HashedList<E>> |
pTree
the data structure that contains a tree of lists of nodes |
Constructor Summary | |
---|---|
ArrayOfHashedListsIntPriorityQueue()
This constructor creates an empty PriorityQueue. |
|
ArrayOfHashedListsIntPriorityQueue(int maxArrayPriority)
This constructor creates an empty PriorityQueue where elements up to the given priority are stored in an array for quicker access. |
Method Summary | |
---|---|
void |
addElementFirst(E element,
int priority)
This function adds the given element at the given priority to this priority queue. |
void |
addElementFirst(E element,
java.lang.Integer priority)
This function adds the given element at the given priority to this priority queue. |
void |
addElementLast(E element,
int priority)
This function adds the given element at the given priority to this priority queue. |
void |
addElementLast(E element,
java.lang.Integer priority)
This function adds the given element at the given priority to this priority queue. |
protected ArrayOfHashedListsIntPriorityQueue<E> |
clone()
This class does not support cloning and an Exception will be thrown if this method is called. |
boolean |
containsElementAt(E element,
int priority)
This function tests whether the given element is currently in this queue at the given priority. |
boolean |
containsElementAt(E element,
java.lang.Integer priority)
This function tests whether the given element is currently in this queue at the given priority. |
boolean |
equals(java.lang.Object obj)
This class does not support equality testing and an exception will be thrown if this method is called. |
E |
getHighestFirst()
This function returns the element in this priority queue that has the highest priority. |
E |
getHighestLast()
This function returns the element in this priority queue that has the highest priority. |
E |
getLowestFirst()
This function returns the element in this priority queue that has the lowest priority. |
E |
getLowestLast()
This function returns the element in this priority queue that has the lowest priority. |
int |
hashCode()
This class does not support hashing and an exception will be thrown if this method is called. |
boolean |
isEmpty()
This function tests whether this PriorityQueue is empty. |
java.util.Iterator<E> |
iterator()
This function returns an Iterator for this priority queue. |
int |
length()
This function returns the size of this priority queue. |
boolean |
removeElementAt(E element,
int priority)
This function attempts to remove the given element at the given priority from this priority queue. |
boolean |
removeElementAt(E element,
java.lang.Integer priority)
This function attempts to remove the given element at the given priority from this priority queue. |
E |
removeHighestFirst()
This function removes and returns the element in this priority queue that has the highest priority. |
E |
removeHighestLast()
This function removes and returns the element in this priority queue that has the highest priority. |
E |
removeLowestFirst()
This function removes and returns the element in this priority queue that has the lowest priority. |
E |
removeLowestLast()
This function removes and returns the element in this priority queue that has the lowest priority. |
java.lang.String |
toString()
This function creates the printable string representation of this priority queue. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected HashedList<E>[] pArray
protected IntKeyTreeMap<HashedList<E>> pTree
Constructor Detail |
---|
public ArrayOfHashedListsIntPriorityQueue()
This constructor creates an empty PriorityQueue.
public ArrayOfHashedListsIntPriorityQueue(int maxArrayPriority)
This constructor creates an empty PriorityQueue where elements up to the given priority are stored in an array for quicker access. Elements with higher priority are stored in a tree.
maxArrayPriority
- the highest priority value stored in the arrayMethod Detail |
---|
protected ArrayOfHashedListsIntPriorityQueue<E> clone() throws java.lang.CloneNotSupportedException
This class does not support cloning and an Exception will be thrown if this method is called.
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- will be thrownpublic void addElementFirst(E element, java.lang.Integer priority)
This function adds the given element at the given priority to this priority queue. Note that the priority must not be negative, the queued element must not be null and no two equal elements can be stored at the same priority. If there are already elements queued at this priority, the new element will be queued at the front.
addElementFirst
in interface PriorityQueue<E,java.lang.Integer>
element
- the element to be added to this IntPriorityQueuepriority
- the priority with which the element is to be queuedpublic void addElementLast(E element, java.lang.Integer priority)
This function adds the given element at the given priority to this priority queue. Note that the priority must not be negative, the queued element must not be null and no two equal elements can be stored at the same priority. If there are already elements queued at this priority, the new element will be queued at the end.
addElementLast
in interface PriorityQueue<E,java.lang.Integer>
element
- the element to be added to this IntPriorityQueuepriority
- the priority with which the element is to be queuedpublic boolean isEmpty()
This function tests whether this PriorityQueue is empty.
isEmpty
in interface PriorityQueue<E,java.lang.Integer>
public int length()
This function returns the size of this priority queue.
length
in interface PriorityQueue<E,java.lang.Integer>
public E getLowestFirst() throws java.util.NoSuchElementException
This function returns the element in this priority queue that has the lowest priority. If there are several elements queued at that priority, the element at the front of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
getLowestFirst
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E getLowestLast() throws java.util.NoSuchElementException
This function returns the element in this priority queue that has the lowest priority. If there are several elements queued at that priority, the element at the end of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
getLowestLast
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E getHighestFirst() throws java.util.NoSuchElementException
This function returns the element in this priority queue that has the highest priority. If there are several elements queued at that priority, the element at the front of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
getHighestFirst
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E getHighestLast() throws java.util.NoSuchElementException
This function returns the element in this priority queue that has the highest priority. If there are several elements queued at that priority, the element at the end of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
getHighestLast
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic boolean containsElementAt(E element, java.lang.Integer priority)
This function tests whether the given element is currently in this queue at the given priority.
containsElementAt
in interface PriorityQueue<E,java.lang.Integer>
element
- element to be tested forpriority
- the priority at which it should be queued
public E removeLowestFirst() throws java.util.NoSuchElementException
This function removes and returns the element in this priority queue that has the lowest priority. If there are several elements queued at that priority, the element at the front of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
removeLowestFirst
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E removeLowestLast() throws java.util.NoSuchElementException
This function removes and returns the element in this priority queue that has the lowest priority. If there are several elements queued at that priority, the element at the end of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
removeLowestLast
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E removeHighestFirst() throws java.util.NoSuchElementException
This function removes and returns the element in this priority queue that has the highest priority. If there are several elements queued at that priority, the element at the front of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
removeHighestFirst
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic E removeHighestLast() throws java.util.NoSuchElementException
This function removes and returns the element in this priority queue that has the highest priority. If there are several elements queued at that priority, the element at the end of the list is retrieved. An exception is thrown if there is no such element, i.e. if this priority queue is empty.
removeHighestLast
in interface PriorityQueue<E,java.lang.Integer>
java.util.NoSuchElementException
- if this PriorityQueue is emptypublic boolean removeElementAt(E element, java.lang.Integer priority)
This function attempts to remove the given element at the given priority from this priority queue. Whether the removal was successful is returned.
removeElementAt
in interface PriorityQueue<E,java.lang.Integer>
element
- the element to be removed from this PriorityQueuepriority
- the priority at which the element is queued
public void addElementFirst(E element, int priority)
This function adds the given element at the given priority to this priority queue. Note that the priority must not be negative, the queued element must not be null and no two equal elements can be stored at the same priority. If there are already elements queued at this priority, the new element will be queued at the front.
addElementFirst
in interface IntPriorityQueue<E>
element
- the element to be added to this IntPriorityQueuepriority
- the priority with which the element is to be queuedpublic void addElementLast(E element, int priority)
This function adds the given element at the given priority to this priority queue. Note that the priority must not be negative, the queued element must not be null and no two equal elements can be stored at the same priority. If there are already elements queued at this priority, the new element will be queued at the end.
addElementLast
in interface IntPriorityQueue<E>
element
- the element to be added to this IntPriorityQueuepriority
- the priority with which the element is to be queuedpublic boolean containsElementAt(E element, int priority)
This function tests whether the given element is currently in this queue at the given priority.
containsElementAt
in interface IntPriorityQueue<E>
element
- element to be tested forpriority
- the priority at which it should be queued
public boolean removeElementAt(E element, int priority)
This function attempts to remove the given element at the given priority from this priority queue. Whether the removal was successful is returned.
removeElementAt
in interface IntPriorityQueue<E>
element
- the element to be removed from this PriorityQueuepriority
- the priority at which the element is queued
public java.util.Iterator<E> iterator()
This function returns an Iterator for this priority queue.
iterator
in interface java.lang.Iterable<E>
public boolean equals(java.lang.Object obj) throws java.lang.UnsupportedOperationException
This class does not support equality testing and an exception will be thrown if this method is called.
equals
in class java.lang.Object
obj
- the Object this should be compared to
java.lang.UnsupportedOperationException
- will be thrownpublic int hashCode() throws java.lang.UnsupportedOperationException
This class does not support hashing and an exception will be thrown if this method is called.
hashCode
in class java.lang.Object
java.lang.UnsupportedOperationException
- will be thrownpublic java.lang.String toString()
This function creates the printable string representation of this priority queue.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |