Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 7 Dec 2015 14:19:58 +0100
From: Ed Schouten <ed@...i.nl>
To: Ed Schouten <ed@...i.nl>, musl@...ts.openwall.com
Subject: Re: AVL tree: storing balances instead of heights

Hi Szabolcs,

2015-12-07 14:03 GMT+01:00 Szabolcs Nagy <nsz@...t70.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@...i.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.