1 | <?php |
||
28 | trait PriorityQueueTrait |
||
29 | { |
||
30 | /** |
||
31 | * inner data storage |
||
32 | * |
||
33 | * @var array |
||
34 | * @access protected |
||
35 | */ |
||
36 | protected $queue = []; |
||
37 | |||
38 | /** |
||
39 | * marker for sorted queue |
||
40 | * |
||
41 | * @var bool |
||
42 | * @access protected |
||
43 | */ |
||
44 | protected $sorted = false; |
||
45 | |||
46 | /** |
||
47 | * priority counter, descreasing |
||
48 | * |
||
49 | * @var int |
||
50 | * @access protected |
||
51 | */ |
||
52 | protected $counter = 10000000; |
||
53 | |||
54 | /** |
||
55 | * {@inheritDoc} |
||
56 | */ |
||
57 | public function insert($data, /*# int */ $priority = 0) |
||
76 | |||
77 | /** |
||
78 | * {@inheritDoc} |
||
79 | */ |
||
80 | public function remove($data) |
||
90 | |||
91 | /** |
||
92 | * {@inheritdic} |
||
93 | */ |
||
94 | public function flush() |
||
99 | |||
100 | /** |
||
101 | * {@inheritDoc} |
||
102 | */ |
||
103 | public function combine( |
||
116 | |||
117 | /** |
||
118 | * {@inheritDoc} |
||
119 | */ |
||
120 | public function count() |
||
124 | |||
125 | /** |
||
126 | * {@inheritDoc} |
||
127 | */ |
||
128 | public function getIterator() |
||
136 | |||
137 | /** |
||
138 | * Make sure priority in the range of -100 - +100 |
||
139 | * |
||
140 | * @param int $priority |
||
141 | * @return int |
||
142 | * @access protected |
||
143 | */ |
||
144 | protected function fixPriority(/*# int */ $priority)/*# : int */ |
||
148 | |||
149 | /** |
||
150 | * Generate one int base on the priority |
||
151 | * |
||
152 | * @param int $priority |
||
153 | * @return int |
||
154 | * @access protected |
||
155 | */ |
||
156 | protected function generateKey(/*# int */ $priority)/*# : int */ |
||
160 | |||
161 | /** |
||
162 | * Sort the queue from higher to lower int $key |
||
163 | * |
||
164 | * @return $this |
||
165 | * @access protected |
||
166 | */ |
||
167 | protected function sortQueue() |
||
175 | } |
||
176 | |||
177 |