Source of file SplPriorityQueue.php
Size: 2,145 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Stdlib/SplPriorityQueue.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Stdlib; use Serializable; /** * 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). */ 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 = array($priority, $this->serial--); } parent::insert($datum, $priority); } /** * Serialize to an array * * Array will be priority => data pairs * * @return array */ public function toArray() { $array = 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 = array(); 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']); } } } |