Req #60926 [Com]: LIFO/FIFO iterator modes for priority queues

From: Date: Mon, 30 Jan 2012 03:09:10 +0000
Subject: Req #60926 [Com]: LIFO/FIFO iterator modes for priority queues
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166939@lists.php.net to get a copy of this message
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:
---------------
<?php
$queue = new \SplPriorityQueue;
$queue->insert('a', 100);
$queue->insert('b', 100);
$queue->insert('c', 110);
$queue->insert('d', 90);

foreach($queue as $element) {
    var_dump($element);
    echo '<br>';
}
echo '<br>';
$queue2 = new \SplPriorityQueue;
$queue2->insert('a', 100);
$queue2->insert('b', 100);

foreach($queue2 as $element) {
    var_dump($element);
    echo '<br>';
}

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


Thread (4 messages)

« previous php.bugs (#166939) next »