Bug #53710 [Opn->Asn]: Data registered with equal priority not returned in expected order
Edit report at http://bugs.php.net/bug.php?id=53710&edit=1
ID: 53710
Updated by: felipe@php.net
Reported by: weierophinney@php.net
Summary: Data registered with equal priority not returned in
expected order
-Status: Open
+Status: Assigned
Type: Bug
Package: SPL related
Operating System: Linux 32-bit
PHP Version: 5.3.5
-Assigned To:
+Assigned To: colder
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2011-01-10 22:23:46] weierophinney@php.net
Description:
------------
SplPriorityQueue does not behave as expected when data is registered
with equal
priority. One would expect one of the following situations:
* The data retain the same order as how they were registered
* The data are ordered based on value
Neither of these are the case, however. From empirical analysis, it
appears that
the following happens:
* The first item registered at that priority will always be the first
returned
* The remaining items are returned in the reverse order in which they
were
enqueued.
Test script:
---------------
$queue = new SplPriorityQueue();
$queue->insert('foo', 100);
$queue->insert('bar', 100);
$queue->insert('baz', 100);
$queue->insert('bat', 100);
foreach ($queue as $data) {
echo $data, "\n";
}
Expected result:
----------------
// IDEALLY order in which they are registered:
foo
bar
baz
bat
// OR following same rules as priority queue -- higher values == higher
priority
foo
baz
bat
bar
Actual result:
--------------
foo
bat
baz
bar
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53710&edit=1
Thread (4 messages)