3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Stdlib
;
15 * Serializable version of SplPriorityQueue
17 * Also, provides predictable heap order for datums added with the same priority
18 * (i.e., they will be emitted in the same order they are enqueued).
20 class SplPriorityQueue
extends \SplPriorityQueue
implements Serializable
23 * @var int Seed used to ensure queue order for items of the same priority
25 protected $serial = PHP_INT_MAX
;
28 * Insert a value with a given priority
30 * Utilizes {@var $serial} to ensure that values of equal priority are
31 * emitted in the same order in which they are inserted.
34 * @param mixed $priority
37 public function insert($datum, $priority)
39 if (!is_array($priority)) {
40 $priority = array($priority, $this->serial
--);
42 parent
::insert($datum, $priority);
47 * Serialize to an array
49 * Array will be priority => data pairs
53 public function toArray()
56 foreach (clone $this as $item) {
68 public function serialize()
71 $clone->setExtractFlags(self
::EXTR_BOTH
);
74 foreach ($clone as $item) {
78 return serialize($data);
87 public function unserialize($data)
89 foreach (unserialize($data) as $item) {
90 $this->insert($item['data'], $item['priority']);