From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful Date: Thu, 29 Sep 2022 16:15:09 +0200 Message-ID: References: <83h70qhez0.fsf@gnu.org> <83edvuhaby.fsf@gnu.org> <831qruh67o.fsf@gnu.org> <83y1u2foli.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28689"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) Cc: Eli Zaretskii , 58158@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 29 18:44: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 1odweN-0007GI-Kt for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 18:44:39 +0200 Original-Received: from localhost ([::1]:39070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odweM-0002lC-MN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Sep 2022 12:44:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oduKd-00030j-4l for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 10:16:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oduKY-0003FC-Ks for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 10:16:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oduKY-0006hl-1O for bug-gnu-emacs@gnu.org; Thu, 29 Sep 2022 10:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Sep 2022 14:16: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.166446092225726 (code B ref 58158); Thu, 29 Sep 2022 14:16:02 +0000 Original-Received: (at 58158) by debbugs.gnu.org; 29 Sep 2022 14:15:22 +0000 Original-Received: from localhost ([127.0.0.1]:39172 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oduJu-0006gs-0R for submit@debbugs.gnu.org; Thu, 29 Sep 2022 10:15:22 -0400 Original-Received: from mail-ej1-f47.google.com ([209.85.218.47]:35438) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oduJq-0006ga-9q for 58158@debbugs.gnu.org; Thu, 29 Sep 2022 10:15:20 -0400 Original-Received: by mail-ej1-f47.google.com with SMTP id sd10so3130102ejc.2 for <58158@debbugs.gnu.org>; Thu, 29 Sep 2022 07:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date; bh=oWmLNZNkBvKstZg4Ohdy2sNKhCJvdX3RTv8U9goAB+8=; b=Ijqx0WmQnpcFy8aHtksvEvKi1/uXB/9/KGv7IhzXUaq+DpSOy0fm4B9b4O49XAihvm r8Yd0H5pSYi7Q3QWSQFg2vOU/IID9NJRB3g6u1G1auQ2mILju6NtQd55a8mHKg9WSt5w Wd72ZRZaGnU0Wnwij+ZF7xjHBnAXOPSCgHnW253uM5U4keU9A1VNe40zI8ZfK6LBxzfj mvLZIwuUnwk1b+u4GULk1r9C2UN/0GpF+PbeLZc7D9dlT2zLKiPnAOv17NdLjxfwWs3v 0m4H5FbdiXvOdgSK3ydDeS/8VqOt/+ap5+bGxpn/3n/zydFSsbk3NDxgtezeSd7oda42 NpRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=oWmLNZNkBvKstZg4Ohdy2sNKhCJvdX3RTv8U9goAB+8=; b=u0v6fajm1toY+la9AINbTJggiWIKLGXHPoy3J1hOY+NW1t20Qtnv0HTmlt0hi+45Ib AXiYvjhCOXgxmrE5s7MsS/hkkQzGyQc2/9RdnZmrBHwWaFIdzUwZHi1MzBaxeC7lzhkS IYM01MWDbigha+r90ni90mZNLk/n4grdKjXs4Ct1nf0i79jkDO9qqMb4ZXYptpjDk+en q7wAjZ04kdq8FP5AYQrM6Guc8akTSM/Zdui5hkYrpyYruINJONiPH//NaS5ElalFsh0J udl6UNFArO9AKOcK+JXj2ScJS0+7Dm0bSKR09iwZut81koM2raloX+EksUp80WYHUDB2 C/3Q== X-Gm-Message-State: ACrzQf1gkbbgsIWa1LbEZ8oSlFgS0fBjvyZFXpD6pM3CRKAejdgURK7U p4KTIH9Ic5qpLT9TSPbFQQHDFUqTCz6GXA== X-Google-Smtp-Source: AMsMyM67tLmMYk84pcUicpcLf7+3bi/nmePHGL6o3N3F7YSFoQ7VNLZqoMcw2Yp62YSBZgZ68JOUWw== X-Received: by 2002:a17:906:2699:b0:781:a473:9791 with SMTP id t25-20020a170906269900b00781a4739791mr2930970ejc.644.1664460911916; Thu, 29 Sep 2022 07:15:11 -0700 (PDT) Original-Received: from Mini.fritz.box (pd9e36935.dip0.t-ipconnect.de. [217.227.105.53]) by smtp.gmail.com with ESMTPSA id v2-20020a170906292200b0073c80d008d5sm3998920ejd.122.2022.09.29.07.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 07:15:11 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Thu, 29 Sep 2022 09:10:19 -0400") 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:243923 Archived-At: 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. 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 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? I already wondered where that was. > 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 = node->begin <= child->begin ? child->left : child->right;