Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Stdlib_PriorityQueue Class Reference

Public Member Functions

 insert ($data, $priority=1)
 Insert an item into the queue.
 
 remove ($datum)
 Remove an item from the queue.
 
 isEmpty ()
 Is the queue empty?
 
 count ()
 How many items are in the queue?
 
 top ()
 Peek at the top node in the queue, based on priority.
 
 extract ()
 Extract a node from the inner queue and sift up.
 
 getIterator ()
 Retrieve the inner iterator.
 
 serialize ()
 Serialize the data structure.
 
 unserialize ($data)
 Unserialize a string into a Zend_Stdlib_PriorityQueue object.
 
 toArray ($flag=self::EXTR_DATA)
 Serialize to an array.
 
 setInternalQueueClass ($class)
 Specify the internal queue class.
 
 contains ($datum)
 Does the queue contain the given datum?
 
 hasPriority ($priority)
 Does the queue have an item with the given priority?
 
 returnPriority ($item)
 Return priority from an internal item.
 
 returnData ($item)
 Return data from an internal item.
 

Public Attributes

const EXTR_DATA = 0x00000001
 
const EXTR_PRIORITY = 0x00000002
 
const EXTR_BOTH = 0x00000003
 

Protected Member Functions

 getQueue ()
 Get the inner priority queue instance.
 

Protected Attributes

 $queueClass = 'Zend_Stdlib_SplPriorityQueue'
 
 $items = array()
 
 $queue
 

Member Function Documentation

contains (   $datum)

Does the queue contain the given datum?

Parameters
mixed$datum
Returns
bool
count ( )

How many items are in the queue?

Returns
int
extract ( )

Extract a node from the inner queue and sift up.

Returns
mixed
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.

Returns
SplPriorityQueue
getQueue ( )
protected

Get the inner priority queue instance.

Returns
Zend_Stdlib_SplPriorityQueue
hasPriority (   $priority)

Does the queue have an item with the given priority?

Parameters
int$priority
Returns
bool
insert (   $data,
  $priority = 1 
)

Insert an item into the queue.

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

Parameters
mixed$data
int$priority
Returns
Zend_Stdlib_PriorityQueue
isEmpty ( )

Is the queue empty?

Returns
bool
remove (   $datum)

Remove an item from the queue.

This is different than 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$datum
Returns
boolean False if the item was not found, true otherwise.
returnData (   $item)

Return data from an internal item.

Used as a lambda in toArray().

Parameters
array$item
Returns
mixed
returnPriority (   $item)

Return priority from an internal item.

Used as a lambda in toArray().

Parameters
array$item
Returns
mixed
serialize ( )

Serialize the data structure.

Returns
string
setInternalQueueClass (   $class)

Specify the internal queue class.

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

Parameters
string$class
Returns
Zend_Stdlib_PriorityQueue
toArray (   $flag = self::EXTR_DATA)

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$flag
Returns
array
top ( )

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

Returns
mixed
unserialize (   $data)

Unserialize a string into a Zend_Stdlib_PriorityQueue object.

Serialization format is compatible with Zend_Stdlib_SplPriorityQueue

Parameters
string$data
Returns
void

Member Data Documentation

$items = array()
protected
$queue
protected
$queueClass = 'Zend_Stdlib_SplPriorityQueue'
protected
const EXTR_BOTH = 0x00000003
const EXTR_DATA = 0x00000001
const EXTR_PRIORITY = 0x00000002