btree

package module
v0.0.0-...-3e46ece Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2015 License: BSD-2-Clause-Views Imports: 9 Imported by: 1

README

Btree library

This is pure golang btree library. it's copy on write btree.

go get github.com/datastream/btree

API

NewRecord(key, value []byte)

create a record

NewBtree()

create a btree

LEAFSIZE = 1 << 5
NODESIZE = 1 << 6
NewBtreeSize(leafsize, nodesize)

create new btree with custom leafsize/nodesize

btree.Insert(key, value)

Insert a record, if insert success, it return nil

btree.Update(key, value)

Update a record, if update success, it return nil

btree.Delete(key)

Delete a record, if delete success, it return nil

btree.Search(key)

Search a key, if find success, it return value, nil

btree.Marshal(filename)

Write btree data into disk.

tree.Dump("treedump")
btree.Unmarshal(filename)

Read btree from disk

TODO

  1. more test
  2. code tunning for performance or mem

Documentation

Overview

Package btree is a generated protocol buffer package.

It is generated from these files:

metadata.proto

It has these top-level messages:

BtreeMetadata
TreeNode
TreeLog

Index

Constants

View Source
const (
	// TreeSize is  tree size
	TreeSize = 1 << 10
	// LeafSize is leaf size
	LeafSize = 1 << 5
	// NodeSize is node size
	NodeSize = 1 << 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Btree

type Btree struct {
	BtreeMetadata
	// contains filtered or unexported fields
}

Btree metadata

func NewBtree

func NewBtree() *Btree

NewBtree create a btree

func NewBtreeSize

func NewBtreeSize(leafsize int64, nodesize int64) *Btree

NewBtreeSize create new btree with custom leafsize/nodesize

func Unmarshal

func Unmarshal(filename string) (*Btree, error)

Unmarshal btree from disk

func (*Btree) Delete

func (t *Btree) Delete(key []byte) error

Delete can delete record

func (*Btree) Insert

func (t *Btree) Insert(key, value []byte) error

Insert can insert record into a btree

func (*Btree) Marshal

func (t *Btree) Marshal(filename string) error

Marshal btree to disk

func (*Btree) PrintInfo

func (t *Btree) PrintInfo()

PrintInfo print some basic btree info

func (*Btree) PrintTree

func (t *Btree) PrintTree()

PrintTree print all btree's leafs/nodes

func (*Btree) Search

func (t *Btree) Search(key []byte) ([]byte, error)

Search return value

func (*Btree) Sync

func (t *Btree) Sync(file string)

func (*Btree) Update

func (t *Btree) Update(key, value []byte) error

Update is used to update key/value

type BtreeMetadata

type BtreeMetadata struct {
	Root             *int64   `protobuf:"varint,1,opt,name=root" json:"root,omitempty"`
	Size             *int64   `protobuf:"varint,3,opt,name=size" json:"size,omitempty"`
	LeafMax          *int64   `protobuf:"varint,4,opt,name=leaf_max" json:"leaf_max,omitempty"`
	NodeMax          *int64   `protobuf:"varint,5,opt,name=node_max" json:"node_max,omitempty"`
	IndexCursor      *int64   `protobuf:"varint,7,opt,name=index_cursor" json:"index_cursor,omitempty"`
	Index            *int64   `protobuf:"varint,8,opt,name=index" json:"index,omitempty"`
	Nodes            [][]byte `protobuf:"bytes,9,rep,name=nodes" json:"nodes,omitempty"`
	XXX_unrecognized []byte   `json:"-"`
}

func (*BtreeMetadata) GetIndex

func (m *BtreeMetadata) GetIndex() int64

func (*BtreeMetadata) GetIndexCursor

func (m *BtreeMetadata) GetIndexCursor() int64

func (*BtreeMetadata) GetLeafMax

func (m *BtreeMetadata) GetLeafMax() int64

func (*BtreeMetadata) GetNodeMax

func (m *BtreeMetadata) GetNodeMax() int64

func (*BtreeMetadata) GetNodes

func (m *BtreeMetadata) GetNodes() [][]byte

func (*BtreeMetadata) GetRoot

func (m *BtreeMetadata) GetRoot() int64

func (*BtreeMetadata) GetSize

func (m *BtreeMetadata) GetSize() int64

func (*BtreeMetadata) ProtoMessage

func (*BtreeMetadata) ProtoMessage()

func (*BtreeMetadata) Reset

func (m *BtreeMetadata) Reset()

func (*BtreeMetadata) String

func (m *BtreeMetadata) String() string

type TreeLog

type TreeLog struct {
	Action           *string `protobuf:"bytes,1,opt,name=action" json:"action,omitempty"`
	Key              []byte  `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"`
	Value            []byte  `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

func (*TreeLog) GetAction

func (m *TreeLog) GetAction() string

func (*TreeLog) GetKey

func (m *TreeLog) GetKey() []byte

func (*TreeLog) GetValue

func (m *TreeLog) GetValue() []byte

func (*TreeLog) ProtoMessage

func (*TreeLog) ProtoMessage()

func (*TreeLog) Reset

func (m *TreeLog) Reset()

func (*TreeLog) String

func (m *TreeLog) String() string

type TreeNode

type TreeNode struct {
	Id               *int64   `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
	Keys             [][]byte `protobuf:"bytes,2,rep,name=keys" json:"keys,omitempty"`
	Childrens        []int64  `protobuf:"varint,3,rep,name=childrens" json:"childrens,omitempty"`
	Values           [][]byte `protobuf:"bytes,4,rep,name=values" json:"values,omitempty"`
	NodeType         *int32   `protobuf:"varint,5,opt,name=node_type" json:"node_type,omitempty"`
	IsDirt           *int32   `protobuf:"varint,6,opt,name=is_dirt" json:"is_dirt,omitempty"`
	XXX_unrecognized []byte   `json:"-"`
}

func (*TreeNode) GetChildrens

func (m *TreeNode) GetChildrens() []int64

func (*TreeNode) GetId

func (m *TreeNode) GetId() int64

func (*TreeNode) GetIsDirt

func (m *TreeNode) GetIsDirt() int32

func (*TreeNode) GetKeys

func (m *TreeNode) GetKeys() [][]byte

func (*TreeNode) GetNodeType

func (m *TreeNode) GetNodeType() int32

func (*TreeNode) GetValues

func (m *TreeNode) GetValues() [][]byte

func (*TreeNode) ProtoMessage

func (*TreeNode) ProtoMessage()

func (*TreeNode) Reset

func (m *TreeNode) Reset()

func (*TreeNode) String

func (m *TreeNode) String() string

Jump to

Keyboard shortcuts

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