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: Sun, 02 Oct 2022 10:22:21 +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="37046"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) Cc: Eli Zaretskii , Andreas Politz , 58158@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 02 10:23:09 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 1oeuFh-0009Rl-6f for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 02 Oct 2022 10:23:09 +0200 Original-Received: from localhost ([::1]:60894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeuFf-0007VT-Kx for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 02 Oct 2022 04:23:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeuFa-0007VL-FX for bug-gnu-emacs@gnu.org; Sun, 02 Oct 2022 04:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oeuFa-0003JX-5B for bug-gnu-emacs@gnu.org; Sun, 02 Oct 2022 04:23:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oeuFZ-0002TO-OM for bug-gnu-emacs@gnu.org; Sun, 02 Oct 2022 04:23:01 -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: Sun, 02 Oct 2022 08:23:01 +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.16646989509460 (code B ref 58158); Sun, 02 Oct 2022 08:23:01 +0000 Original-Received: (at 58158) by debbugs.gnu.org; 2 Oct 2022 08:22:30 +0000 Original-Received: from localhost ([127.0.0.1]:46205 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeuF4-0002SW-7w for submit@debbugs.gnu.org; Sun, 02 Oct 2022 04:22:30 -0400 Original-Received: from mail-ed1-f54.google.com ([209.85.208.54]:34628) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oeuF2-0002SJ-Jk for 58158@debbugs.gnu.org; Sun, 02 Oct 2022 04:22:29 -0400 Original-Received: by mail-ed1-f54.google.com with SMTP id s30so7251730eds.1 for <58158@debbugs.gnu.org>; Sun, 02 Oct 2022 01:22:28 -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=Fdi+me/iuvYvsi48ukiZyXLNGoEZapStVWoVwzHfxiA=; b=J4W/+/r7GKgtJUVaywpfj28U+lqjwmdfqn2oQaQNMPZa/nCMAT7d54wkMhZM+H56TK L6Z7Q4B4deOXZ6zgqyhT0T2A1orKL/UBRF+YF677MHdLEVsRWIUdM+Y2LD1NsksCL2zT zDNMFcPfbLltUCi+j6nmBFWywY9dMXXzlwyza0fhHKdHUoQfGU6xsC+rX6hYskC/WOiX pU8p7q6Y0qlNvqcrOTfFbDDwHE2Mpgt6hYFZdyYffFUtqwuW/re/FghounGhty6nWieK zlYKf9XQeBqiFm+c35cQYvx8Kqn4M6j7ebMxsD/1+PzMcUQiKtwXsYNE/yP5g1au1pZX Rmyw== 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=Fdi+me/iuvYvsi48ukiZyXLNGoEZapStVWoVwzHfxiA=; b=1/E+cNYRsc9XztC0MbafxEZY6lM0DDaA6O0b5EWsHBHISgxJFXmKNMHHu3tbkDhtz4 VJdj1gEt8218aCeZ9/NNkEXv45eGBRYPW8n5y/Vshliagf/VK6x6WmO1Rwnwc1umIL2l ae9nOT6wrQG6KKct5VMHJ+b0Tu8VQo430O+WoGcuuolKtHEcfjP+soLgVIARpliH9BTU UTRwGpT/qSZDbPWRRG2hGCVXTdqbQ8MkyM4HJmtfxvZGM1YLfGPGg7UZ90y/WmzD/7A5 ccOpbw8Y1kGeLkI6UTL8lptjyDaTzg+SCBu2ejhGHpyEK9GGQejADRQgIiBCBBXB3dSO kUbw== X-Gm-Message-State: ACrzQf1vSpjnSi3514GJBjSDnKCrY16NMGMD1hFKm5IHtkixqOoIhVK/ aOK2s8HrKxsfU7dwTGXiAj0= X-Google-Smtp-Source: AMsMyM7jWY04tiwJpzip2zbOSbgQW/ns+rzhmakGdbjzIexh8EXsVNIQvi13hdYdh3CWeaIm67VbqQ== X-Received: by 2002:a05:6402:357:b0:458:5cb6:f587 with SMTP id r23-20020a056402035700b004585cb6f587mr11545322edw.183.1664698942702; Sun, 02 Oct 2022 01:22:22 -0700 (PDT) Original-Received: from Mini.fritz.box (p54b0c1f2.dip0.t-ipconnect.de. [84.176.193.242]) by smtp.gmail.com with ESMTPSA id y8-20020a056402358800b0044dbecdcd29sm5012468edc.12.2022.10.02.01.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Oct 2022 01:22:22 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Sat, 01 Oct 2022 09:54:36 -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:244183 Archived-At: Stefan Monnier writes: >> Phew. I'm not sure but I get the feeling that makes implementing a >> successor function, let's say, challenging. > > I don't think it makes any difference in that respect, no. The reason I find it challenging, and I'm sure now, is that I've written the following code, and failed :-). /* FIXME: This assumption is wrong. Nodes on the left of P are <=, and nodes on the right are >=. */ /* Value is the successor of interval node X in ascending order. It is assumed that the tree is organized so that nodes < X are in X->left and nodes in X->right are >= X. */ static struct interval_node * in_order_successor (struct interval_node *x) { if (x->right != ITREE_NULL) { /* X has a right child, which means X's right subtree has elements >= X. Proceed to the left-most child in the right subtree, which is the smallest in that subtree. */ x = x->right; while (x->left != 0) x = x->left; } else { /* X's left subtree is uninteresting, because everything there is < X. Therefore follow the parent chain. If X is the parent's right child, this means the parent is < X, We are looking for a parent that is >=. */ struct interval_node *y = x->parent; while (x == y->right) { x = y; y = y->parent; } /* If we found a parent that's >=, the parent is what we sought. Otherwise, X has arrived at the null node, whose right child is the sentinel node itself. */ if (x->right != y) x = y; } return x; } I tried to change the comments and/or modify the code for a tree like we have (left subtree <=, right >=), and couldn't explain why it works, but I also couldn't produce a counter-example that the existing tree code actually can produce. IOW, I couldn't prove anything. P.S. With the "all over the place" I indented to hint at the fact that the tree is not a "normal" BST. I should probably have said that directly, sorry.