From: "Jörn Engel" <joern@logfs.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC] B+Tree library V2
Date: Thu, 8 Jan 2009 22:09:10 +0100 [thread overview]
Message-ID: <20090108210910.GE24884@logfs.org> (raw)
In-Reply-To: <1231445935.8398.18.camel@johannes>
On Thu, 8 January 2009 21:18:55 +0100, Johannes Berg wrote:
>
> > 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?
>
> I, uh, I didn't even realise that. I think the code for
> btree_last/btree_get_prev_key isn't correct as is since the 0 key is
> valid, but you can't tell whether it returned 0 because it didn't find
> anything, or because there was no more entry. Or am I missing something?
Correct or not is a matter of opinion, so let's not go there. It
certainly is unexpected and also inefficient. The alternative would be
to return two values, they key and a flag to indicate the end.
> > > (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))
>
> Well, that does lots of lookups that don't seem necessary, since a
> function like btree_last should be able to return the value right away.
> Also, if it was
>
> #define btree_for_each_val(head, geo, key, val)
> for (val = btree_last(head, geo, &key);
> val;
> val = btree_get_prev(head, geo, &key))
>
> it would be more correct, I think?
More efficient, certainly. Half the tree walks are gone. Let's do it.
Note, btw, that this changes effort from O(2n) to O(n), while the old
visitor is O(1) *). That was the reason why I wrote it in the first
place. If the code wasn't as horrible and hard to use, it would be a
clear winner. Guess we'll have to keep both variants.
*) Or rather O(2n*log(n)), O(n*log(n)) and O(log(n)) respectively.
Jörn
--
Joern's library part 6:
http://www.gzip.org/zlib/feldspar.html
next prev parent reply other threads:[~2009-01-08 21:09 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-26 12:46 [RFC] B+Tree library Jörn Engel
2008-10-28 1:25 ` Dave Chinner
2008-10-30 17:43 ` Pavel Machek
2008-10-30 17:58 ` Jörn Engel
2008-10-30 19:14 ` Pavel Machek
2008-10-30 20:20 ` Jörn Engel
2008-10-31 6:38 ` Christian Borntraeger
2008-10-31 7:35 ` Jörn Engel
2008-10-31 9:16 ` Geert Uytterhoeven
2008-10-31 9:20 ` Jörn Engel
2008-10-31 10:35 ` Johannes Berg
2008-10-31 11:26 ` Jörn Engel
2008-10-31 11:32 ` Johannes Berg
2008-10-31 12:54 ` Jörn Engel
2008-10-31 13:07 ` Johannes Berg
2008-10-31 13:15 ` Jörn Engel
2008-11-01 15:59 ` [RFC] B+Tree library V2 Jörn Engel
2008-11-05 19:57 ` Johannes Berg
2008-11-05 20:06 ` Jörn Engel
2008-11-05 20:12 ` Johannes Berg
2008-11-05 20:21 ` Jörn Engel
2008-11-05 20:25 ` Johannes Berg
2008-11-07 7:52 ` Jörn Engel
2009-01-08 0:57 ` Johannes Berg
2009-01-08 16:24 ` Jörn Engel
2009-01-08 16:34 ` Johannes Berg
2009-01-08 19:40 ` Jörn Engel
2009-01-08 16:50 ` Johannes Berg
2009-01-08 19:46 ` Jörn Engel
2009-01-08 17:10 ` Johannes Berg
2009-01-08 20:02 ` Jörn Engel
2009-01-08 20:18 ` Johannes Berg
2009-01-08 21:09 ` Jörn Engel [this message]
2008-10-31 13:16 ` [RFC] B+Tree library Johannes Berg
2008-10-31 13:29 ` Jörn Engel
2008-10-31 13:45 ` Bert Wesarg
2008-10-31 15:18 ` Tim Gardner
2008-10-31 15:35 ` Jörn Engel
2008-10-31 20:17 ` Sean Young
2008-10-31 23:36 ` Jörn Engel
2008-11-01 10:17 ` Sean Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090108210910.GE24884@logfs.org \
--to=joern@logfs.org \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox