class SplPriorityQueue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-stdlib/src/SplPriorityQueue.php \Zend\Stdlib\SplPriorityQueue
Serializable version of SplPriorityQueue
Also, provides predictable heap order for datums added with the same priority (i.e., they will be emitted in the same order they are enqueued).
Hierarchy
- class \Zend\Stdlib\SplPriorityQueue implements \Serializable
- class \Zend\Stdlib\SplPriorityQueue implements \Serializable
Expanded class hierarchy of SplPriorityQueue
2 files declare their use of SplPriorityQueue
- ExtractPriorityQueue.php in vendor/
zendframework/ zend-stdlib/ benchmark/ ExtractPriorityQueue.php - InsertPriorityQueue.php in vendor/
zendframework/ zend-stdlib/ benchmark/ InsertPriorityQueue.php
File
- vendor/
zendframework/ zend-stdlib/ src/ SplPriorityQueue.php, line 20
Namespace
Zend\StdlibView source
class SplPriorityQueue extends \SplPriorityQueue implements Serializable {
/**
* @var int Seed used to ensure queue order for items of the same priority
*/
protected $serial = PHP_INT_MAX;
/**
* Insert a value with a given priority
*
* Utilizes {@var $serial} to ensure that values of equal priority are
* emitted in the same order in which they are inserted.
*
* @param mixed $datum
* @param mixed $priority
* @return void
*/
public function insert($datum, $priority) {
if (!is_array($priority)) {
$priority = [
$priority,
$this->serial--,
];
}
parent::insert($datum, $priority);
}
/**
* Serialize to an array
*
* Array will be priority => data pairs
*
* @return array
*/
public function toArray() {
$array = [];
foreach (clone $this as $item) {
$array[] = $item;
}
return $array;
}
/**
* Serialize
*
* @return string
*/
public function serialize() {
$clone = clone $this;
$clone
->setExtractFlags(self::EXTR_BOTH);
$data = [];
foreach ($clone as $item) {
$data[] = $item;
}
return serialize($data);
}
/**
* Deserialize
*
* @param string $data
* @return void
*/
public function unserialize($data) {
foreach (unserialize($data) as $item) {
$this
->insert($item['data'], $item['priority']);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SplPriorityQueue:: |
protected | property |
Overrides SplPriorityQueue:: |
1 |
SplPriorityQueue:: |
public | function |
Insert a value with a given priority Overrides SplPriorityQueue:: |
1 |
SplPriorityQueue:: |
public | function |
Serialize Overrides SplPriorityQueue:: |
1 |
SplPriorityQueue:: |
public | function |
Serialize to an array Overrides SplPriorityQueue:: |
1 |
SplPriorityQueue:: |
public | function |
Deserialize Overrides SplPriorityQueue:: |
1 |