This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

I'm unhappy about twalk_r


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]