From: Ed Schouten <ed@nuxi.nl>
To: Ed Schouten <ed@nuxi.nl>, musl@lists.openwall.com
Subject: Re: AVL tree: storing balances instead of heights
Date: Mon, 7 Dec 2015 14:19:58 +0100 [thread overview]
Message-ID: <CABh_MKnkw_Yp9ifwybXBOMb0FuPvP05T183utZ1kW6Ohqq3gvQ@mail.gmail.com> (raw)
In-Reply-To: <20151207130344.GZ23362@port70.net>
Hi Szabolcs,
2015-12-07 14:03 GMT+01:00 Szabolcs Nagy <nsz@port70.net>:
> i think the macro definitions for inlining twalk and tfind
> are not justified.
I personally think it is justified in this case. In trivial cases it
may even mean that the compare function is inlined into the body of
twalk()/tfind().
I haven't measured this for twalk() and tfind() explicitly, but my
observation for bsearch() was that a separate compare function and an
invocation of bsearch() is about the same size as inlining the
bsearch() routine.
> you got the rootp==0 case wrong too (posix requires that to
> return 0).
That already happens, right? tdelete() sets it to (void *)1, but
tdelete_recurse() then sets it to NULL immediately.
> and the (T**) cast is invalid in
>
> void *tdelete(const void *restrict key, void **restrict rootp,
> int (*compar)(const void *, const void *)) {
> void *result = (void *)1;
> tdelete_recurse(key, (struct __tnode **)rootp, compar, &result);
> return result;
> }
Could you please elaborate this a bit further?
> posix specifies to return a pointer to a node, not to an element
> pointer, i think that's a bug in posix (otherwise the api would
> be useless).
Yes. On lines 40 and 44 the result pointer is set to the parent
object. As __key is the first member of the structure, I could have
written *n instead of &(*n)->__key, but this implementation does not
strongly enforce it. I could put __key anywhere in the node structure
and it would always return a pointer to a pointer to a key.
--
Ed Schouten <ed@nuxi.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717
next prev parent reply other threads:[~2015-12-07 13:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CABh_MKm1Ow5_dc4ENJM-fAqWc+uPPZgftRdSDxPJiPXZAfZ+FQ@mail.gmail.com>
2015-12-07 13:03 ` Szabolcs Nagy
2015-12-07 13:19 ` Ed Schouten [this message]
2015-12-07 13:22 ` Ed Schouten
2015-12-07 14:46 ` Szabolcs Nagy
2015-12-10 9:21 ` Ed Schouten
2015-12-10 12:14 ` Szabolcs Nagy
2015-12-10 13:12 ` Ed Schouten
2015-12-10 13:43 ` Szabolcs Nagy
2015-12-20 21:43 ` Szabolcs Nagy
2015-12-21 1:28 ` Szabolcs Nagy
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABh_MKnkw_Yp9ifwybXBOMb0FuPvP05T183utZ1kW6Ohqq3gvQ@mail.gmail.com \
--to=ed@nuxi.nl \
--cc=musl@lists.openwall.com \
/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.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).