Re: svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/spl/spl_heap.c branches/PHP_5_3/ext/spl/tests/bug53588.phpt trunk/ext/spl/spl_heap.c
trunk/ext/spl/tests/bug53588.phpt

From: Date: Tue, 21 Dec 2010 18:52:07 +0000
Subject: Re: svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/spl/spl_heap.c branches/PHP_5_3/ext/spl/tests/bug53588.phpt trunk/ext/spl/spl_heap.c
trunk/ext/spl/tests/bug53588.phpt
References: 1 2 3  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-64192@lists.php.net to get a copy of this message
On 12/21/2010 10:47 AM, Gustavo Lopes wrote:
On Tue, 21 Dec 2010 18:23:11 -0000, Christopher Jones <christopher.jones@oracle.com> wrote:
Hi Gustavo, Can you review the definition of http://www.php.net/manual/en/splminheap.compare.php ? I believe the testcase should have the operands reversed to satisfy this definition and so the bug was bogus.
I did. The definition says compare() should give a positive number if $value1 is larger than $value2, which it does:
That's the definition for SplMaxHeap. The definition for SplMinHeap is "positive integer if value1 is lower than value2". See the link above. Chris
+<?php +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"; +} +--EXPECT-- +0 +4 +8 +
So this implementation of compare() gives the "usual order" and SplMinHeap should give the elements in the usual increasing order (the top should have the smallest). Moreover, without the change extending SplMinHeap or SplMaxHeap would give the same result.
-- Email: christopher.jones@oracle.com Tel: +1 650 506 8630 Blog: http://blogs.oracle.com/opal/

« previous php.cvs (#64192) next »