svn commit: r286484 - projects/collation/usr.bin/localedef

Davide Italiano davide at freebsd.org
Wed Aug 12 19:10:50 UTC 2015


On Wed, Aug 12, 2015 at 2:35 PM, Bruce Simpson <bms at 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


More information about the svn-src-projects mailing list