btree

package
v0.0.0-...-c1fb98d Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package BTree functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLeaf

func IsLeaf(node *BNode) bool

Return true if the node is leaf

Types

type BNode

type BNode struct {
	Parent   *BNode
	Entries  []*Entry // Contained keys in node
	Children []*BNode // Children nodes
}

Node

func NewBNode

func NewBNode(p *BNode, entry []*Entry, child []*BNode) *BNode

New BTree Node

type BTree

type BTree struct {
	Root *BNode // Root node
	// contains filtered or unexported fields
}

B-Tree object

func NewBTree

func NewBTree(order int, comp goutils.TypeComparator) *BTree

New B Tree

func (*BTree) Clear

func (t *BTree) Clear()

Removes all nodes

func (*BTree) FromJSON

func (t *BTree) FromJSON(data []byte) error

FromJSON Convert to JSON format the elements

func (*BTree) Get

func (t *BTree) Get(key interface{}) interface{}

Get Value

func (*BTree) Height

func (t *BTree) Height() int

Returns the height

func (*BTree) IsEmpty

func (t *BTree) IsEmpty() bool

IsEmpty, true if tree doesnt have nodes

func (*BTree) Iterator

func (t *BTree) Iterator() Iterator

Iterator returns a stateful iterator whose elements are key/value pairs.

func (*BTree) Keys

func (t *BTree) Keys() []interface{}

Keys returns all keys in-order

func (*BTree) Left

func (t *BTree) Left() *BNode

Return minimum element

func (*BTree) LeftKey

func (t *BTree) LeftKey() interface{}

LeftKey returns the left-most (min) key or nil if tree is empty.

func (*BTree) LeftValue

func (t *BTree) LeftValue() interface{}

LeftValue returns the left-most value or nil if tree is empty.

func (*BTree) Put

func (t *BTree) Put(key interface{}, value interface{})

Put inserts key-value pair node into the tree

func (*BTree) Remove

func (t *BTree) Remove(key interface{})

Remove Node by key

func (*BTree) Right

func (t *BTree) Right() *BNode

Return maximum element

func (*BTree) RightKey

func (t *BTree) RightKey() interface{}

RightKey returns the right-most (max) key or nil if tree is empty.

func (*BTree) RightValue

func (t *BTree) RightValue() interface{}

RightValue returns the right-most value or nil if tree is empty.

func (*BTree) Size

func (t *BTree) Size() int

Return Size of tree

func (*BTree) String

func (t *BTree) String() string

String returns a string representation of container (for debugging purposes)

func (*BTree) ToJSON

func (t *BTree) ToJSON() ([]byte, error)

ToJSON return JSON format of elements

func (*BTree) Values

func (t *BTree) Values() []interface{}

Values returns all values in-order based on the key.

type Entry

type Entry struct {
	Key   interface{}
	Value interface{}
}

Entry is the key-value pair in node

func NewEntry

func NewEntry(key, value interface{}) *Entry

New Entry

func (*Entry) String

func (entry *Entry) String() string

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator holding the iterator's state

func (*Iterator) Begin

func (iterator *Iterator) Begin()

Set pointer to Begin state

func (*Iterator) End

func (iterator *Iterator) End()

Set pointer to last state

func (*Iterator) First

func (iterator *Iterator) First() bool

Moves to the first element

func (*Iterator) Key

func (iterator *Iterator) Key() interface{}

Return current Key

func (*Iterator) Last

func (iterator *Iterator) Last() bool

Moves to the Last element

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Moves to the next element

func (*Iterator) Prev

func (iterator *Iterator) Prev() bool

Move to the Prev element

func (*Iterator) Value

func (iterator *Iterator) Value() interface{}

Return current value

Jump to

Keyboard shortcuts

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