google / btree

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

Added GetAt(i), which returns the ith item. #15

Closed darfire closed 4 years ago

darfire commented 8 years ago

Added a method that returns the ith item in the btree. In order to do this, each node has an idea of the number of items in the tree of which it is the root. I've updated all relevant insert/delete functions to maintain each node's length. The performance is unchanged.

Looking forward to suggestions that can improve this feature. Cheers.

googlebot commented 8 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


darfire commented 8 years ago

Signed

On Sun, Oct 16, 2016 at 10:30 PM, googlebot notifications@github.com wrote:

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll

verify. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/btree/pull/15#issuecomment-254068518, or mute the thread https://github.com/notifications/unsubscribe-auth/ADG9vzSLnOK3ePwJ3m4kqU0lPf1YL8t5ks5q0ns7gaJpZM4KYDrF .

googlebot commented 8 years ago

CLAs look good, thanks!

gconnell commented 8 years ago

Interesting, what's the use case for this?

darfire commented 8 years ago

My use case was that I needed to draw a random item from my btree, which I was using as a set. With this is just GetAt(randInt(t.Len()))

Having this, we can also implement other operations like split/join on btrees, if needed.

On Mon, Oct 17, 2016 at 6:38 PM, Graeme Connell notifications@github.com wrote:

Interesting, what's the use case for this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/btree/pull/15#issuecomment-254244661, or mute the thread https://github.com/notifications/unsubscribe-auth/ADG9v5XVXjRoVpOrR1Ek2epfJNQKTOzcks5q05aKgaJpZM4KYDrF .