From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: I'm unhappy about twalk_r
Date: Tue, 14 May 2019 14:08:00 +0200 [thread overview]
Message-ID: <874l5x44tb.fsf@oldenburg2.str.redhat.com> (raw)
I have second thoughts about twalk_r. I think the twalk interface is
just broken because the internal tree structure is
implementation-defined (because there is so much flexibility in
balancing a binary tree). Or put differently, while the overall
iteration order is well-defined by the key ordering, it's mostly
unspecified which nodes are leaf nodes and which are internal nodes.
Exposing this information using the VISIT argument seems wrong to me.
I still think the function is useful, but I think the interface should
look like this instead:
int twalk_r (const void *root,
int (*action) (const void *nodep, void *closure),
void *closure);
ACTION is invoked for every node in the tree, in increasing key order,
as long as ACTION returns zero. Otherwise, no further invocations
happen and twalk_r returns this non-zero value. If all calls to ACTION
return zero (and the entire tree is traversed), twalk_r returns zero.
I think this is much more useful: It avoids pointless repeated calls to
ACTION, and it allows premature termination of the iteration.
Thanks,
Florian
next reply other threads:[~2019-05-14 12:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 12:08 Florian Weimer [this message]
2019-05-14 18:22 ` I'm unhappy about twalk_r DJ Delorie
2019-05-14 19:50 ` Adhemerval Zanella
2019-05-17 15:43 ` Florian Weimer
2019-05-14 20:40 ` Carlos O'Donell
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/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874l5x44tb.fsf@oldenburg2.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/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.
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).