Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58066 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49891 invoked from network); 25 Feb 2012 14:08:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2012 14:08:45 -0000 Authentication-Results: pb1.pair.com header.from=dsnytkine@Ultralogistics.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dsnytkine@Ultralogistics.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain Ultralogistics.com from 64.197.110.172 cause and error) X-PHP-List-Original-Sender: dsnytkine@Ultralogistics.com X-Host-Fingerprint: 64.197.110.172 thrud.alliantinternet.com Received: from [64.197.110.172] ([64.197.110.172:38786] helo=thrud.alliantinternet.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/90-46034-C6BE84F4 for ; Sat, 25 Feb 2012 09:08:44 -0500 Received: by thrud.alliantinternet.com (Postfix, from userid 1001) id B2983174310; Sat, 25 Feb 2012 09:08:41 -0500 (EST) To: "'Etienne Kneuss'" Cc: References: <006601ccf3c0$68054cf0$380fe6d0$@alliantinternet.com> In-Reply-To: Date: Sat, 25 Feb 2012 09:08:40 -0500 Message-ID: <006801ccf3c6$fa0e3110$ee2a9330$@alliantinternet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thread-Index: AczzxiZjFA1TLp5rRraqEWbEonnH/AAAMW4w Content-Language: en-us Subject: RE: [PHP-DEV] Is this correct behaviour with SplMinHeap? From: dsnytkine@Ultralogistics.com ("Dmitri Snytkine") This makes sense.=20 Thank you. Dmitri Snytkine Web Developer Ultra Logistics, Inc. Phone: (888) 220-4640 x 2097 Fax: (888) 795-6642 E-Mail: dsnytkine@ultralogistics.com Web: www.ultralogistics.com "A Top 100 Logistics I.T. Provider in 2011" -----Original Message----- From: ekneuss@gmail.com [mailto:ekneuss@gmail.com] On Behalf Of Etienne = Kneuss Sent: Saturday, February 25, 2012 9:03 AM To: Dmitri Snytkine Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Is this correct behaviour with SplMinHeap? Hi, On Sat, Feb 25, 2012 at 14:21, Dmitri Snytkine wrote: > I am not sure if this is a bug or not, but something is strange with = this: > I run this little test script, this one is posted on php.net in = comments > section > > > class MySimpleHeap extends SplMaxHeap > { > public function compare( $value1, $value2 ) { > return ( $value1 - $value2 ); > } > } > > $obj =3D new MySimpleHeap(); > $obj->insert( 4 ); > $obj->insert( 8 ); > $obj->insert( 1 ); > $obj->insert( 0 ); > > foreach( $obj as $number ) { > echo $number."\n"; > } > > The output is 8 4 1 0 > Good. > Now I change the > class MySimpleHeap extends SplMaxHeap > to > class MySimpleHeap extends SplMinHeap > > run it again (now I expet to get lowest value first) and get exact = same > results back. > > Is this a bug? No, this is not a bug. SplMin/MaxHeap simply define their own compare method, but you overwrite it anyway. If you specify the compare method, I don't believe it is useful to extends SplMin/MaxHeap if you overwrite the compare method completely, you should extend SplHeap directly in such cases. Best, > > > > Dmitri Snytkine > Web Developer > Ultra Logistics, Inc. > Phone: (888) 220-4640 x 2097 > Fax: (888) 795-6642 > E-Mail: dsnytkine@ultralogistics.com > Web: www.ultralogistics.com > > "A Top 100 Logistics I.T. Provider in 2011" > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --=20 Etienne Kneuss http://www.colder.ch