Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Stdlib / SplPriorityQueue.php
blob5baa967ff93f03e50a76f8d3ac16b874d27076aa
1 <?php
2 /**
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
8 */
10 namespace Zend\Stdlib;
12 use Serializable;
14 /**
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
22 /**
23 * @var int Seed used to ensure queue order for items of the same priority
25 protected $serial = PHP_INT_MAX;
27 /**
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.
33 * @param mixed $datum
34 * @param mixed $priority
35 * @return void
37 public function insert($datum, $priority)
39 if (!is_array($priority)) {
40 $priority = array($priority, $this->serial--);
42 parent::insert($datum, $priority);
46 /**
47 * Serialize to an array
49 * Array will be priority => data pairs
51 * @return array
53 public function toArray()
55 $array = array();
56 foreach (clone $this as $item) {
57 $array[] = $item;
59 return $array;
63 /**
64 * Serialize
66 * @return string
68 public function serialize()
70 $clone = clone $this;
71 $clone->setExtractFlags(self::EXTR_BOTH);
73 $data = array();
74 foreach ($clone as $item) {
75 $data[] = $item;
78 return serialize($data);
81 /**
82 * Deserialize
84 * @param string $data
85 * @return void
87 public function unserialize($data)
89 foreach (unserialize($data) as $item) {
90 $this->insert($item['data'], $item['priority']);