Req #60926 [Com]: LIFO/FIFO iterator modes for priority queues
Edit report at https://bugs.php.net/bug.php?id=60926&edit=1 ID: 60926 Comment by: franssen dot roland at gmail dot com Reported by:franssen dot roland at gmail dot com Summary:LIFO/FIFO iterator modes for priority queues Status: Open Type: Feature/Change Request Package:SPL related Operating System: Ubuntu PHP Version:5.4.0RC6 Block user comment: N Private report: N New Comment: Of course the idea initially was to avoid "arrays" here... not to end up using both. Think i'll have to bench; * object using array only (data + priority + order); no use fancy PHP 5.3 stuff ;-) * object using priority queue (data + priority) and array (order); not against semantics (?) * object extending priority queue and extra array internally (order); all logic nicely encapsulated in compare() / against semantics (?) Previous Comments: [2012-01-30 18:23:22] franssen dot roland at gmail dot com > "it really does not matter which one comes first" So why cant we control it then? ;-) However, you probably mean you shouldn't have to rely on it. Which makes sense. Still.. i was so close with a out-of-the-box event listener data structure ^^ I guess i'll compose the priority queue for internal usage and store the order of shared priorities myself. It can be done. [2012-01-30 03:09:10] carloschilazo at gmail dot com I believe this goes against the definition of a priority queue, if you insert them with the same priority then it really does not matter which one comes first... I understand what you are asking, but if you need them like that then you could maybe use another data structure or a mixture, or user different priorities.. [2012-01-29 19:31:07] franssen dot roland at gmail dot com Description: PHP version is actually PHP5.4RC3 It would be nice to be able to maintain the input order in a SPL priority queue when multiple values share the same priority. E.g. FIFO and LIFO The current "mode" is neither one of these. I guess this is best peformance-wise but sometimes you want to be explicitly, for instance when registering event listeners; you expect them to run in order. Test script: --- insert('a', 100); $queue->insert('b', 100); $queue->insert('c', 110); $queue->insert('d', 90); foreach($queue as $element) { var_dump($element); echo ''; } echo ''; $queue2 = new \SplPriorityQueue; $queue2->insert('a', 100); $queue2->insert('b', 100); foreach($queue2 as $element) { var_dump($element); echo ''; } Expected result: string(1) "c" string(1) "a" string(1) "b" string(1) "d" string(1) "a" string(1) "b" Actual result: -- string(1) "c" string(1) "b" string(1) "a" string(1) "d" string(1) "a" string(1) "b" -- Edit this bug report at https://bugs.php.net/bug.php?id=60926&edit=1
Req #60926 [Com]: LIFO/FIFO iterator modes for priority queues
Edit report at https://bugs.php.net/bug.php?id=60926&edit=1 ID: 60926 Comment by: franssen dot roland at gmail dot com Reported by:franssen dot roland at gmail dot com Summary:LIFO/FIFO iterator modes for priority queues Status: Open Type: Feature/Change Request Package:SPL related Operating System: Ubuntu PHP Version:5.4.0RC6 Block user comment: N Private report: N New Comment: > "it really does not matter which one comes first" So why cant we control it then? ;-) However, you probably mean you shouldn't have to rely on it. Which makes sense. Still.. i was so close with a out-of-the-box event listener data structure ^^ I guess i'll compose the priority queue for internal usage and store the order of shared priorities myself. It can be done. Previous Comments: [2012-01-30 03:09:10] carloschilazo at gmail dot com I believe this goes against the definition of a priority queue, if you insert them with the same priority then it really does not matter which one comes first... I understand what you are asking, but if you need them like that then you could maybe use another data structure or a mixture, or user different priorities.. [2012-01-29 19:31:07] franssen dot roland at gmail dot com Description: PHP version is actually PHP5.4RC3 It would be nice to be able to maintain the input order in a SPL priority queue when multiple values share the same priority. E.g. FIFO and LIFO The current "mode" is neither one of these. I guess this is best peformance-wise but sometimes you want to be explicitly, for instance when registering event listeners; you expect them to run in order. Test script: --- insert('a', 100); $queue->insert('b', 100); $queue->insert('c', 110); $queue->insert('d', 90); foreach($queue as $element) { var_dump($element); echo ''; } echo ''; $queue2 = new \SplPriorityQueue; $queue2->insert('a', 100); $queue2->insert('b', 100); foreach($queue2 as $element) { var_dump($element); echo ''; } Expected result: string(1) "c" string(1) "a" string(1) "b" string(1) "d" string(1) "a" string(1) "b" Actual result: -- string(1) "c" string(1) "b" string(1) "a" string(1) "d" string(1) "a" string(1) "b" -- Edit this bug report at https://bugs.php.net/bug.php?id=60926&edit=1
Req #60926 [Com]: LIFO/FIFO iterator modes for priority queues
Edit report at https://bugs.php.net/bug.php?id=60926&edit=1 ID: 60926 Comment by: carloschilazo at gmail dot com Reported by:franssen dot roland at gmail dot com Summary:LIFO/FIFO iterator modes for priority queues Status: Open Type: Feature/Change Request Package:SPL related Operating System: Ubuntu PHP Version:5.4.0RC6 Block user comment: N Private report: N New Comment: I believe this goes against the definition of a priority queue, if you insert them with the same priority then it really does not matter which one comes first... I understand what you are asking, but if you need them like that then you could maybe use another data structure or a mixture, or user different priorities.. Previous Comments: [2012-01-29 19:31:07] franssen dot roland at gmail dot com Description: PHP version is actually PHP5.4RC3 It would be nice to be able to maintain the input order in a SPL priority queue when multiple values share the same priority. E.g. FIFO and LIFO The current "mode" is neither one of these. I guess this is best peformance-wise but sometimes you want to be explicitly, for instance when registering event listeners; you expect them to run in order. Test script: --- insert('a', 100); $queue->insert('b', 100); $queue->insert('c', 110); $queue->insert('d', 90); foreach($queue as $element) { var_dump($element); echo ''; } echo ''; $queue2 = new \SplPriorityQueue; $queue2->insert('a', 100); $queue2->insert('b', 100); foreach($queue2 as $element) { var_dump($element); echo ''; } Expected result: string(1) "c" string(1) "a" string(1) "b" string(1) "d" string(1) "a" string(1) "b" Actual result: -- string(1) "c" string(1) "b" string(1) "a" string(1) "d" string(1) "a" string(1) "b" -- Edit this bug report at https://bugs.php.net/bug.php?id=60926&edit=1