Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Aug 2015 15:10:48 -0400
From:      Davide Italiano <davide@freebsd.org>
To:        Bruce Simpson <bms@fastmail.net>
Cc:        Baptiste Daroussin <bapt@freebsd.org>,  "src-committers@freebsd.org" <src-committers@freebsd.org>, svn-src-projects@freebsd.org
Subject:   Re: svn commit: r286484 - projects/collation/usr.bin/localedef
Message-ID:  <CACYV=-F4HTmPp2VuaKFbk35bjcG4zJHtR7rbFkSVhoHAh8Xs3g@mail.gmail.com>
In-Reply-To: <55CB91FD.8000004@fastmail.net>
References:  <201508082257.t78MvIT1000841@repo.freebsd.org> <CACYV=-GnOpPddd-x_J0yW4g4QFsdcEVXaVc9CER9JD7iObGzAg@mail.gmail.com> <20150812182739.GB51754@ivaldir.etoilebsd.net> <55CB91FD.8000004@fastmail.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Aug 12, 2015 at 2:35 PM, Bruce Simpson <bms@fastmail.net> wrote:
> On 12/08/15 19:27, Baptiste Daroussin wrote:
>>
>> On Wed, Aug 12, 2015 at 01:22:17PM -0400, Davide Italiano wrote:
>>>>
>>>> +#define RB_NUMNODES(type, name, head, cnt) do { \
>>>> +       type *t; \
>>>> +       cnt = 0; \
>>>> +       RB_FOREACH(t, name, head) { \
>>>> +               cnt++; \
>>>> +       } \
>>>> +} while (0);
>>>> +
>>>
>>>
>>> Can you commit this one to HEAD && move it to the right header?
>>>
>> You mean adding to tree(3)?
>
>
> Not sure why you'd want to pollute it by doing this. The macro is simple
> enough that anyone can write it, and it is often best to count RB nodes
> whilst doing something else (or lazy-update) to avoid unnecessary
> traversals.

I'm not sure which pollution are you referring to.
The fact that a macro is easy enough doesn't necessarily imply it
shouldn't be part of the API/KPI.
Not only I think that having all the RB macro in a single place is
better than having them scatter-gathered in the tree, using
RB_NUMNODES to hide the details would save us a lot of headache in
case we want to change internal node representation, e.g. if we want
to store a field in the struct that keeps the number of nodes in the
subtree rooted at a given node, to make count O(1 ) rather than O( N )
where N is the number of nodes in the tree.

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACYV=-F4HTmPp2VuaKFbk35bjcG4zJHtR7rbFkSVhoHAh8Xs3g>