Bug #53588 [Csd->Bgs]: SplMinHeap bad insert sort
Edit report at http://bugs.php.net/bug.php?id=53588&edit=1
ID: 53588
Updated by: cataphract@php.net
Reported by: ojousset49 at yahoo dot fr
Summary: SplMinHeap bad insert sort
-Status: Closed
+Status: Bogus
Type: Bug
Package: SPL related
Operating System: RHEL 55 64bits
PHP Version: 5.3.4
Assigned To: cataphract
Block user comment: N
Private report: N
New Comment:
Reverted change and closing as bogus.
Turns out the semantics of SplMinHeap::compare() and
SplMaxHeap::compare() are different. See:
http://docs.php.net/manual/en/splminheap.compare.php
http://docs.php.net/manual/en/splmaxheap.compare.php
Previous Comments:
------------------------------------------------------------------------
[2010-12-21 18:29:29] cataphract@php.net
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
------------------------------------------------------------------------
[2010-12-21 18:29:16] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=306542
Log: - Fixed bug #53588 (SplMinHeap bad sorting with custom compare
function).
------------------------------------------------------------------------
[2010-12-21 14:50:45] ojousset49 at yahoo dot fr
Description:
------------
SplMinHeap have the same behavior than SplMaxHeap when inserting data.
Top value of a SplMinHeap object is the max value instead of the min
Test script:
---------------
class MySimpleHeap extends SplMinHeap{
public function compare( $value1, $value2 ){
return ( $value1 - $value2 );
}
}
$obj = new MySimpleHeap();
$obj->insert( 8 );
$obj->insert( 0 );
$obj->insert( 4 );
foreach( $obj as $number ) {
echo $number."\n";
}
// Output display : 8, 4, 0 instead of 0, 4, 8
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53588&edit=1
Thread (3 messages)