Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71300 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10293 invoked from network); 20 Jan 2014 07:31:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2014 07:31:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=bof@bof.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bof@bof.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bof.de designates 80.242.145.70 as permitted sender) X-PHP-List-Original-Sender: bof@bof.de X-Host-Fingerprint: 80.242.145.70 mars.intermailgate.com Received: from [80.242.145.70] ([80.242.145.70:59103] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/81-02192-BC0DCD25 for ; Mon, 20 Jan 2014 02:31:25 -0500 Received: (qmail 21525 invoked by uid 1009); 20 Jan 2014 08:31:20 +0100 Received: from 209.85.128.48 by mars (envelope-from , uid 89) with qmail-scanner-1.25-st-qms (clamdscan: 0.96.2/18371. spamassassin: 3.3.1. perlscan: 1.25-st-qms. Clear:RC:1(209.85.128.48):. Processed in 0.068892 secs); 20 Jan 2014 07:31:20 -0000 X-Antivirus-MYDOMAIN-Mail-From: bof@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:1(209.85.128.48):. Processed in 0.068892 secs Process 21519) Received: from mail-qe0-f48.google.com (gmail@bof.de@209.85.128.48) by mars.intermailgate.com with RC4-SHA encrypted SMTP; 20 Jan 2014 08:31:19 +0100 Received: by mail-qe0-f48.google.com with SMTP id b4so1002612qen.7 for ; Sun, 19 Jan 2014 23:31:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=pGixjsNCmZ3slDG28tmIyaFFAo4EqcqQuY4cwpnaIAY=; b=LE0w9lnlS+QNYMyT7D83d81SHEMWcam6AP5wL0lRtszk2umF0+yn5cefdwRq/k5l3O /PQdLy4ArROrogYbG/xgJYF3J+77fkzpJcZR4xzYojv9mcaPsazM8Z9Sf/X0+Dv3jYsM HEUquw3DtWV5h4WdrnmkwQUvC9Fnnc1P7n9XVrVCg2DxVp6FEEsCBz1VOTHSmY07bvuG BnvVAk6i0nYMh3nm1l+U+Mz1S/3jctpoOq6nt0MJDhtgIjI2O7Ws2OP0KeMh+L9gHBGY x2IE80uIviCM8+07g/tkNkbrutQ125RYTnGLYAtdXOdyITSTY+moyM4/G2TIQ/dCzcYR rkcg== MIME-Version: 1.0 X-Received: by 10.140.22.145 with SMTP id 17mr24390369qgn.0.1390203077941; Sun, 19 Jan 2014 23:31:17 -0800 (PST) Received: by 10.140.84.175 with HTTP; Sun, 19 Jan 2014 23:31:17 -0800 (PST) Received: by 10.140.84.175 with HTTP; Sun, 19 Jan 2014 23:31:17 -0800 (PST) In-Reply-To: <52DCC067.9090603@garfieldtech.com> References: <002d01cf1234$01e6dc60$05b49520$@tutteli.ch> <004c01cf123d$35730870$a0591950$@tutteli.ch> <52D71748.1090402@googlemail.com> <52D71FAE.8030002@ajf.me> <005001cf124f$3a40df00$aec29d00$@tutteli.ch> <20140116110127.202079vzjsj76n7b@webmail.tutteli.ch> <0B.B1.24763.139B7D25@pb1.pair.com> <002001cf12da$2bfbda90$83f38fb0$@tutteli.ch> <52DCA3E7.80602@lerdorf.com> <52DCC067.9090603@garfieldtech.com> Date: Mon, 20 Jan 2014 08:31:17 +0100 Message-ID: To: Larry Garfield Cc: internals Content-Type: multipart/alternative; boundary=001a11c13010a0627404f061e0f4 Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: bof@bof.de (Patrick Schaaf) --001a11c13010a0627404f061e0f4 Content-Type: text/plain; charset=ISO-8859-1 Regarding the N*M checking complexity, couldn't a little bit of memory alleviate the problem? For each array, have a "member type" pointer, initially NULL. When the member type needs to be checked for the first time, and that "member type" pointer is not already set, do an O(N) scan of the arrray, testing compatibility of all members against the hinted type. Error on mismatch, but when all members match, remember the type behind the "member type" pointer. When the member type needs to be checked and the "member type" pointer _is_ set, just compare it to the hinted type O(1). There must be some overhead when elements are added to an array. Either "when member type is set, forget it", or even "when member type is already set, check compatiility of the newly added element with the member type, and then remove member type on mismatch or keep it on match". Finally when arrays are copied, and "member type" is already set, copy it along with the array, Optionally some of the array functions like array_merge might be made aware of the scheme, too. BTW, I'm undecided regarding the need for the overall feature, from my rather limited personal coding practise it seems to me that whenever I am interested in member type checking I'm already looping over the array and can easily add up-front instanceof checks to the loops with suitable explicit error-out. Which I generally prefer over automatic errors, especially fatal ones, because _I_ control the error case behaviour. But I think _if_ such a scheme were added, the implementation described above would solve the O(N*M) problem with acceptable overall cost. best regards Patrick --001a11c13010a0627404f061e0f4--