Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64346 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94953 invoked from network); 18 Dec 2012 18:32:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Dec 2012 18:32:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.53 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.53 mail-vb0-f53.google.com Received: from [209.85.212.53] ([209.85.212.53:64272] helo=mail-vb0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/CB-33799-4B6B0D05 for ; Tue, 18 Dec 2012 13:32:21 -0500 Received: by mail-vb0-f53.google.com with SMTP id b23so1239595vbz.26 for ; Tue, 18 Dec 2012 10:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=1NREUM9WZbWAdRYjqFjlKsA1vf+q7tD/CTr4HxuvQdM=; b=ZzGYmYoS8dyPWcBDTJs1j/EbghVVyDQV3+KS4vifuyutv1BlF490zBRiYddQAFyPlL uSJy5IzDEuax1hqHFSlNqw0xksW44edcEIIOu3chGxAN+HLsYqhIUtkloQfb/G4t/8ap aBxvtX0L1iX+fL5fLjJeqJEKwiL4pirUQHJi+zIjyNCuvkVkg9upM0AhHIIGfhtLn9Lx Rh4aKVIJaaVP2FpOjsaWV0QpfN6NZW4AFOz3DfAkS4uQtRUAWDS5itwPMQ1wccN3Ygfy FGkeBY79sWqhfoAqA6XJe5vhCp5cavC8bkzTsZGlnMbYOm3OK5M7oRVb0xcJ0bDCTB/N 1Ijw== MIME-Version: 1.0 Received: by 10.52.68.4 with SMTP id r4mr4037019vdt.15.1355855537601; Tue, 18 Dec 2012 10:32:17 -0800 (PST) Received: by 10.58.200.130 with HTTP; Tue, 18 Dec 2012 10:32:17 -0800 (PST) In-Reply-To: <50D0B162.90006@gmail.com> References: <50D08108.1020503@suumit.com> <50D0B162.90006@gmail.com> Date: Tue, 18 Dec 2012 13:32:17 -0500 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: victor@suumit.com, "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec50166adaf7bde04d124b723 Subject: Re: [PHP-DEV] How about implementing more data structures (ie Map, Set) From: ircmaxell@gmail.com (Anthony Ferrara) --bcaec50166adaf7bde04d124b723 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 My $0.02 at least, Anthony On Tue, Dec 18, 2012 at 1:09 PM, =C1ngel Gonz=E1lez wro= te: > On 18/12/12 15:43, Victor Berchet wrote: > > Dear all: > > > > I would like to get your feedback on implementing some more data > > structure in the PHP core. > (...) > > I think this could be summarised as "allow objects as keys for arrays". > Which would give the Map behavior. > Implementing Set from that is straightforward. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --bcaec50166adaf7bde04d124b723--