Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64347 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96795 invoked from network); 18 Dec 2012 18:43:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Dec 2012 18:43:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=victor@suumit.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=victor@suumit.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain suumit.com from 98.139.213.129 cause and error) X-PHP-List-Original-Sender: victor@suumit.com X-Host-Fingerprint: 98.139.213.129 nm4-vm0.bullet.mail.bf1.yahoo.com Received: from [98.139.213.129] ([98.139.213.129:32919] helo=nm4-vm0.bullet.mail.bf1.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/2C-33799-859B0D05 for ; Tue, 18 Dec 2012 13:43:36 -0500 Received: from [98.139.212.145] by nm4.bullet.mail.bf1.yahoo.com with NNFMP; 18 Dec 2012 18:43:33 -0000 Received: from [76.13.13.92] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 18 Dec 2012 18:43:32 -0000 Received: from [127.0.0.1] by smtp109.prem.mail.ac4.yahoo.com with NNFMP; 18 Dec 2012 18:43:32 -0000 X-Yahoo-Newman-Id: 881863.37496.bm@smtp109.prem.mail.ac4.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 3Kd5EU4VM1khVnqEQricYO3_HRyd3rlxRPvAjZhuJAAOgJM dg_l8jOViVKwz2XIIEBHUS2FxagkTCKoonPJ95koafSyV07VtKXVBkKFyEyf dOC9aEzGxb15EHEGrB5ZtMH7ApE3xgtYpDqYRQbGx_zn3bVEYDuwpDkGiBeY B15Hq0JHR.g28IAp5.T0vz95HdbM8M0cDoa1eNW5UJkemNQC7LKbPajo2eaO aJ5HYbeW76yNBOniRxxC2vZzJThJz9DlJdfeW_2ZFFS3S660AmOxNutvGxbe ElOZ71N1XbfkL.iW3yYWL7eU0PO4NGJxShl3Pu8UFN4GbzLBdmzQdeEowbR3 Sqb4I2NR2zL0tVP8BEPTq6KD3NZ0mWTGohE264oaqWpItom54ewLCp_Ol2YC t2N_dt65k5k_xgqNVXiSOpk69ibjGAvTvXgZK70HX33Zo3OH0ADSLItRI15E S.acW6k72k0Ic.1.tI8zQ4XndNsBHXOdfMicrgw0VKg9vYtWkaIq8PSdbp7l vuE4KVPipKNsySCKmOBMCt1fyvbiHq1xTl2ry8D801K2ZwaPY9OPd9LJMNbg nFztxJ7TeseIHYFZPB17IzVTVhT45ZiDVUL2x4HXrWidVhRtKcfE.qNYiQQr sTDSIgg-- X-Yahoo-SMTP: JD6O2cuswBAWdaVT1ffr98ATm3fQ3wF_ou8N Received: from [192.168.0.10] (victor@82.236.98.234 with plain) by smtp109.prem.mail.ac4.yahoo.com with SMTP; 18 Dec 2012 10:43:32 -0800 PST Message-ID: <50D0B953.8010001@suumit.com> Date: Tue, 18 Dec 2012 19:43:31 +0100 Reply-To: victor@suumit.com Organization: Suumit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Anthony Ferrara CC: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= , "internals@lists.php.net" References: <50D08108.1020503@suumit.com> <50D0B162.90006@gmail.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------040302000003010306050503" Subject: Re: [PHP-DEV] How about implementing more data structures (ie Map, Set) From: victor@suumit.com (Victor Berchet) --------------040302000003010306050503 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I am happy to see some interest in this discussion, I'll try to give more details in the coming days. To clarify, my first example should be: $setA = new Set(); $setA->append('a'); $setA->append('a'); $setB = new Set(); $setB->append('a'); // 'a' instead of 'b' $setA == $setB; Cheers, Victor On 12/18/2012 07:32 PM, Anthony Ferrara wrote: > Guys, > > PHP arrays are a great one-size-fits-all data structure. But like all > one-size-fits-all , jack-of-all-trades usually means master > of none. > > There are definitely benefits to using specific data structures if > implemented correctly under the hood. > > A good example of this is a Queue. Implemented properly using a > Singly-Linked-List or Doubly-Linked-List, inserts are O(1), peeks are > O(1) and removals are O(1). Compare that to an array based > queue implementation where inserts are O(1) and peeks are O(1) but > removals are O(n)... (or inserts and removals are reversed). > > For low volume logic, the array can substitute for more custom data > structures quite easily. But for needs with more data (or more > transactions), there's no replacement for a proper data structure... > > > > To the original question: > > I would love to see not just more data structures, but better designed > ones in core. > > For example, with SPLStack http://php.net/manual/en/class.splstack.php > 1. Why the heck does it have unshift() as well as push()? A stack is a > One-way-in, one-way-out data structure, why are both exposed? > 2. Why the heck does it implement ArrayAccess? Again, completely > defeats the point of a stack > 3. Why does it *extend* DLL? A Stack can be implemented with a DLL, > but it is *not* a DLL. Huge difference... > > Now, there was some discussion by some of us about re-doing the entire > spl data structures a while ago. This git repo (PHP) is the evolution > of that idea. https://github.com/morrisonlevi/Ardent > > Now it's not written with the explicit intent of replacing SPL. It's > written in an attempt to try to get the data structures designed > right. Then, it may be ported to PECL, and then finally may be > proposed to core. > > > As far as MAP, we already have one: > http://php.net/manual/en/class.splobjectstorage.php If you give a closer look to my example, you will notice a difference: $map[$setA] and $map[$setB] point to the same storage which I think is not possible with SPLObjectStorage. > > My $0.02 at least, > > Anthony > --------------040302000003010306050503--