From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful Date: Thu, 29 Sep 2022 12:40:25 -0400 Message-ID: References: <83h70qhez0.fsf@gnu.org> <83edvuhaby.fsf@gnu.org> <831qruh67o.fsf@gnu.org> <83y1u2foli.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2011"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Eli Zaretskii , 58158@debbugs.gnu.org To: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 29 19:42:39 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1odxYV-0000Kq-22 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 19:42:39 +0200 Original-Received: from localhost ([::1]:46914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odxYU-00083C-1q for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 13:42:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odwat-0005A1-TL for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 12:41:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1odwas-0004ur-MK for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 12:41:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1odwas-00029U-HS for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 12:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Sep 2022 16:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58158 X-GNU-PR-Package: emacs Original-Received: via spool by 58158-submit@debbugs.gnu.org id=B58158.16644696408236 (code B ref 58158); Thu, 29 Sep 2022 16:41:02 +0000 Original-Received: (at 58158) by debbugs.gnu.org; 29 Sep 2022 16:40:40 +0000 Original-Received: from localhost ([127.0.0.1]:39412 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odwaW-00028m-7D for submit@debbugs.gnu.org; Thu, 29 Sep 2022 12:40:40 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:35643) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1odwaP-00028E-BO for 58158@debbugs.gnu.org; Thu, 29 Sep 2022 12:40:38 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id D36DC100138; Thu, 29 Sep 2022 12:40:27 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 28F2D1000FC; Thu, 29 Sep 2022 12:40:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1664469626; bh=vnOYG21YnYzvzyiBpZ/ZaBMm58G73v9/WSgDmA9WCFE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=VNN6lwGeUZ5ce7QbLow+PCTbw6eZbeu3MH4fRedAtIxhcfYgTi1pj1T23cpXli9K3 jUNsUtiPoxQs/85SKtV/fdc0CLTFxl2r9K0tbHWRb8aRdLftDU9iGWJGMyfNowvNtp vjudKhsvZXFES+RIIGv5fo2CTc2ELHg1cggbWLb+MYO8g68OoyVYKhMyo2BUtVSBCY LX2ucjw4+jMaDfllGn/8f2jHg6zCpppLTBCKV7sOsb1BOe3L8R+LLpo1m81rXpJmCr dSdQuYQFfoerJor3o0yssB9VewPh+wuPXkFghRwP/J8GSruoDowRpuHWTF6GPsYOpv zIaI8JryAL4NA== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 032631203D7; Thu, 29 Sep 2022 12:40:25 -0400 (EDT) In-Reply-To: ("Gerd =?UTF-8?Q?M=C3=B6llmann?="'s message of "Thu, 29 Sep 2022 16:15:09 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:243930 Archived-At: Gerd M=F6llmann [2022-09-29 16:15:09] wrote: > Stefan Monnier writes: >> One reason is that traversing a binary tree usually requires something >> like recursion, but that wouldn't fit very conveniently with the current >> code (nor with C in general since you can't make a local recursive >> closure which accesses local variables from the surrounding function). > Ok, usually, but not necessarily. The alternative is to implement an > iterator that starts with a node N, and an implementation of a successor > function, which return the successor of N in a given order. The approach currently used is somewhat similar to that. Some of the difference is that we need an actual "iterator/generator" object to remember the parameter of the filtering we want to apply to the set of objects. And the problem is that this "object" is currently implemented not only as a global value (thus restricting us to one-iteration at a time) but also with some parts of the data stored in the tree. I think this is the part that really needs to be changed. > This requires a parent pointer in nodes, but that we have. > > (Something like this is used for ordered containers like "map" and "set" > in C++ STL, for instance, which are based on rb-trees in GCC's > libstdc++.) Another difference is that itree.c's iterator uses a local "work stack" instead of traversing the tree exclusively via left/right/parent like in the code you show. I don't know if that difference is important, tho. >> Another is the need to update the begin/end fields (these need updating >> because of insertions/deletions but they're updated lazily while >> traversing the tree to avoid an O(N) complexity during the >> insertions/deletions). Hiding that behind 'some kind of "next node" >> function keeps the code more readable. > > Is this for buffer text changes, something akin to a delayed update of > marker positions? Yes, exactly. >> But yes, the current restriction to have a single iteration at a time is >> a bit of a problem, especially because it's very "global". I added >> a comment yesterday describing how we could make it non-global (hence >> getting rid of the `visited` flag in the nodes). > > BTW, and related to iteration directly, did you notice this in > interval_tree_insert? > > /* This suggests that nodes in the right subtree are strictly > greater. But this is not true due to later rotations. */ > child =3D node->begin <=3D child->begin ? child->left : child->righ= t; No, I had not noticed that yet, and I don't understand this comment. Stefan