Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116071 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99792 invoked from network); 17 Sep 2021 12:36:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 12:36:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A343B1804B3 for ; Fri, 17 Sep 2021 06:16:25 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_HOTMAIL_RCVD2, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8075 40.80.0.0/12 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2087.outbound.protection.outlook.com [40.92.23.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 17 Sep 2021 06:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnZ/YqSbOKdj6PW3vevwEbzOPmLPBGxmpoeWqBA0pwFJu16HAC2ZN1kLZVzb27kDjJlM+qBVTvF+eOOKHD5sab3/c19U5aISrdtjXS9RKC2XkQxxrI7I4agExy6OxZhFGTwRgQEHNeWfnGeA9Rt0qrAu4bSASTXwcE8am87rN8Qn+yl6WnnmLobcH+uo2jx/BmPvpn4uvkksXpaCwzxVkTXv3+PUZOLdpFvIzeiuJsxORZzUIdp0x+Yo50KGRTi+zzB+p6AdMncW9/iKGLBuZ0MmLHkPKjIaiDm2aAZSzxoFLKwDI11VJ3Rw+8OgJrnLgsTCKOFBHpgNtJeplQsLSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Ypcnz85KASzdASVn42ebc0+WDCP+YcNck828sD6sRCY=; b=XEkEqo8UY+WmCb5gHBdWfS4xaKp4jsADTG/GNcPs28csjvxJa/6NM87DJCjnmCLgOMXVzVHNuwU1Ig1wAxtTZfp9aODMO26RaDfk38NiiCLjDEid6ZjDfUIMh8z4V35sdhtQyBS4shnT7XDeadBkO0R4qwPPD/F+vUfApK5tCg8xsBmE7b00r4HvqBvfWJQqeKj4WwiTWgkWxHeNcxJ4+kLDbLfFUZCUkM1LnPtMAXey8+tCO2e2/0cGhVKMAk89Cvd7FdE3cEMfw1Y0ROKxN1iimzCUpjKAuVmCD62ctGGoxfP17VKyuWA3DiYHOAZ6EJbGT1wLMZZpaPKzY90tGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ypcnz85KASzdASVn42ebc0+WDCP+YcNck828sD6sRCY=; b=ilnaNqUwiC2f40JckVotvBUeVmlH9XicWfwgJzk1k+mGRp1Dcg+RoECz+rUrCOs4/3TgBhKzP17P+q8WRc+juYNcxhLF1ztR5l3ubnB64ReOXsi4ZudJcvl5L2xzLbKZ87r6UeuIWhg809l54Q9ehfghggCQfe3JiqX1QAWFv2s6hSHJ+3djGqI6nkYRETHnxUZFiOSg+hym6LJZKy2LjijygBwoBbPmkR9rLuF3JdqloC1ruBrL85D1VN17rAxW9xbZlsTsKDqXiXGLcHtPiZ+b8xvsI6xKRWCWahb4DKXopruJr5hyqHDiLFnIjtdZFbRV3h3qA8TFOpVWsDGJdQ== Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2603:10b6:5:1cf::26) by DM6PR07MB8111.namprd07.prod.outlook.com (2603:10b6:5:1b8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Fri, 17 Sep 2021 13:16:23 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::7181:60db:c4d2:835]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::7181:60db:c4d2:835%7]) with mapi id 15.20.4523.017; Fri, 17 Sep 2021 13:16:23 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] RFC: Add `final class Vector` to PHP Thread-Index: AQHXq2Dr5ROExEhu802SAlX6zd1M+6unhrKAgAAIYYyAABhEgIAAiIpr Date: Fri, 17 Sep 2021 13:16:23 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: d3e1b61b-263c-64f3-060e-76ff72493088 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [206U5vVjx3DdfS3lpcWFyhrh9CqrovrJ5hKiNx7CeJEJnJd/UUy4GNAnyqA2Pm/A] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ebbc20ad-09fe-4dd8-e8d3-08d979dd58d8 x-ms-traffictypediagnostic: DM6PR07MB8111: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SxZzARBFY211ygKHlTELGvWgszktLitemf1Gn8hOuOb/71oOPpyURJxZiWLNt1b9/6x1aAbtSx/asr2Nbd8Y3cpvjhbA+4geeAOwXSA6RpcMnkaS/4A+kpDd0T8g8OIcBMEXgYVaIoqQAcqEgc8rTqpHmbMEIjHjpeNTXduBteCUf3rYvMfL8BNXrkBfb4pFG+1AmneGpILBv1yGrEpMd94Q9t6eJgiBSZzLeZrhUZPu6GuOu7/mlul4NTUW53NIf7m7aOHzoX9ma8oZD0GlQPLolSQQiV1H9unbKzYd3oKUz+vI75Bn70+xvfaglb4+wslDnTIhMWp5O06xcpDlgQmaYxMEUJ3HMXRLGXCnqJEJ+BqA+c7tX9/nAXXZtnw2tsuqBbHNHCB0fTzAsT/rA2GYimCVadmAW56WTkwNv8SEQmip/ULtlLJaZySpUjE0jas8x0K3j/8Qd9NL1Ne+2nL99PNEtobpTeCYXRUsEnI= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: NM/faDbxPhS/WmLXtXQcSYyXe8vsoIn9rxAVXhgN5B2GogaAMij9ajFmWnvN2FtTlkRdm2urmMrH9SncSwmgwioQbo540IgniaQU5+mIQ1skefusxTcE4UXkOr+0CuT7lF8utG9miHqygRmOUVVYVdgM/1mDNHoaw9ZOZ0fTWZoGAsKwGzX5lhm/EcZl0sqOya+baH7LGtogbXcDNf7kbw== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-35401.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR07MB6618.namprd07.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ebbc20ad-09fe-4dd8-e8d3-08d979dd58d8 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Sep 2021 13:16:23.4299 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB8111 Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: tysonandre775@hotmail.com (tyson andre) Hi Levi Morrison,=0A= =0A= > I mean that there isn't a way to provide a custom way to compare for=0A= > equality. One way to accomplish this is to have a signature like:=0A= > =0A= >=A0=A0=A0 function contains(T $value, ?callable(T, T):bool $comparator =3D= null): bool=0A= > =0A= > The same goes for `indexOf`.=0A= =0A= It'd make much more sense to have `->any(static fn($other): bool =3D> $comp= arator($value, $other)): ?:int`=0A= Overloading contains to do two different things (identity check or test the= result of a callable)=0A= seems like it's unintuitive to users.=0A= =0A= Since there is plenty of time to add more functionality,=0A= and I still haven't created the extended iterable library proposal,=0A= this currently only adds operations that are significantly more efficient i= nside the Vector=0A= (or have a return type of Vector) rather than going through the generic Ite= rator methods.=0A= =0A= > > > - I don't know what `setSize(int $size)` does. What does it do if the= =0A= > > > current size is less than `$size`? What about if its current size is= =0A= > > > greater? I suspect this is about capacity, not size, but without docs= =0A= > >=A0 > I am just guessing.=0A= > >=0A= > > It's the same behavior as https://www.php.net/manual/en/splfixedarray.s= etsize.php . It's about size, not capacity.=0A= > >=0A= > > > Change the size of an array to the new size of size.=0A= > > > If size is less than the current array size, any values after the new= size will be discarded.=0A= > > > If size is greater than the current array size, the array will be pad= ded with null values.=0A= > >=0A= > > I'd planned to add phpdoc documentation and examples before starting a = vote to document the behavior and thrown exceptions of the proposed methods= .=0A= > =0A= > I would rather see multiple methods like:=0A= > =A0=A0=A0 function truncateTo(int $size)=0A= > =A0=A0=A0 function padEnd(int $length, $value) // allows more than just n= ull=0A= > =A0=A0=A0 function padBeginning(int $length, $value)=0A= =0A= I'd consider this unfriendly to users (and personally consider it a poor de= sign) if we start with 3 or 4 different ways to change the size of the Vect= or.=0A= (Especially if English is a second language)=0A= =0A= A wide variety of programming languages such as Java, Rust, C++, etc. all u= se resize rather than truncateTo/padEnd,=0A= after what I assume is considerable discussion among language design expert= s in those languages.=0A= In the vast majority of cases, users know the exact size they want and don'= t care about the mechanism to set that.=0A= (And if the size is set larger or smaller in an `if{...}else{...}`, the exi= stence of setSize is still needed.=0A= Or if the user intends to reuse the allocated memory while overwriting all = values.)=0A= =0A= - Diverging from what end users are familiar with (without a strong reason = to) would also make it harder to start using `Vector`.=0A= =0A= I'd considered using a signature of `setSize(int $size, mixed $value =3D nu= ll)` to allow using something other than null=0A= but decided to leave that to a followup proposal if it passed.=0A= =0A= For now, I'd omitted ways to add to the start of the array because the line= ar time taken would be potentially objectionable,=0A= if people didn't imagine using it themselves or thought it'd be more approp= riate for end users to use a Deque.=0A= =0A= > And one or more for increasing/ensuring capacity without changing size.= =0A= =0A= setCapacity seems useful to me for reserving exactly the amount of memory n= eeded when the final size was known (e.g. setCapacity(2) to avoid over-allo= cating) but I was waiting to see if anyone else wanted that.=0A= =0A= Thanks,=0A= Tyson=0A=