google / btree

BTree provides a simple, ordered, in-memory data structure for Go programs.
Apache License 2.0
3.97k stars 420 forks source link

backwards iteration #7

Closed tidwall closed 8 years ago

tidwall commented 8 years ago

Added DescendRange, DescendLessOrEqual, DescendGreaterThan, and Descend functions. These are modeled after the existing Ascend.. methods.

Also modified the iteration function to remove the from() and to() in favor of adding a start and stop parameters instead. There is a modest performance ~10% boost by avoiding superfluous function calls.

before:

BenchmarkAscend-8          10000        216529 ns/op
BenchmarkAscendRange-8      3000        433896 ns/op

after:

BenchmarkAscend-8          10000        196143 ns/op
BenchmarkAscendRange-8      3000        396469 ns/op

The benchmark code is not included in the source, but I did create a gist at iteration_test.go

I hope you find this update useful and thanks a ton for such a fantastic library!

gconnell commented 8 years ago

Hey, just saw this as it was closed. I've been on an extended vacation June-August, so this must have come in right as I was leaving. Appologies for the delay, but if it's something you'd still like to do, let me know.

tidwall commented 8 years ago

Sure, that would be great. Thanks!

gconnell commented 8 years ago

Ping this once the above changes (benchmarks, coment changes on reverse ranges) are in place, and I think we should be good to go.

tidwall commented 8 years ago

Sounds good. Thanks.

tidwall commented 8 years ago

Ping

I made the changes a few weeks back, but forgot to ping like you asked. Sorry.

gconnell commented 8 years ago

Merged, thanks!