Messages in this thread | | | Date | Thu, 8 Jan 2009 21:02:43 +0100 | From | Jörn Engel <> | Subject | Re: [RFC] B+Tree library V2 |
| |
On Thu, 8 January 2009 18:10:01 +0100, Johannes Berg wrote: > 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_get_prev_key(head, geo, key); > key; key = tmp, tmp = btree_get_prev_key(head, geo, key))
[ Changed the function name above. It really isn't a lookup, it returns a key, not a value. My fault. ]
Looks correct otherwise. Probably needs a comment that without "tmp" we would skip a 0 key. Or am I the only one who wants to simplify the code before spotting this little subtlety?
> (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?
Not sure what you mean. Something with the same effect as this?
#define btree_for_each_val(head, geo, key, val) \ for (key = btree_last(head, geo), \ val = btree_lookup(head, geo, key); \ val; \ key = btree_get_prev_key(head, geo, key), \ val = btree_lookup(head, geo, key))
Jörn
-- Time? What's that? Time is only worth what you do with it. -- Theo de Raadt -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |