First stab at a B+Tree

Hello,

I'm new to this forum, but I hope I came to the right place. I'm a loooong time python programmer and I've also done some C/C++, mainly to write python extensions.
I've played around with rust a few times over the years, but 2 months ago I decided to really try to get my head around it. And now I have written my first non-trivial program: a B+Tree (a file based key/value store).
It's only a start, but I would really love it if someone with some genuine rust-fu could do some code reviewing. You can find the code at:

TIA!
Wietse

3 Likes

cargo clippy points out some low-hanging fruit, and rustc will point out more if you remove the allow(...) attributes, but in general (based on a quick skim) this looks pretty good/idiomatic to me. Some small things:

  • I would probably return an Error instead of panicking when a deleted key is requested (lib.rs line 254)
  • When "printf debugging", like in tests::test_root, you can use the dbg macro for nicer output

In terms of future work, you should be able to lift the Copy constraints on keys and values by just deleting them from the code and letting the compiler errors guide you to where you need to insert .clone(). Actually I expect you don't even need Clone -- you can serialize stuff from a shared reference -- but getting there might require some more involved changes to the code.

1 Like

Thank you very much for taking the time! I will definitely follow up on your comments.
One thing: I’ve tried the dbg macro and - in the heat of debugging - it’s annoying that it consumes it’s arguments... I’ve tried debugging with gdb, but that will take a lot more practice before it’s effective.

Thanks again,
Wietse

Have you tried passing a reference? It will still print the pointed value's debug information.

2 Likes

Duh... next time I will!