Coder Social home page Coder Social logo

byjuandiego / b-plus-tree Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 2.66 MB

Memory-resident B+ tree implementation, supporting insertion, key based search, bound based search and range search operations.

License: Apache License 2.0

CMake 0.74% C++ 99.08% Shell 0.18%
range-query range-search tree-searching b-plus-tree

b-plus-tree's Introduction

B+ Tree C++ implementation

BPlusTree

Run the project

This project do not use any dependencies, just the Standard Template Library

git clone https://github.com/ByJuanDiego/b-plus-tree.git
cd b-plus-tree
chmod +x run.zsh
./run.zsh

Member functions

All the search operations returns an std::list<V> and are made on a $O(log_{M}(n) + k)$ time complexity, where $k$ is the cost of traversing the leaf nodes and could be different depending on the type of search, and the logarithmic function belongs to the cost of descending in the tree.

Member Function Optional Parameters
search_below(K upper_bound, bool include_max) the search returned do not include the superior limit for default, to include it, set the optional parameter include_max as true
search_above(K lower_bound, bool include_min) the search returned do not include the inferior limit for default, to include it, set the optional parameter include_min as true
search_between(K lower_bound, K upper_bound, bool include_min, bool include_max) the search returned includes both limits (inferior and superior) for default; to exclude one or both limits, set the include_min or include_max values to false depending on the desired semantic

Usage Cases

Initialization

auto index = [&](const transaction *tx) -> int { return tx->amount; };
auto greater = [&](int a, int b) -> bool { return a > b; };
b_plus_tree<4, int, transaction *, decltype(greater), decltype(index)> bPlusTree(index, greater);

index function recieves a value and returns the attribute that will be used for indexing values

greater is a function that, trivially, returns if an indexing value is greater than another

  • this last function do not need to be passed as parameter; in that case, the type is assigned to std::greater by default. If the indexing attribute is not a comparable type by default (which is not recommendable) a specialization of std::greater is necesary

Querying

int min{10}, max{97};
bool include_min{true}, include_max{false};
for (const transaction *tx: bPlusTree.search_between(min, max, include_min, include_max)) {
    std::cout << tx->to_string() << std::endl;
}

This query returns all the transactions which amount value is between 10 (inclusive) and 97 (exclusive) in a non-decreasing order.

Freeing memory

If the value-type is a pointer, the pointed values will not be freed when b_plus_tree::~b_plus_tree is called. This is manual process.

for (transaction *tx: destructor) {
    delete tx;
}

To manage this situation, optionally, a std::shared_ptr could be used.

To be implemented

  • iterator class for B+

b-plus-tree's People

Contributors

byjuandiego avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.