Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116967 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72531 invoked from network); 1 Feb 2022 15:12:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2022 15:12:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D49B7180542 for ; Tue, 1 Feb 2022 08:27:04 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (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 ; Tue, 1 Feb 2022 08:27:04 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 428933201FED for ; Tue, 1 Feb 2022 11:27:03 -0500 (EST) Received: from imap43 ([10.202.2.93]) by compute5.internal (MEProxy); Tue, 01 Feb 2022 11:27:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=RtbVDAD+ylnc+VsOx Mz7pxYlrhncmRHEf9JqkA4l8Ks=; b=mT7joIUs4Kt4a8ENQKFmsIa/Mwn8c/yvN mZNrqXwkrWxM91N13kAcsCSoN8ps/gSQ6hRqBn2zZGM+fVVflhXNCnCLdaTJvRGb XEy5PLqwbMfbi9yk2EW+nbju4hZzm6BvEqaM1hMF9YXtSCddnijFuej62PAJmmOH cpW972o4y1sQL/DW8LiobdZCKnp/98NKSDqg43W2ihmT51i/O1+kHAfkIPdEVM6E ztqpV8aGyb9/+1WK9WO+NdW3wO3Ze57EeGyaqmUFq5Ntw4fVivTwqkLES7WrZ6kJ rMq4mkHmloonT/JqFPyz0r1+yTZqdU3evAchUPinxAhWM3HUgeOiQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrgeefgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenog fuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughrpefofgggkfgjfhffhffvufgt sehttdertderredtnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoehlrg hrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhepveeu hfegffefvefggfelffevkedtgefgkedvkeejvdevhffgffetvdehfeeivdeknecuffhomh grihhnpehphhhprdhnvghtpdgvgihtvghrnhgrlhhsrdhiohdpghhithhhuhgsrdhiohen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrh ihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5C1D7AC0E9D; Tue, 1 Feb 2022 11:27:02 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4585-ga9d9773056-fm-20220113.001-ga9d97730 Mime-Version: 1.0 Message-ID: <1c9e79d5-fd79-45a8-9c77-4228d770062d@www.fastmail.com> In-Reply-To: References: Date: Tue, 01 Feb 2022 10:26:42 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Re: Adding `final class Deque` to PHP From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 1, 2022, at 8:46 AM, tyson andre wrote: > I plan to start voting on https://wiki.php.net/rfc/deque on Friday, > February 4th. > > Several changes have been made to https://wiki.php.net/rfc/deque#changelog > after the feedback in https://externals.io/message/116100 > > - The class is now named `Collections\Deque` > - The api documentation in https://wiki.php.net/rfc/deque#proposal was > expanded for methods. > - Benchmarks were updated. > - Like other standard datastructures, iteration over the deque is now > over the original object (instead of creating a copy), > and mutating the deque will be reflected in `$iterator->current()` > (and moving the end with push()/pop() will affect where iteration ends). > - Iteration will account for calls to shift/unshift moving the start of > the deque. > the offsets will be corrected and values won't be skipped or iterated > over multiple times. > (no matter how many iterators were created by `Deque->getIterator()`) > See https://wiki.php.net/rfc/deque#iteration_behavior > - The get()/set() methods were removed, after feedback in > https://externals.io/message/116100#116214 > > A WebAssembly demo is available at > https://tysonandre.github.io/php-rfc-demo/deque/ Request: push() and unshift() currently return void. That's not helpful. It would be vastly more useful if they both returned $this. Not as much for chaining, but more so that you can add a value to a queue and pass it as an argument to another call (often recursive, but not necessarily) in a single operation. Example: I was doing last year's Advent of Code in functional PHP, and had a stack walker that looked like this: function parse(string $line, $pos = 0, array $stack = []): Result|string { $next = $line[$pos] ?? null; $head = $stack[0] ?? null; return match ($next) { // Opening brace, push an "expected" onto the stack. '{' => parse($line, $pos + 1, ['}', ...$stack]), '<' => parse($line, $pos + 1, ['>', ...$stack]), '(' => parse($line, $pos + 1, [')', ...$stack]), '[' => parse($line, $pos + 1, [']', ...$stack]), '}', '>', ')', ']' => $next === $head ? parse($line, $pos + 1, array_slice($stack, 1)) : $next, null => count($stack) ? Result::Incomplete : Result::OK, }; } The interesting part is the ['<', ...$stack], to pass on a modified version of an array-as-stack. That's of course annoyingly slow with arrays right now, and a Deque would be better, but only if it could be "modified and passed" like that. If not, it would be incompatible with single-expression usages (match statements, short lambdas, etc.) Returning $this would resolve that, I think. (Making it return a new, immutable copy of the Deque would be even nicer, but I realize that's probably not an argument I'm going to win at this point on this RFC.) Also, typo: "By introducing a data structure (Deque) that's even faster and more memory usage than an array for use as a double-ended queue, even more applications would benefit from it. " I think you mean "less memory usage", or possibly "more memory efficient", or something like that. --Larry Garfield