1799. Class

1799.1. 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.

1799.1.1. Methods

1799.1.1.1. insert

insert()

Insert an item into the queue

Priority defaults to 1 (low priority) if none provided.

Parameters:
  • mixed
  • int
Return type:

PriorityQueue

1799.1.1.2. remove

remove()

Remove an item from the queue

This is different than {@link extract()}; its purpose is to dequeue an item.

This operation is potentially expensive, as it requires re-initialization and re-population of the inner queue.

Note: this removes the first item matching the provided item found. If the same item has been added multiple times, it will not remove other instances.

Parameters:mixed
Return type:bool False if the item was not found, true otherwise.

1799.1.1.3. isEmpty

isEmpty()

Is the queue empty?

Return type:bool

1799.1.1.4. count

count()

How many items are in the queue?

Return type:int

1799.1.1.5. top

top()

Peek at the top node in the queue, based on priority.

Return type:mixed

1799.1.1.6. extract

extract()

Extract a node from the inner queue and sift up

Return type:mixed

1799.1.1.7. getIterator

getIterator()

Retrieve the inner iterator

SplPriorityQueue acts as a heap, which typically implies that as items are iterated, they are also removed. This does not work for situations where the queue may be iterated multiple times. As such, this class aggregates the values, and also injects an SplPriorityQueue. This method retrieves the inner queue object, and clones it for purposes of iteration.

Return type:SplPriorityQueue

1799.1.1.8. serialize

serialize()

Serialize the data structure

Return type:string

1799.1.1.9. unserialize

unserialize()

Unserialize a string into a PriorityQueue object

Serialization format is compatible with {@link ZendStdlibSplPriorityQueue}

Parameters:string
Return type:void

1799.1.1.10. toArray

toArray()

Serialize to an array

By default, returns only the item data, and in the order registered (not sorted). You may provide one of the EXTR_* flags as an argument, allowing the ability to return priorities or both data and priority.

Parameters:int
Return type:array

1799.1.1.11. setInternalQueueClass

setInternalQueueClass()

Specify the internal queue class

Please see {@link getIterator()} for details on the necessity of an internal queue class. The class provided should extend SplPriorityQueue.

Parameters:string
Return type:PriorityQueue

1799.1.1.12. contains

contains()

Does the queue contain the given datum?

Parameters:mixed
Return type:bool

1799.1.1.13. hasPriority

hasPriority()

Does the queue have an item with the given priority?

Parameters:int
Return type:bool

1799.1.1.14. getQueue

getQueue()

Get the inner priority queue instance

Return type:SplPriorityQueue

1799.1.1.15. __clone

__clone()

Add support for deep cloning

Return type:void

1799.1.2. Constants

1799.1.2.1. EXTR_DATA

1799.1.2.2. EXTR_PRIORITY

1799.1.2.3. EXTR_BOTH