Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116214 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12769 invoked from network); 4 Oct 2021 11:20:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Oct 2021 11:20:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D41D41804C6 for ; Mon, 4 Oct 2021 05:04:47 -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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 4 Oct 2021 05:04:47 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id p11so10768635edy.10 for ; Mon, 04 Oct 2021 05:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bXGe5p/cL9u0cLf0+YFrv5bzXmLHLdN34rteEkScKQk=; b=VZIiGJP96A3DLLLORRueL4oJCip1RFIA7UzkZmLemVMKuBuK02ofivDMvGSVqglEGa zhG255JKGKsLBOcXjwCDD7lnXRc7wXiR3WQM3W4sVoWULc03tfYywzgP0iN/zZfAYRHu QL47dW94/6kjhf+nWYBharrRk3dby4xi/6erE2GvamZiQXnFYxy3Vq74GU8mc1hV6NqH CQHKWd1tj2mpx9swblvTDl1ZWGtd/sXcLQBp7XGTOQn9ipIVKtfAZqdfkDaMkxFfdNXE 3/vdh3rvQVSCKcB+qpB+rNKm5VBwFdcDYVpN2HskoIv0r08cV9TQtk/QtllXrVUcVz97 Z3vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bXGe5p/cL9u0cLf0+YFrv5bzXmLHLdN34rteEkScKQk=; b=Bw7GsDxPGA0oSR2S7ltwS5KRWvDoL7jzwdsOs09OYoshw52UPop4SadKLTYz+StwVK x6RXM/oWaIc+Bw79OyExQfRwseQRzKnGOKnyRp1JSmHysKZfw/NyZDaRtdtf5nRi1O+4 9RLkvBhDGI35N0jD+qoE93+SvO9uRy4Y5RIsOB83LYZPX4+gguLDsvAPtqX62AWasQJu M0k43RFWIAi9ov0g/llocFtYncjqKGHDJm8sOpEppXeqWblP9kO9rZk50H7WlbZX4zKx LHzgr4DHDhn57nA+fKjKRAyFXqv7tUwAqIFGH4v0k+1V/jKoVCaGopLL6Y4l/nU50R2b uYMg== X-Gm-Message-State: AOAM531LnhX8T5DRNzLxesldl2yF+QzDjXVY4fkyw/xezzEIOTKCKXJH MbAGk4qKdiVPNdZOQQP2+r+qeeOxD0wamHRn8UgVqggW X-Google-Smtp-Source: ABdhPJwR4ThInQUaZWc5RPoKqf8B66d61fYhYxEyUXeu6WI6l+08QN+QnHIBhC58fsJwOs9uEp3tAGvxVRc1O76q5Og= X-Received: by 2002:a17:906:1dc4:: with SMTP id v4mr17078518ejh.282.1633349084680; Mon, 04 Oct 2021 05:04:44 -0700 (PDT) MIME-Version: 1.0 References: <67BFE5C6-3C3F-4309-97A2-14CA0D8C3B3B@newclarity.net> <7BEE0406-3CAE-4E83-A196-F9F608BE8D17@newclarity.net> In-Reply-To: Date: Mon, 4 Oct 2021 14:04:28 +0200 Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000fc947b05cd85b7bb" Subject: Re: [PHP-DEV] Adding `final class Deque` to PHP From: nikita.ppv@gmail.com (Nikita Popov) --000000000000fc947b05cd85b7bb Content-Type: text/plain; charset="UTF-8" On Tue, Sep 21, 2021 at 11:05 PM Levi Morrison via internals < internals@lists.php.net> wrote: > The name "deque" is used in the standard library of these languages: > > - C++: std::deque > - Java: java.util.Deque (interface) > - Python: collections.deque > - Swift: Collections.Deque (not standard lib, apparently, but Apple > official? Don't know Swift) > - Rust: std::collections::VecDeque > > And these don't have it in the standard library: > - Go > - C# > - C > - JavaScript > > Anyway, it's pretty decent evidence that: > 1. This functionality is pretty widely used across languages. > 2. This functionality should have "deque" be in the name, or be the > complete name. > > Discussion naming for "vector" I can understand, as it's less widely > used or sometimes means something specific to numbers, but there's > little point in discussing the name "deque." It's well established in > programming, whether PHP programmers are aware of it or not. > > As I see it, the discussion should be centered around: > 1. The API Deque provides. > 2. The package that provides it. > 3. Whether Deque's API is consistent with other structures in the same > package. > 4. Whether this should be included in php-src or left to extensions. > > I suggest that we try to make PHP as homogenous in each bullet as we > can with other languages: > 1. Name it "Deque." > 2. Put it in the namespace "Collections" (and if included in core, > then "ext/collections"). > 3. Support common operations on Deque (pushing and popping items to > both front and back, subscript operator works, iteration, size, etc) > and add little else (don't be novel here). To me, the biggest thing > left to discuss is a notion of a maximum size, which in my own > experience is common for circular buffers (the implementation chosen > for Deque) but not all languages have this. > 4. This is less clear, but I'm in favor as long as we can provide a > few other data structures at the same time. Obviously, this a voter > judgement call on the yes/no. > > Given that I've suggested the most common options for these across > many languages, it shouldn't be very controversial. The worst bit > seems like picking the namespace "Collections" as this will break at > least one package: https://github.com/danielgsims/php-collections. We > should suggest that they vendor it anyway, as "collections" is common > e.g. "Ramsey\Collections", "Doctrine\Common\Collections". I don't see > a good alternative here to "Collections", as we haven't agreed on very > much on past namespace proposals. > > Anyway, that's what I suggest. > I generally agree with everything Levi has said here. I think that adding a deque structure generally makes sense, and that putting it into a new ext/collections extension under the corresponding namespace would be appropriate. I wouldn't insist on introducing it together with other structures (I'm a lot more sceptical about your Vector proposal), but do think there should be at least some overarching plan here, even if we only realize a small part of it in this version. A few questions for the particular API proposed here: 1. There would be the possibility of having an interface Deque that is backed by a VecDeque/ArrayDeque implementation. I'm not convinced this would actually make sense, but I wanted to throw it out there, given that the class is final (which is without any doubt the correct decision). 2. How do set() / offsetSet() work with an out of range index? Is it possible to push an element with $deque[count($deque)] = x? I would assume that throws, but want to make sure. On a related note, why do we need both get()/set() and offsetGet()/offsetSet()? These APIs seem redundant. 3. I believe it's pretty standard for Deque implementations to provide insert() / remove() methods to insert at any position (these would be O(n)). 4. The design of getIterator() here is rather unusual, and deserves some additional justification. Normally, we let getIterator() see concurrent modifications to the structure, though the precise behavior is unspecified. I would also like to know how this will look like on a technical level (it doesn't seem to be implemented yet?) This seems like something that will require a check on every write operation, to potentially separate the structure in some form. 5. The shift/unshift terminology is already used by our array API, but I'm not sure it's the most intuitive choice in the context of a deque. SplQueue has enqueue() and dequeue(). Another popular option from other languages (which I would personally favor) is pushFront() and popFront(). Regards, Nikita --000000000000fc947b05cd85b7bb--