btree

package module
v0.0.0-...-5a02cf2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Ondisk BTree implementation for Go

This package provides simple ondisk BTree implementation for Go.

Since code base is relatively small, it's suitable to learn about datastructure, storage engine and database.

The implementation is mainly inspired by Database Internals (2019 Alex Petrov).

Note that validation is minimum to keep simplicity of source code.

Install

go get -u github.com/opeco17/ondisk-btree

Usage

import btree "github.com/opeco17/ondisk-btree"

type Book struct {
	ID     int
	Name   string
	Author string `maxLength:"64"`
}

func (book Book) GetKey() int64 {
	return int64(book.ID)
}

func main() {
	btree, _ := btree.New[Book](btree.DEFAULT_DATA_PATH, btree.DEFAULT_DEGREE)
	defer btree.Close()

	btree.Put(&Book{ID: 0, Name: "Database Internals", Author: "Alex Petrov"})
	btree.Put(&Book{ID: 1, Name: "Designing Data-Intensive Applications", Author: "Martin Kleppmann"})

	btree.Delete(1)

	book, _ := btree.Get(0)
}

Documentation

Index

Constants

View Source
const DEFAULT_DATA_PATH = "btree.bin"
View Source
const DEFAULT_DEGREE = 3
View Source
const DEFAULT_STRING_MAX_LENGTH = 256
View Source
const LENGTH_IN_NODE_BYTE = 8
View Source
const OFFSET_SIZE_BYTE = 8

Variables

Functions

This section is empty.

Types

type BTree

type BTree[T Item] struct {
	// contains filtered or unexported fields
}

func New

func New[T Item](path string, degree int) (*BTree[T], error)

func (*BTree[T]) Close

func (btree *BTree[T]) Close() error

func (*BTree[T]) Delete

func (btree *BTree[T]) Delete(key KeyType) error

func (*BTree[T]) Get

func (btree *BTree[T]) Get(key KeyType) (*T, error)

func (*BTree[T]) Put

func (btree *BTree[T]) Put(item *T) error

func (*BTree[T]) Show

func (btree *BTree[T]) Show() error

type Element

type Element[T Item] struct {
	// contains filtered or unexported fields
}

type Item

type Item interface {
	GetKey() KeyType
}

type KeyType

type KeyType = int64

type LengthInNodeType

type LengthInNodeType = int64

type Node

type Node[T Item] struct {
	// contains filtered or unexported fields
}

type OffsetType

type OffsetType = int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL