Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58065 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48371 invoked from network); 25 Feb 2012 14:02:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2012 14:02:48 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.170 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.212.170 mail-wi0-f170.google.com Received: from [209.85.212.170] ([209.85.212.170:45393] helo=mail-wi0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/40-46034-60AE84F4 for ; Sat, 25 Feb 2012 09:02:47 -0500 Received: by wibhm4 with SMTP id hm4so2320106wib.29 for ; Sat, 25 Feb 2012 06:02:43 -0800 (PST) Received-SPF: pass (google.com: domain of ekneuss@gmail.com designates 10.180.101.228 as permitted sender) client-ip=10.180.101.228; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ekneuss@gmail.com designates 10.180.101.228 as permitted sender) smtp.mail=ekneuss@gmail.com; dkim=pass header.i=ekneuss@gmail.com Received: from mr.google.com ([10.180.101.228]) by 10.180.101.228 with SMTP id fj4mr4317873wib.4.1330178563070 (num_hops = 1); Sat, 25 Feb 2012 06:02:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=OW5aCJeehLbVQsl8oAVqv8k8U/5qq2uLZufuF5/3HGk=; b=jkF4JAqgeP4lorMt04HQ21vc6sAv8n+W5PFRBslM/julblJrIu8Irdf89yji593RQy Y+8kjnqD5VzNbkyQwSx0oMJREMQ39Y5r45AkJb3Yj4r5NSRSiKHXoumBfli5ai772E2l o7NLyeX2/3U29/dRYlC5IPg3+VhyyoWKUJh2U= MIME-Version: 1.0 Received: by 10.180.101.228 with SMTP id fj4mr3403312wib.4.1330178563007; Sat, 25 Feb 2012 06:02:43 -0800 (PST) Sender: ekneuss@gmail.com Received: by 10.223.115.10 with HTTP; Sat, 25 Feb 2012 06:02:42 -0800 (PST) In-Reply-To: <006601ccf3c0$68054cf0$380fe6d0$@alliantinternet.com> References: <006601ccf3c0$68054cf0$380fe6d0$@alliantinternet.com> Date: Sat, 25 Feb 2012 15:02:42 +0100 X-Google-Sender-Auth: hHrCXn6WOkcjN16oi43bEFd-zlo Message-ID: To: Dmitri Snytkine Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Is this correct behaviour with SplMinHeap? From: colder@php.net (Etienne Kneuss) 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 > { > =C2=A0 =C2=A0public function =C2=A0compare( $value1, $value2 ) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0return ( $value1 - $value2 ); > =C2=A0 =C2=A0} > } > > $obj =3D new MySimpleHeap(); > $obj->insert( 4 ); > $obj->insert( 8 ); > $obj->insert( 1 ); > $obj->insert( 0 ); > > foreach( $obj as $number ) { > =C2=A0 =C2=A0echo $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