#import <ObjectiveLib/Queue.h>
Inheritance diagram for OLPriorityQueue:
Public Member Functions | |
(int) | - compare: |
Compare this queue to another object. | |
(id) | - copy |
Make a copy of this queue. | |
(BOOL) | - empty |
Test whether the queue is empty. | |
(BOOL) | - isEqual: |
Return whether this queue is equal to another one. | |
(void) | - pop |
Remove the highest priority item. | |
(void) | - push: |
Add an item to the queue. | |
(unsigned) | - size |
Return the number of elements in the queue. | |
(id) | - top |
Return the highest priority element. | |
(void) | - writeSelfToStream: |
Write the object to a stream. | |
Initializers and Deallocators | |
(id) | - free |
Finalize the queue and deallocate any allocated memory. | |
(id) | - init |
Initialize the queue. | |
(id) | - initFrom:to: |
Initialize the queue. | |
(id) | - initFrom:to:predicate: |
Initialize the queue. | |
(id) | - initWithObjectInStream: |
Initialize the object. | |
(id) | - initWithPredicate: |
Initialize the queue. | |
(id) | - initWithPriorityQueue: |
Initialize the queue. | |
Static Public Member Functions | |
(id) | + priorityQueue |
Create and return a new queue. | |
(id) | + priorityQueueFrom:to: |
Create and return a new queue. | |
(id) | + priorityQueueFrom:to:predicate: |
Create and return a new queue. | |
(id) | + priorityQueueWithPredicate: |
Create and return a new queue. | |
(id) | + priorityQueueWithPriorityQueue: |
Create and return a new queue. | |
Protected Attributes | |
OLStreamableFunctor< OLBoolBinaryFunction > * | predicate |
The function object used to order the queue. | |
OLVector * | vector |
The container that provides that underlying data structure. |
This is similar to a first-in-first-out queue in that elements are pushed to the back of the queue and retrieved from the head of the queue. The difference is that rather than ordering elements according to the order in which they were placed in the queue, the priority queue orders elements according to a function object that determines each elements priority. Thus, the priority queue's top (OLPriorityQueue) message retrieves the element with the highest priority regardless of when that element was placed in the queue. As with OLQueue, OLPriorityQueue is not a true container because it does not provide iterators, and therefore cannot be used with generic algorithms.
The function object that orders the elements considers the highest priority element to be the one that fails the comparison when compared to all other elements in the queue. Therefore, to create a queue where the largest elements are considered the ones of highest priority, the function OLLess should be used.
- (int) compare: | (id) | other |
Compare this queue to another object.
If the other object is of type OLPriorityQueue, the underlying vector of this object will compared to the underlying vector of other using the compare: (OLVector) method.
other | the object with which to compare this one |
- (id) copy |
Make a copy of this queue.
- (BOOL) empty |
Test whether the queue is empty.
- (id) free |
Finalize the queue and deallocate any allocated memory.
- (id) init |
Initialize the queue.
The queue is initially empty and the comparison function OLLess.
- (id) initFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
Initialize the queue.
The queue uses the comparison function OLLess. All elements in the range [first, last)
are inserted into the queue.
first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert |
- (id) initFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
predicate: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | pred | ||
Initialize the queue.
The queue uses the comparison function pred. All elements in the range [first, last)
are inserted into the queue.
first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert | |
pred | the function object used to order elements |
- (id) initWithObjectInStream: | (OLObjectInStream *) | stream |
Initialize the object.
Each instance variable is read from stream and all other initialization is performed.
stream | the stream from which to read |
Reimplemented from < OLStreamable >.
- (id) initWithPredicate: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | pred |
Initialize the queue.
The queue is empty and uses the function object pred to order elements.
pred | the function object used to order elements |
- (id) initWithPriorityQueue: | (OLPriorityQueue *) | right |
Initialize the queue.
The comparison function and all elements are copied from right into this queue.
right | the queue to copy |
- (BOOL) isEqual: | (id) | object |
Return whether this queue is equal to another one.
Two queues are considered equal if they both contain the same number of objects that all return YES to the message isEqual:
and they are in the same order.
object | the object to test |
- (void) pop |
Remove the highest priority item.
The element returned by the message top is removed from the queue.
+ (id) priorityQueue |
Create and return a new queue.
An instance of OLLess is used to order the items by priority.
+ (id) priorityQueueFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
Create and return a new queue.
The queue is initialized with the contents of the range [first, last)
. An instance of OLLess is used to order the items by priority.
first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert |
+ (id) priorityQueueFrom: | (OLForwardIterator *) | first | ||
to: | (OLForwardIterator *) | last | ||
predicate: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | pred | ||
Create and return a new queue.
The queue is initialized with the contents of the range [first, last)
, and pred is used to order the items by priority.
first | the first in the range of elements to insert | |
last | one beyond the last in the range of elements to insert | |
pred | the function object used to order elements |
+ (id) priorityQueueWithPredicate: | (OLStreamableFunctor< OLBoolBinaryFunction > *) | pred |
Create and return a new queue.
The function object pred is used to order the items by priority.
pred | the function object used to order elements |
+ (id) priorityQueueWithPriorityQueue: | (OLPriorityQueue *) | right |
Create and return a new queue.
The queue is initialized with the contents of the priority queue right.
right | the priority queue to copy into the new one |
- (void) push: | (id) | object |
Add an item to the queue.
The element object will be added to the queue at whatever position is determined by predicate.
object | the element to add |
- (unsigned) size |
Return the number of elements in the queue.
- (id) top |
Return the highest priority element.
This is the same element that will be removed by the message pop.
- (void) writeSelfToStream: | (OLObjectOutStream *) | stream |
Write the object to a stream.
All instance variables are written to stream.
stream | the stream to which to write. |
Reimplemented from < OLStreamable >.
- (OLStreamableFunctor<OLBoolBinaryFunction>*) predicate [protected] |
The function object used to order the queue.
|