Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116048 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10921 invoked from network); 17 Sep 2021 01:30:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 01:30:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C3C221804C0 for ; Thu, 16 Sep 2021 19:09:57 -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 NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2045.outbound.protection.outlook.com [40.92.18.45]) (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 ; Thu, 16 Sep 2021 19:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N/1/5okh0okAV8Z8vNdtnrolTKSIKcQGRX+j5CWpjUmvUwVlFKMrPd5tGA9cULOYuCU2eJ2CWPx1auScH5ihqEkRbHvmQpK8TbV+c9HXTUVdByaNFOVRjeGwo+W22vc29DoqH0J48CxctZjqc4jAcgSixs4fE/I/zVyGfF11uNVSs5o7fCmeaPYDEGV5dmvxcRqqsWdVPv3tAUvJagjI1CqxJzW0zI0wzlS4DSk8V88n9dAoRw3SvVuReFYbtVZ09INTUVYa8779e8//vAOl18Va3fYYBM9MQo4MrUm0CFxyKaMWH3WwlT3Pe7HtNaldZgCIGQKtrIQObDWaGYRYzA== 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=RbhJsMBOpi7/mLeIFWC7vvdH0RG+oBMEchvfn1BvjLQ=; b=O5pqCRO9qXY6AvmTqRU3xCJ1KBqvEmtdrcQZoD7uJrP4jfV9krNLMg4hO+7SGdD6QY2s0SWS8ZnfCUb5la6wRDHdRqTDbVD3772YW8JOsdo73CStVyYC1KeUwoYMRf5kd7Wy9c4E4/GicaV57IpAjSiqdc5wCGjyuujD7nEWiC4Nsr8WSll5Kee7miD5V0YmEB6eUI69zmqg8dHlf75Ky5gBfEdDOdIN/MVqvWIHi2+GtIbPHYLVrpicFmwiSYnKVlrWEPAOJFsMTSKN+5kOEMxF6P4ZOjq8DXTDVtSRXwBTF22CTTulJnXyMH4ZebiiY8us1tOPcKH5GmdyqdkNAA== 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=RbhJsMBOpi7/mLeIFWC7vvdH0RG+oBMEchvfn1BvjLQ=; b=EW/+/VZ8jQiBmMoNA6H4IBfBaDI9IFCLirzTkvrouyoB3F9wj2cHNLHQGgx9qX9mZSmvlz4M+zFAduOuhU/03vu0FnwioQW8lhCDNlqb0CDbU3rLU0sCbkXmP39El1NX1Divm10xmyr0EYMil9lC0JDF6GfYn9f/VKHotvpI4eDm4ISd384vYjJBsY191yru22UQgT1MtHb5KYZ9afyvEnLsbwmehneumSpD2JbLmqTUqyQY4aciZESCXzdq00k2+KpcVQpS2zDYafeU3fvLriSq7h4G9x8k0wLx+3z1qKgb3yRoUiyFUkzrYqUfHDuqMJxfaZwfWNk4fCfhCMU5pw== Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2603:10b6:5:1cf::26) by DM6PR07MB6506.namprd07.prod.outlook.com (2603:10b6:5:1ca::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 02:09:55 +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.016; Fri, 17 Sep 2021 02:09:55 +0000 To: "internals@lists.php.net" Thread-Topic: RFC: Add `final class Vector` to PHP Thread-Index: AQHXq2Dr5ROExEhu802SAlX6zd1M+w== Date: Fri, 17 Sep 2021 02:09:55 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 2247ce0a-8dcb-23a3-9683-dd7685f45cec x-tmn: [v1B7ugK8c0YQJ2d2qvnTl4hV8Jp96JvA1UnAfd/Dswap5EdbJNccUIeVwocs4r+4G+nm8KsVFm0=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0e1443d9-9d32-4b74-b4cd-08d979803e0d x-ms-traffictypediagnostic: DM6PR07MB6506: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3zSR3C5gQAMs87G11YB3QJz7LDPINEdndItpMQn1vETd2//xmbZ6DM9hFVJsT9pobOtvj1QnAS9ZMpzBiIgFVJrb9inJLZWiL5NR1BRytEVVzJ+I7mD5LVSDTP6NY8wrHI17dEmGY+NRe4m3z0KoGQL5VKc6hhqUqZ8sqKYlZtkApg/ZBgOql8Ms2ulRkZZ5mgolXWez537qHIejEeOvcsYHQrqgnEKJMOw6qIVyCcMLUiaRZjgKS4lkzOn9Ldm/zZBTOj1hcmJXKN36SHfYLJttQHwKjOZf8Kz7xuIbFzuy+wVreVcgeXQI8xA0Pj1qM8m87PnWLbW3INT+6YE08tnEPwzqShwjVs2cvbDrRtWaMKdMYtsjsoDNaFmr19FMrP1JrpmivOTqK+rX/Z5YtUz7aUYlsNDA7sHT2HUyWJ+vVdVJtfQ8SjqRt9aun8zUjsynkJYLD3Th/om/eFPry6DaC8E4y+OVWaUVvGTWdpw= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: gJ+Y+kFZxUpifZavhhHUSC+ZPJ/GaPW8P1snB4KN8VZy5c7N0iGmyqjM0EampwCRdl8WXkJ8yB4gvmQjVio4b0FbTetVzfigm96G3HRnAWD8P9akUryNJ1/vL4Og5OA0+nJI94kyeJRTt2d176Ngl03tzZ/CMMa7cYYGpTC5mpDsqbjOPpi2Jp440O2m7ny3AXKFcJ/ALtA1rGC7UNmvHg== 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: 0e1443d9-9d32-4b74-b4cd-08d979803e0d X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Sep 2021 02:09:55.2236 (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: DM6PR07MB6506 Subject: RFC: Add `final class Vector` to PHP From: tysonandre775@hotmail.com (tyson andre) Hi internals,=0A= =0A= I've created a new RFC https://wiki.php.net/rfc/vector proposing to add `fi= nal class Vector` to PHP.=0A= =0A= PHP's native `array` type is rare among programming language in that it is = used as an associative map of values, but also needs to support lists of va= lues.=0A= In order to support both use cases while also providing a consistent intern= al array HashTable API to the PHP's internals and PECLs, additional memory = is needed to track keys (https://www.npopov.com/2014/12/22/PHPs-new-hashtab= le-implementation.html - around twice as much as is needed to just store th= e values due to needing space both for the string pointer and int key in a = Bucket, for non-reference counted values)).=0A= Additionally, creating non-constant arrays will allocate space for at least= 8 elements to make the initial resizing more efficient, potentially wastin= g memory.=0A= =0A= It would be useful to have an efficient variable-length container in the st= andard library for the following reasons: =0A= =0A= 1. To save memory in applications or libraries that may need to store many = lists of values and/or run as a CLI or embedded process for long periods of= time =0A= (in modules identified as using the most memory or potentially exceeding= memory limits in the worst case)=0A= (both in userland and in native code written in php-src/PECLs)=0A= 2. To provide a better alternative to `ArrayObject` and `SplFixedArray` for= use cases =0A= where objects are easier to use than arrays - e.g. variable sized collec= tions (For lists of values) that can be passed by value to be read and modi= fied.=0A= 3. To give users the option of stronger runtime guarantees that property, p= arameter, or return values really contain a list of values without gaps, th= at array modifications don't introduce gaps or unexpected indexes, etc.=0A= =0A= Thoughts on Vector?=0A= =0A= P.S. The functionality in this proposal can be tested/tried out at https://= pecl.php.net/teds (under the class name `\Teds\Vector` instead of `\Vector`= ).=0A= (That is a PECL I created earlier this year for future versions of iterable= proposals, common data structures such as Vector/Deque, and less commonly = used data structures that may be of use in future work on implementing othe= r data structures)=0A= =0A= Thanks,=0A= Tyson=