Stdlib/PriorityQueue.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Stdlib  

\Zend_Stdlib_PriorityQueue

Package: Zend_Stdlib
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.
Implements
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

>VConstant  EXTR_DATA = 1
>VConstant  EXTR_PRIORITY = 2
>VConstant  EXTR_BOTH = 3

Properties

>VPropertyprotectedarray $items = array()
Actual items aggregated in the priority queue. Each item is an array with keys "data" and "priority".
Default valuearray()Details
Type
array
>VPropertyprotected\SplPriorityQueue $queue
Inner queue object
>VPropertyprotectedstring $queueClass = 'Zend_Stdlib_SplPriorityQueue'
Inner queue class to use for iteration
Default value'Zend_Stdlib_SplPriorityQueue'Details
Type
string

Methods

methodpubliccontains(mixed $datum) : bool

Does the queue contain the given datum?

Parameters
NameTypeDescription
$datummixed
Returns
TypeDescription
bool
methodpubliccount() : int

How many items are in the queue?

Returns
TypeDescription
int
methodpublicextract() : mixed

Extract a node from the inner queue and sift up

Returns
TypeDescription
mixed
methodpublicgetIterator() : \SplPriorityQueue

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.
Returns
TypeDescription
\SplPriorityQueue
methodprotectedgetQueue() : \Zend_Stdlib_SplPriorityQueue

Get the inner priority queue instance

Returns
TypeDescription
\Zend_Stdlib_SplPriorityQueue
methodpublichasPriority(int $priority) : bool

Does the queue have an item with the given priority?

Parameters
NameTypeDescription
$priorityint
Returns
TypeDescription
bool
methodpublicinsert(mixed $data, int $priority = 1) : \Zend_Stdlib_PriorityQueue

Insert an item into the queue

Priority defaults to 1 (low priority) if none provided.
Parameters
NameTypeDescription
$datamixed
$priorityint
Returns
TypeDescription
\Zend_Stdlib_PriorityQueue
methodpublicisEmpty() : bool

Is the queue empty?

Returns
TypeDescription
bool
methodpublicremove(mixed $datum) : boolean

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
NameTypeDescription
$datummixed
Returns
TypeDescription
booleanFalse if the item was not found, true otherwise.
methodpublicreturnData(array $item) : mixed

Return data from an internal item

Used as a lambda in toArray().
Parameters
NameTypeDescription
$itemarray
Returns
TypeDescription
mixed
methodpublicreturnPriority(array $item) : mixed

Return priority from an internal item

Used as a lambda in toArray().
Parameters
NameTypeDescription
$itemarray
Returns
TypeDescription
mixed
methodpublicserialize() : string

Serialize the data structure

Returns
TypeDescription
string
methodpublicsetInternalQueueClass(string $class) : \Zend_Stdlib_PriorityQueue

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
NameTypeDescription
$classstring
Returns
TypeDescription
\Zend_Stdlib_PriorityQueue
methodpublictoArray(int $flag = self::EXTR_DATA) : array

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
NameTypeDescription
$flagint
Returns
TypeDescription
array
methodpublictop() : mixed

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

Returns
TypeDescription
mixed
methodpublicunserialize(string $data) : void

Unserialize a string into a Zend_Stdlib_PriorityQueue object

Serialization format is compatible with {@link Zend_Stdlib_SplPriorityQueue}
Parameters
NameTypeDescription
$datastring
Documentation was generated by phpDocumentor 2.2.0 .