Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64343 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78967 invoked from network); 18 Dec 2012 15:21:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Dec 2012 15:21:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=wfitch@meetme.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=wfitch@meetme.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain meetme.com designates 74.125.149.149 as permitted sender) X-PHP-List-Original-Sender: wfitch@meetme.com X-Host-Fingerprint: 74.125.149.149 na3sys009aog123.obsmtp.com Linux 2.5 (sometimes 2.4) (4) Received: from [74.125.149.149] ([74.125.149.149:41019] helo=na3sys009aog123.obsmtp.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/1A-33799-AE980D05 for ; Tue, 18 Dec 2012 10:21:16 -0500 Received: from mail-qc0-f198.google.com ([209.85.216.198]) (using TLSv1) by na3sys009aob123.postini.com ([74.125.148.12]) with SMTP ID DSNKUNCJ56DV5SbpwxZ+PpYlkcOJMVefMFpk@postini.com; Tue, 18 Dec 2012 07:21:15 PST Received: by mail-qc0-f198.google.com with SMTP id l35so1127387qco.5 for ; Tue, 18 Dec 2012 07:21:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to:x-mailer:x-gm-message-state; bh=kBTUxHKAOex3kQDZSj80JRW3nRLgGdBMmeO27KympU8=; b=XNrYBKn9Zy9Mjb8BnpJB9KaisdcWWy/PWVk3o6e3PNug/ZQ+1IwUMl7S2f71FVlU3p by5CNXXdsiKshMXgrCAsNJuI2TLGhpveeaKvdkaTvjcn0sWx1vpBA97TDYUvQ0DfCcSY 6xrFPFU4mzcRHkrJ+WhjpDyZ5k06naBwd5Prg995hNh1VuQBWaZE12kDTkTvEpAMdhIe VAGrrDp54mYrJejdamPUoVf/MwEoAQrnUOcGt5azmdchX3mIF3dX55fbNkC0tVCVfGa1 p5xNICPNp1W8FrB8hcZ+PPe86e4laA0D6mxY/OOmDDs7u8fNnd20qmQS0gaUOY4ohomd MwhQ== X-Received: by 10.49.131.67 with SMTP id ok3mr1099664qeb.42.1355844070905; Tue, 18 Dec 2012 07:21:10 -0800 (PST) X-Received: by 10.49.131.67 with SMTP id ok3mr1099661qeb.42.1355844070829; Tue, 18 Dec 2012 07:21:10 -0800 (PST) Received: from [192.168.110.198] ([204.145.120.11]) by mx.google.com with ESMTPS id cs3sm556621qab.10.2012.12.18.07.21.09 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 18 Dec 2012 07:21:10 -0800 (PST) Sender: Will Fitch Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) In-Reply-To: <50D08108.1020503@suumit.com> Date: Tue, 18 Dec 2012 10:21:10 -0500 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <50D08108.1020503@suumit.com> To: victor@suumit.com X-Mailer: Apple Mail (2.1499) X-Gm-Message-State: ALoCoQnUae4ZlBH4w2oMmS/A2NTDmziQEDsEGRWjMb2KzlTpxr0zi9K7PS/4yhz7MnQbYUYUF5l15RPYpxOBF/K6igI9vwvZapsa94i5CEy4VY59vChENIrGy1En4GBW4p+rSPhAloLHljGzM6LSK3ZMiOB5BntrYW8AylTeC/2NzmxYGCEV1mk= Subject: Re: [PHP-DEV] How about implementing more data structures (ie Map, Set) From: willfitch@php.net (William Fitch) On Dec 18, 2012, at 9:43 AM, Victor Berchet wrote: > Dear all: >=20 > I would like to get your feedback on implementing some more data = structure in the PHP core. >=20 > Things like Set, Map could be really helpful. >=20 > A Set would be an unordered collection with no duplicate elements = (same as in Python) >=20 > $setA =3D new Set(); > $setA->append('a'); > $setA->append('a'); >=20 > $setB =3D new Set(); > $setB->append('b'); >=20 > $setA =3D=3D $setB; >=20 > // A set can hold objects > $set->append($object); >=20 > A Map would be an associative array that can hold objects (same as = Python dictionaries) >=20 > $map=3D new Map(); >=20 > $map[$setA] =3D 'Hello, world!'; > echo $maps[$setB]; // Hello, world ! Most of what you're looking for can be accomplished by implementing = ArrayAccess in your own classes, or using the ArrayObject generically = like so: php > $obj =3D new ArrayObject(array()); php > $obj->append('some string'); php > $obj->append(new ArrayObject(array())); php > var_dump($obj[1]); class ArrayObject#4 (0) { } php > var_dump($obj[0]); string(11) "some string" For the duplicate issue you're referring to, you'd need to implement = your own methods for removing (e.g. array_unique). >=20 > I can not really help with the implementation, however I could help = defining the API, creating a test suite and docs should this idea be = accepted. >=20 > Note: I had to implement this in PHP while working on Automaton, it's = tedious and inefficient. >=20 > Thanks for your feedback, > Victor >=20 >=20 >=20