GithubHelp home page GithubHelp logo

ifmo-b-tree's Introduction

B-tree

B-tree is a self-balancing tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic time. The B-tree is a generalization of a binary search tree in that a node can have more than two children. Unlike self-balancing binary search trees, the B-tree is optimized for systems that read and write large blocks of data. B-trees are a good example of a data structure for external memory. It is commonly used in databases and filesystems.

The Code:

  • Searching:
    • value(for:) method searches for the given key and if it's in the tree, it returns the value associated with it, else it returns nil.
  • Insertion:
    • The method insert(_:for:) does the insertion. After it has inserted a key, as the recursion goes up every node checks the number of keys in its child.
    • if a node has too many keys, its parent calls the split(child:atIndex:) method on it.
    • If the root has too many nodes after the insertion the tree calls the splitRoot() method.
  • Deletion:
    • remove(_:) method removes the given key from the tree. After a key has been deleted, every node checks the number of keys in its child. If a child has less nodes than the order of the tree, it calls the fix(childWithTooFewKeys:atIndex:) method.
    • fix(childWithTooFewKeys:atIndex:) method decides which way to fix the child (by moving a key to it, or by merging it), then calls move(keyAtIndex:to:from:at:) or merge(child:atIndex:to:) method according to its choice.

Benchmarks Results:

Helpful Links:

LICENSE

This project is open-sourced software licensed under the MIT License.

See the LICENSE file for more information.

ifmo-b-tree's People

Contributors

ivan-magda avatar

Watchers

 avatar  avatar

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.