Zend Framework  3.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
FastPriorityQueue Class Reference

This is an efficient implementation of an integer priority queue in PHP. More...

Public Member Functions

 insert ($value, $priority)
 Insert an element in the queue with a specified priority.
 
 extract ()
 Extract an element in the queue according to the priority and the order of insertion.
 
 remove ($datum)
 Remove an item from the queue.
 
 count ()
 Get the total number of elements in the queue.
 
 current ()
 Get the current element in the queue.
 
 key ()
 Get the index of the current element in the queue.
 
 next ()
 Set the iterator pointer to the next element in the queue without removing the previous element.
 
 valid ()
 Check if the current iterator is valid.
 
 rewind ()
 Rewind the current iterator.
 
 toArray ()
 Serialize to an array.
 
 serialize ()
 Serialize.
 
 unserialize ($data)
 Deserialize.
 
 setExtractFlags ($flag)
 Set the extract flag.
 
 isEmpty ()
 Check if the queue is empty.
 
 contains ($datum)
 Does the queue contain the given datum?
 
 hasPriority ($priority)
 Does the queue have an item with the given priority?
 

Public Attributes

const EXTR_DATA = PhpSplPriorityQueue::EXTR_DATA
 
const EXTR_PRIORITY = PhpSplPriorityQueue::EXTR_PRIORITY
 
const EXTR_BOTH = PhpSplPriorityQueue::EXTR_BOTH
 

Protected Member Functions

 nextAndRemove ()
 Set the iterator pointer to the next element in the queue removing the previous element.
 

Protected Attributes

 $extractFlag = self::EXTR_DATA
 
 $values = []
 
 $priorities = []
 
 $subPriorities = []
 
 $maxPriority = 0
 
 $count = 0
 
 $index = 0
 
 $subIndex = 0
 

Detailed Description

This is an efficient implementation of an integer priority queue in PHP.

This class acts like a queue with insert() and extract(), removing the elements from the queue and it also acts like an Iterator without removing the elements. This behaviour can be used in mixed scenarios with high performance boost.

Member Function Documentation

contains (   $datum)

Does the queue contain the given datum?

Parameters
mixed$datum
Returns
bool
count ( )

Get the total number of elements in the queue.

Returns
integer
current ( )

Get the current element in the queue.

Returns
mixed
extract ( )

Extract an element in the queue according to the priority and the order of insertion.

Returns
mixed
hasPriority (   $priority)

Does the queue have an item with the given priority?

Parameters
int$priority
Returns
bool
insert (   $value,
  $priority 
)

Insert an element in the queue with a specified priority.

Parameters
mixed$value
integer$prioritya positive integer
isEmpty ( )

Check if the queue is empty.

Returns
boolean
key ( )

Get the index of the current element in the queue.

Returns
integer
next ( )

Set the iterator pointer to the next element in the queue without removing the previous element.

nextAndRemove ( )
protected

Set the iterator pointer to the next element in the queue removing the previous element.

remove (   $datum)

Remove an item from the queue.

This is different than extract(); its purpose is to dequeue an item.

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
bool False if the item was not found, true otherwise.
rewind ( )

Rewind the current iterator.

serialize ( )

Serialize.

Returns
string
setExtractFlags (   $flag)

Set the extract flag.

Parameters
integer$flag
toArray ( )

Serialize to an array.

Array will be priority => data pairs

Returns
array
unserialize (   $data)

Deserialize.

Parameters
string$data
Returns
void
valid ( )

Check if the current iterator is valid.

Returns
boolean

Member Data Documentation

$count = 0
protected
$extractFlag = self::EXTR_DATA
protected
$index = 0
protected
$maxPriority = 0
protected
$priorities = []
protected
$subIndex = 0
protected
$subPriorities = []
protected
$values = []
protected
const EXTR_BOTH = PhpSplPriorityQueue::EXTR_BOTH
const EXTR_DATA = PhpSplPriorityQueue::EXTR_DATA
const EXTR_PRIORITY = PhpSplPriorityQueue::EXTR_PRIORITY