tinybtree

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: MIT Imports: 1 Imported by: 2

README

tinybtree

GoDoc

Just an itsy bitsy b-tree.

Usage

Keys are strings, values are interfaces.

Functions
Get(key string) (value interface{}, gotten bool)
Set(key string, value interface{}) (prev interface{}, replaced bool)
Delete(key string) (prev interface{}, deleted bool)
Scan(iter func(key string, value interface{}) bool)
Ascend(pivot string, iter func(key string, value interface{}) bool)
Descend(pivot string, iter func(key string, value interface{}) bool)
Example
// Create a btree
var tr tinybtree.BTree

// Set a key. Returns the previous value and ok a previous value exists.
prev, ok := tr.Set("hello", "world")

// Get a key. Returns the value and ok if the value exists.
value, ok := tr.Get("hello")

// Delete a key. Returns the deleted value and ok if the previous value exists.
prev, ok := tr.Delete("hello")

Contact

Josh Baker @tidwall

License

tinybtree source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BTree

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

BTree is an ordered set of key/value pairs where the key is a string and the value is an interface{}

func (*BTree) Ascend

func (tr *BTree) Ascend(
	pivot string,
	iter func(key string, value interface{}) bool,
)

Ascend the tree within the range [pivot, last]

func (*BTree) Delete

func (tr *BTree) Delete(key string) (prev interface{}, deleted bool)

Delete a value for a key

func (*BTree) Descend

func (tr *BTree) Descend(
	pivot string,
	iter func(key string, value interface{}) bool,
)

Descend the tree within the range [pivot, first]

func (*BTree) Get

func (tr *BTree) Get(key string) (value interface{}, gotten bool)

Get a value for key

func (*BTree) Len

func (tr *BTree) Len() int

Len returns the number of items in the tree

func (*BTree) Reverse

func (tr *BTree) Reverse(iter func(key string, value interface{}) bool)

Reverse interates over all items in tree, in reverse.

func (*BTree) Scan

func (tr *BTree) Scan(iter func(key string, value interface{}) bool)

Scan all items in tree

func (*BTree) Set

func (tr *BTree) Set(key string, value interface{}) (prev interface{}, replaced bool)

Set or replace a value for a key

Jump to

Keyboard shortcuts

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