From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>, 58158@debbugs.gnu.org
Subject: bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful
Date: Thu, 29 Sep 2022 16:37:51 +0200 [thread overview]
Message-ID: <m2y1u2qm9s.fsf@Mini.fritz.box> (raw)
In-Reply-To: <m235cas1w2.fsf@Mini.fritz.box> ("Gerd Möllmann"'s message of "Thu, 29 Sep 2022 16:15:09 +0200")
Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> Stefan Monnier <monnier@iro.umontreal.ca> 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++.)
The code from libstdc++ is this (from libstdc++-v3/src/c++98/tree.cc):
static _Rb_tree_node_base*
local_Rb_tree_increment(_Rb_tree_node_base* __x) throw ()
{
if (__x->_M_right != 0)
{
__x = __x->_M_right;
while (__x->_M_left != 0)
__x = __x->_M_left;
}
else
{
_Rb_tree_node_base* __y = __x->_M_parent;
while (__x == __y->_M_right)
{
__x = __y;
__y = __y->_M_parent;
}
if (__x->_M_right != __y)
__x = __y;
}
return __x;
}
I hope one can read that.
The idea is to find the root of the smallest subtree containing the
current node, and proceed from there. That's why the parent pointer is
needed.
Symmmetrical for max->min ordering. And finding min/max is trivial.
next prev parent reply other threads:[~2022-09-29 14:37 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 5:29 bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful Gerd Möllmann
2022-09-29 6:28 ` Eli Zaretskii
2022-09-29 7:03 ` Gerd Möllmann
2022-09-29 8:08 ` Eli Zaretskii
2022-09-29 9:09 ` Gerd Möllmann
2022-09-29 9:37 ` Eli Zaretskii
2022-09-29 10:05 ` Gerd Möllmann
2022-09-29 10:43 ` Eli Zaretskii
2022-09-29 11:33 ` Gerd Möllmann
2022-09-29 13:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-29 13:23 ` Eli Zaretskii
2022-09-29 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-29 13:40 ` Eli Zaretskii
2022-09-29 14:15 ` Gerd Möllmann
2022-09-29 14:37 ` Gerd Möllmann [this message]
2022-09-29 22:09 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-30 5:28 ` Gerd Möllmann
2022-09-30 6:11 ` Eli Zaretskii
2022-09-30 11:31 ` Gerd Möllmann
2022-09-30 18:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-02 8:06 ` Gerd Möllmann
2022-10-06 22:36 ` Dmitry Gutov
2022-10-07 19:47 ` Eli Zaretskii
2022-10-08 18:50 ` Dmitry Gutov
2022-10-10 8:10 ` Eli Zaretskii
2022-10-11 2:12 ` Dmitry Gutov
2022-10-11 6:37 ` Eli Zaretskii
2022-09-30 13:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-30 14:08 ` Gerd Möllmann
2022-09-30 15:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-30 16:04 ` Eli Zaretskii
2022-09-30 17:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-01 5:06 ` Gerd Möllmann
2022-10-01 13:54 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-02 8:22 ` Gerd Möllmann
2022-10-02 16:32 ` Andreas Politz
2022-10-03 4:35 ` Gerd Möllmann
2022-10-04 10:50 ` Andreas Politz
2022-10-01 7:25 ` Gerd Möllmann
2022-10-01 10:55 ` Gerd Möllmann
2022-10-01 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-29 16:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-01 1:57 ` Richard Stallman
2022-10-01 7:00 ` Eli Zaretskii
2022-10-06 22:26 ` Matt Armstrong
2023-10-06 13:14 ` Gerd Möllmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2y1u2qm9s.fsf@Mini.fritz.box \
--to=gerd.moellmann@gmail.com \
--cc=58158@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).