Zend\Stdlib\PriorityQueue
Re-usable, serializable priority queue implementation
SplPriorityQueue acts as a heap; on iteration, each item is removed from the
queue. If you wish to re-use such a queue, you need to clone it first. This
makes for some interesting issues if you wish to delete items from the queue,
or, as already stated, iterate over it multiple times.
This class aggregates items for the queue itself, but also composes an
"inner" iterator in the form of an SplPriorityQueue object for performing
the actual iteration.
Synopsis
class PriorityQueue
implements
Countable,IteratorAggregate,Serializable
{
- // constants
- const EXTR_DATA = 0x00000001;
- const EXTR_PRIORITY = 0x00000002;
- const EXTR_BOTH = 0x00000003;
- // members
- protected string $queueClass;
- protected array $items;
- protected SplPriorityQueue $queue;
- // methods
- public PriorityQueue insert()
- public bool remove()
- public bool isEmpty()
- public int count()
- public mixed top()
- public mixed extract()
- public SplPriorityQueue getIterator()
- public string serialize()
- public void unserialize()
- public array toArray()
- public PriorityQueue setInternalQueueClass()
- public bool contains()
- public bool hasPriority()
- protected SplPriorityQueue getQueue()
- public void __clone()
Hierarchy
Constants
Name | Value |
---|---|
EXTR_DATA | 0x00000001 |
EXTR_PRIORITY | 0x00000002 |
EXTR_BOTH | 0x00000003 |
Members
protected
- $items
—
array
Actual items aggregated in the priority queue. Each item is an array with keys "data" and "priority". - $queue
—
Zend\Stdlib\SplPriorityQueue
Inner queue object - $queueClass
—
string
Inner queue class to use for iteration
Methods
protected
- getQueue() — Get the inner priority queue instance
public
- __clone() — Add support for deep cloning
- contains() — Does the queue contain the given datum?
- count() — How many items are in the queue?
- extract() — Extract a node from the inner queue and sift up
- getIterator() — Retrieve the inner iterator
- hasPriority() — Does the queue have an item with the given priority?
- insert() — Insert an item into the queue
- isEmpty() — Is the queue empty?
- remove() — Remove an item from the queue
- serialize() — Serialize the data structure
- setInternalQueueClass() — Specify the internal queue class
- toArray() — Serialize to an array
- top() — Peek at the top node in the queue, based on priority.
- unserialize() — Unserialize a string into a PriorityQueue object