Re: [RFC] B+Tree library V2

From: Johannes Berg
Date: Thu Jan 08 2009 - 12:09:45 EST


On Thu, 2009-01-08 at 17:24 +0100, JÃrn Engel wrote:

> If you want to open-code it, you can use btree_lookup_less(). I added
> that function sometime last month. Basically something like this:
> key = btree_last(head, geo);
> while (key) {
> /* do something with key */
> key = btree_lookup_less(head, geo, key);
> }

Ok, so looking deeper into this, how about adding

#define btree_for_each_key(head, geo, key, tmp) \
for (key = btree_last(head, geo), tmp = btree_lookup_less(head, geo, key);
key; key = tmp, tmp = btree_lookup_less(head, geo, key))

(and possibly some type-checking variants that hardcode the geo)

Does that seem correct? And would it be possible to provide btree_last()
that takes an void ** and fills it with the last entry, and the same for
lookup_less(), so we can write btree_for_each_entry() too?

johannes

Attachment: signature.asc
Description: This is a digitally signed message part