Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118983 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40681 invoked from network); 7 Nov 2022 22:45:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Nov 2022 22:45:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D67CF180382 for ; Mon, 7 Nov 2022 14:45:36 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_HOTMAIL_RCVD2, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2080.outbound.protection.outlook.com [40.92.42.80]) (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 ; Mon, 7 Nov 2022 14:45:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JDn7C2kLNBCdg0ZLc3XthLI9H6dVjA6FscJsGSdHm8nfKX3Bonj6+Fk8j5jPZF34xLsBjXHHxaxWi1QaAyoLNTVD83TaS7KbMDJ0ZxnRdFDIbkdefDbd39yYbxgjdXS9uzqZQEzSeh+xz4OXX6fceM1eyOCUKJelouzE9T5vZ9O85AZvcS81uXGNrYx7LwZKDVdKjUSDcYWaBZGNKF+eZgZAumxWJx3NLFFAyq/hx4euyIRG0EHo1KNgybKvm7AlZ0N0iew9aVFLWcEKauxlCRualje2rysK7+zlFMQhI88fhj9C3Pe2e+DE4ssn8iq1vORHWt0Mw8rXoaVTC/wnHg== 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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7OUWAWPOM/Fd56nqk0iEnUXKuaSSDgDZqlMH/4dFCiU=; b=eTlXGwNdseth49wuNNifBDxYZ7vsXVu2aYVhVlaDpMCr2UEo/MqeIfMLg8G7tRpGDWvJzfveTro0OuZ0H+ZlmUqtUv9P2AlJeyCbh+70+7dDk9vePNi6jBotzA/q4M02/bd1s9vwNXKyiQgUnjtD7gtVDPYuQ9ONuDyfN/kKxvJxX0BESEppvoLUwJnkpGzi3PvVsui0KTch/Fe2z9lkz/1uBXRouL8lH8okc1kfEG/hTG6hTaY29CqOEjNPrpvlTRwjYXCpHDKtX+Jp2YKEMT/ZQgAzBedASayCIrP7l9opw4Fa5eGdWRw5l7O+HVHm7izzKAZEH5TaCWKd7rYAZQ== 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=7OUWAWPOM/Fd56nqk0iEnUXKuaSSDgDZqlMH/4dFCiU=; b=fdYCpcnadIU6vU+/jdLumARFaz9d5kspZR2q5JhXV1tAYde0JWG4D8yo0iwc8JL2hJQ0hSP9TtyKTOno5nd2rZ/OINXqElJ8QV6W5jan5ZtaF6rVZx2eav2oXuL7jq5p8Bl0gWQMj7QpJLoaF/02aGThAfibDjpvhTOVsSzIk+DKqaSi0Iyqa2VhAdoOAaTSwR/NVu9zIluslRQYg7UE1byIvftHSTsiE16HABq/spVymOTL+svlZKcW1+TBi+ISzgWLxoJffwE41yLW5alh+QSHqXBcdin3n660dIPjOtSz9mlvLPfUBsizR3gQJqEBFY0AxH46+ZHywpna1tGivg== Received: from DM6PR14MB4155.namprd14.prod.outlook.com (2603:10b6:5:21e::11) by PH7PR14MB5418.namprd14.prod.outlook.com (2603:10b6:510:13c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.11; Mon, 7 Nov 2022 22:45:34 +0000 Received: from DM6PR14MB4155.namprd14.prod.outlook.com ([fe80::2f29:e49a:1e61:f79e]) by DM6PR14MB4155.namprd14.prod.outlook.com ([fe80::2f29:e49a:1e61:f79e%9]) with mapi id 15.20.5813.011; Mon, 7 Nov 2022 22:45:34 +0000 To: "internals@lists.php.net" Thread-Topic: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option Thread-Index: AQHY754K7rLPnqJ71kmEriA/RUN+qq4zssIAgABdays= Date: Mon, 7 Nov 2022 22:45:34 +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: msip_labels: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [1PqJXkkViz/wfx0cOaqb/6UvUVFzjGqRhqIhK2MfeDfupv5qnh1ASw==] x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR14MB4155:EE_|PH7PR14MB5418:EE_ x-ms-office365-filtering-correlation-id: 7e87f093-0bf8-40c1-a8f8-08dac111c80e x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Rut3CBpZzfG0QgY2VoJokODM0sRrnz5oMIftosys6C+ZH5ielvaJ5DlO+gW6JyScpTCL/Xqs8XKR9YofkCqkRle9KWS9wFeQXd02Ls+KIKCUjIQjfiu9AEHKYodhrOw3n0nPEMGAWv8CDN12wlCOFFANWv4OSsFiBy7b4Hu6rg9kJ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wasva1KqXtztFN9hkPsUPEePVP0IvAA38osja?= =?iso-8859-1?Q?zPC/02AJoDImxOBPlnzDwY0/qH16kyY7yqZ9RWw1bzDCI/LAVq7EASHpXv?= =?iso-8859-1?Q?Gpb9CdOc3PYRfd3/wYjxykdAwXAqroS1EHKEBZR/PQhCWMUmf56Gratfkq?= =?iso-8859-1?Q?zeeSQnq21WrMa9/wSGn85KnZgbIvuJXdPcAO12RHRo6Zk6m6YmWptg2VWU?= =?iso-8859-1?Q?3wvtpryfPzEiLX7mAjkxA0cf5f2im5iF/cSREc+CuufsvnMmIZL6PKLJK9?= =?iso-8859-1?Q?XxRCLFWrI5lACQFF0XW9gpdj/2ZzGJw1Fw3J0nzgllHmP/55BL29zUhsfY?= =?iso-8859-1?Q?VhmcegroMeQN5xtuhOsNeGZ9IA/3EqdItzliad/gtgiKsr84Az/TsMsyMS?= =?iso-8859-1?Q?4SlIAlkbNl6pjM1NxFLTxaGLrTdm/99e3dX1DazQew1edg4AsS02523dCE?= =?iso-8859-1?Q?iigUwX84KALY7qz9Y3oI4gOVDDDq7aH8gxVbTKdGdALy71L9MpgAtyhfrc?= =?iso-8859-1?Q?4oDknGnJ4ebNW6m2tgjHoqLAlspaPifS8owpTVHtXPG2k+NA18v0E4vx+c?= =?iso-8859-1?Q?moshTzPf48IDrdfy46hiJhZ/xd4KGGPD76A0czSJXU13I9AOdqk4aw3xbS?= =?iso-8859-1?Q?SVVb0bB2khoDF8RFbGdPJtXlWVYxWofq9aVf/N91IGvC5lCUNzJygf33HH?= =?iso-8859-1?Q?Jy/YaVbb5f/UCR/eioSY4rsRZJshgc85w+HJDcFrngk66fUxAoJn6h6+aQ?= =?iso-8859-1?Q?aqyEoLSiGtlq7oBcx1z7b2JBLB86hEimw80UnMX/NdVEBUdTpHNDzivc5H?= =?iso-8859-1?Q?bRWaBtAhoZ+p4CVfMaVKZFSlTXQR0++9Rx4lx6P8JH4XyrFc1ILXwdlDDj?= =?iso-8859-1?Q?k0NkC/x8SyB6ib8LCrA0pZmDXGa0+bWmRxcBIS7jI6j0O8uSmuIckuQdzm?= =?iso-8859-1?Q?KeQq8sW+onrzXTB5Ir9ztVmEY3Ryoso+ew4Aqxg6ru1oEcQ=3D?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-cd57b.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR14MB4155.namprd14.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 7e87f093-0bf8-40c1-a8f8-08dac111c80e X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Nov 2022 22:45:34.1199 (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: PH7PR14MB5418 Subject: Re: [PHP-DEV] ARRAY_UNIQUE_IDENTICAL option From: tysonandre775@hotmail.com (tyson andre) Hi Levi Morrison,=0A= =0A= > A bit off topic, but not entirely:=0A= >=0A= > In my opinion, adding another flag isn't the _real_ fix. Any function=0A= > which does comparisons should take a callable for users to provide any=0A= > comparison they wish. An iteratively better API would be:=0A= >=0A= > =A0=A0=A0 function array_unique(list $array, callable(T $a, T $b): = int $comparator);=0A= >=0A= > Of course, there are other things like instead of using int for `0`,=0A= > `-1`, `1`, we could have used an enum but we don't have one today. I=0A= > just mean the core idea of taking callable is better than mucking=0A= > around with flags while also allowing for custom comparison. Note that=0A= > it doesn't necessarily prevent optimizations either. For instance, if=0A= > they had passed `php_compare` or some function which represents `$a=0A= > <=3D> $b`, we could identify that just as we identify a specific flag=0A= > and take an optimized pass.=0A= =0A= 1. Calling php functions from C is fairly slow. Sorting compared to hash ma= ps is also slow=0A= =0A= If we did want a specialized implementation for user-provided=0A= equality criteria, `?callable(T $a): U $iteratee =3D null` would seems more= practical to me=0A= (Calling a function `n` times rather than `n log n` times would be faster,= =0A= and this would work even for cases such as=0A= `[$obj->nonObjectField1, $obj->field2->toNormalizedRepresentation()]` inste= ad of using a comparator in most cases=0A= =0A= (by putting both arrays into the internal hash map)=0A= =0A= (same approach as https://lodash.com/docs/#uniqBy)=0A= =0A= 2. `<=3D>` isn't a stable order for int/string/float (etc) in various ways,= =0A= so some comparators would have issues and return duplicates.=0A= =0A= It's possible to implement stable comparisons, but I don't really expect= enthusiasm for that=0A= https://github.com/TysonAndre/pecl-teds/#stable-comparison=0A= 3. I expect a majority of cases could use the `ARRAY_UNIQUE_IDENTICAL` dire= ctly.=0A= (or use that on array_map()ped values to find the keys of the original a= rray to use)=0A= So requiring the use of $comparator would result in longer code and more= possible sources of bugs=0A= (e.g. a comparator returning `$a - $b` might overflow/underflow int if u= sers don't realize `<=3D>` should be used)=0A= =0A= Thanks,=0A= Tyson=0A=