Code Monkey home page Code Monkey logo

bp_tree's Introduction

bp_tree

Build Status

An Erlang implementation of B+ tree.

Build

Dependencies:

  • erlang >= 18.0
  • make

Once you have all of the dependencies, simply run make in bp_tree directory to build it.

User Guide

Add bp_tree as a rebar dependency to your project:

{deps, [
  {bp_tree, "1.0.0", {git, "https://github.com/krzysztof-trzepla/bp_tree.git", {tag, "1.0.0"}}}
}.

API

In order to create a B+ tree a init function from a bp_tree module should be called. Overloaded init/1 function accepts following options:

  • order - each node of a tree will hold up to 2 * order keys and 2 * order + 1 values (default: 50),
  • store_module - the name of a tree store backend module (default: bp_tree_map_store),
  • store_args - list of arguments that will be passed to init/1 function of store_module module (default: []).

A bp_tree module provides standard B+ tree operations:

  • find/2 - search key in a tree and return associated value,
  • insert/3 - store key-value pair in a tree (keys must be unique),
  • remove/2 - remove key and associated value from a tree.

In addition to standard operations a fold operation is provided. It allows for iterating over B+ tree leaf in a similar fashion to lists:foldl/3 function. It accepts following options:

  • start_key - key from which start iteration (inclusive), start_key takes precedence over offset (by default the leftmost - smallest - key),
  • end_key - key on which stop iteration (inclusive) (by default the rightmost - largest - key),
  • offset - distance from the leftmost key from which start iteration (default: 0),
  • total_size - how many key in total should be iterated (by default return all nodes),
  • batch_size - how many key should be iterated in terms of a batch (by default use single batch).

fold will iterate keys in batch if batch_size option is provided. For batch iteration a continuation token is returned which should be passed to an overloaded fold function in order to continue iteration. It is guaranteed that iterated keys are provided in a strictly increasing order, even if fold operation is interleaved with insert operations.

Tree store backend

The bp_tree uses bp_tree_store module to save, access and modify tree structure. The bp_tree_store uses yet another customizable module as a storage backend, which must implement bp_tree_store behaviour. Default bp_tree_store storage backend is bp_tree_map_store, which stores tree nodes in a map. There is also bp_tree_ets_store module that holds tree structure in an ETS. It is easy to add new storage by creating new module implementing bp_tree_store behaviour and passing its name as store_module option to init/1 function.

Test

$ make test

bp_tree's People

Contributors

krzysztof-trzepla avatar

Stargazers

 avatar  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.