Giter Site home page Giter Site logo

bptree's Introduction

bptree

bptree is a pure Go B+ tree implementation. The project started out as a Go copy of Amittai Aviram's C implementation. The goal of the project is to maintain a tiny B+ tree with a concise API to use in the composition of more complex systems.

Project Roadmap

Please submit issues/PRs for anything else you'd like to see in this package.

Getting Started

Installing

To get started using bptree, install Go and run go get

$ go get github.com/collinglass/bptree

This will retrieve the library, your project is now ready to use bptree.

Example

package main

import (
	"fmt"
	"github.com/collinglass/bptree"
)

func main() {
	key := 1
	value := []byte("hello friend")

	t := bptree.NewTree()

	err := t.Insert(key, value)
	if err != nil {
		fmt.Printf("error: %s\n\n", err)
	}

	r, err := t.Find(key, true)
	if err != nil {
		fmt.Printf("error: %s\n\n", err)
	}

	fmt.Printf("%s\n\n", r.Value)

	t.FindAndPrint(key, true)
}

API

func NewTree()

func NewTree() *Tree

Returns a pointer to a new B+ tree

func (t *Tree) Insert

func (t *Tree) Insert(key, value int) (*node, error)

Insert adds a key value pair to the b+ tree.

func (t *Tree) Find

func (t *Tree) Find(key int, verbose bool) (*record, error)

Find returns the value associated with the key. If verbose is true, it gives some insight on its location in the tree.

func (t *Tree) FindAndPrint

func (t *Tree) FindAndPrint(key int, verbose bool)

FindAndPrint outputs the value associated with the key. If verbose is true, it gives added insight.

func (t *Tree) FindAndPrintRange

func (t *Tree) FindAndPrintRange(key_start, key_end int, verbose bool)

FindAndPrintRange outputs the values associated with the keys inside of the range inclusive.

func (t *Tree) PrintTree

func (t *Tree) PrintTree(root *node)

Prints the whole tree.

func (t *Tree) PrintLeaves

func (t *Tree) PrintLeaves()

Prints the leaves of the tree.

bptree's People

Watchers

James Cloos 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.