php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53588 SplMinHeap bad insert sort
Submitted: 2010-12-21 14:50 UTC Modified: 2010-12-21 20:53 UTC
From: ojousset49 at yahoo dot fr Assigned: cataphract (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.3.4 OS: RHEL 55 64bits
Private report: No CVE-ID: None
 [2010-12-21 14:50 UTC] 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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-21 17:01 UTC] cataphract@php.net
-Assigned To: +Assigned To: cataphract
 [2010-12-21 18:29 UTC] 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 18:29 UTC] cataphract@php.net
-Status: Assigned +Status: Closed -Type: Feature/Change Request +Type: Bug
 [2010-12-21 18:29 UTC] 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 20:53 UTC] cataphract@php.net
-Status: Closed +Status: Bogus
 [2010-12-21 20:53 UTC] cataphract@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC