Git Product home page Git Product logo

Comments (9)

gconnell avatar gconnell commented on September 27, 2024 1

Because the closest book I had on how to do BTrees used it ;)

from btree.

gconnell avatar gconnell commented on September 27, 2024 1

And it's my favorite :D

from btree.

gconnell avatar gconnell commented on September 27, 2024 1

I believe I got most of my stuff from https://en.wikipedia.org/wiki/Introduction_to_Algorithms

I'd also check out http://assets.en.oreilly.com/1/event/36/How%20TokuDB%20Fractal%20Tree%20Databases%20Work%20Presentation.pdf and https://en.wikipedia.org/wiki/Fractal_tree_index

from btree.

gconnell avatar gconnell commented on September 27, 2024

I believe this is actually working as intended.

In this BTree implementation, the tree makes a single pass down the tree to find/remove the node. All redistribution is done on the way down, none on the way up. Also, while traversing the tree, we only have a view of the current node and its direct children. Given that constraint, at each node we traverse we must assume the worst case about our children's children (that they have the least number of nodes they could possibly have) and act accordingly.

While in your case, the leaf node did have enough elements, the root node doesn't know that (it only sees itself and its children, not its children's children. Consider this case:

NODE:[11]
  NODE:[5 8]
    NODE:[1 2]
    NODE:[6 7]
    NODE:[9 10]
  NODE:[14 17]
    NODE:[12 13]
    NODE:[15 16]
    NODE:[18 19 20]

The root here says "my child has 2, and its child may have none to spare". So, it performs a merge before traversing down. By merging first, it knows that, should the child not have enough, its parent will have a spare value to give.

In short, we use option 2 of https://en.wikipedia.org/wiki/B-tree#Deletion: "Do a single pass down the tree, but before entering (visiting) a node, restructure the tree so that once the key to be deleted is encountered, it can be deleted without triggering the need for any further restructuring"

I believe that, had we implemented option 1 ("Locate and delete the item, then restructure the tree to retain its invariants"), the tree would behave as you expect and would not have rebalanced after the deletion of 1.

from btree.

cookieisaac avatar cookieisaac commented on September 27, 2024

Thanks for clarifying the assumptions. This implementation, by design, takes a proactive tree restructure approach during deletion to save one extra pass, instead of the reactive approach which aims to reduce unnecessary restructure operations. Agree to close the issue as "Working as Designed".

from btree.

CheyenneForbes avatar CheyenneForbes commented on September 27, 2024

Hey, why was the single pass strategy used instead of the other popular one?

from btree.

CheyenneForbes avatar CheyenneForbes commented on September 27, 2024

The Btree I implemented in C++ is designed to be used as a "disk btree" to be used at scale in my data management system... which implementation would you recommend that I use?

from btree.

gconnell avatar gconnell commented on September 27, 2024

I think single-pass is better for disk, but you could also look at fractal trees and the like that are even better for disk purposes.

from btree.

CheyenneForbes avatar CheyenneForbes commented on September 27, 2024

Okay, thanks... may I know which book you read?

from btree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.