1 | <?php |
||
27 | trait PriorityQueueTrait |
||
28 | { |
||
29 | /** |
||
30 | * inner data storage |
||
31 | * |
||
32 | * @var array |
||
33 | * @access protected |
||
34 | */ |
||
35 | protected $queue = []; |
||
36 | |||
37 | /** |
||
38 | * marker for sorted queue |
||
39 | * |
||
40 | * @var bool |
||
41 | * @access protected |
||
42 | */ |
||
43 | protected $sorted = false; |
||
44 | |||
45 | /** |
||
46 | * priority counter, descreasing |
||
47 | * |
||
48 | * @var int |
||
49 | * @access protected |
||
50 | */ |
||
51 | protected $counter = 10000000; |
||
52 | |||
53 | /** |
||
54 | * {@inheritDoc} |
||
55 | * |
||
56 | * @since 2.0.21 added extra data |
||
57 | */ |
||
58 | public function insert($data, /*# int */ $priority = 0, $extra = null) |
||
79 | |||
80 | /** |
||
81 | * {@inheritDoc} |
||
82 | */ |
||
83 | public function remove($data) |
||
93 | |||
94 | /** |
||
95 | * {@inheritdic} |
||
96 | */ |
||
97 | public function flush() |
||
102 | |||
103 | /** |
||
104 | * {@inheritDoc} |
||
105 | */ |
||
106 | public function combine( |
||
119 | |||
120 | /** |
||
121 | * {@inheritDoc} |
||
122 | */ |
||
123 | public function count() |
||
127 | |||
128 | /** |
||
129 | * {@inheritDoc} |
||
130 | */ |
||
131 | public function getIterator() |
||
139 | |||
140 | /** |
||
141 | * Make sure priority in the range of -100 - +100 |
||
142 | * |
||
143 | * @param int $priority |
||
144 | * @return int |
||
145 | * @access protected |
||
146 | */ |
||
147 | protected function fixPriority(/*# int */ $priority)/*# : int */ |
||
151 | |||
152 | /** |
||
153 | * Generate one int base on the priority |
||
154 | * |
||
155 | * @param int $priority |
||
156 | * @return int |
||
157 | * @access protected |
||
158 | */ |
||
159 | protected function generateKey(/*# int */ $priority)/*# : int */ |
||
163 | |||
164 | /** |
||
165 | * Sort the queue from higher to lower int $key |
||
166 | * |
||
167 | * @return $this |
||
168 | * @access protected |
||
169 | */ |
||
170 | protected function sortQueue() |
||
178 | } |
||
179 |