vtree

package module
v0.0.0-...-1ba79a5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

vtree

Vtree is an in-memory multi-version radix / patricia tree package for Golang.

Features
  • Immutable radix tree
  • Copy-on-write radix tree
  • Rich transaction support
  • Versioned key-value items
  • Select key-value items since a specific version
  • Insert, and delete key-value items with a specific version
  • Iterate through all versions of every key-value item
Installation
go get github.com/abcum/vtree

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Copy

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

Copy is a copy of a tree which can be used to apply changes to the radix tree. All changes are applied atomically and a new tree is returned when committed. A Copy is not thread safe.

func (*Copy) Cursor

func (c *Copy) Cursor() *Cursor

Cursor returns a new cursor for iterating through the radix tree.

func (*Copy) Cut

func (c *Copy) Cut(key []byte) []byte

Cut is used to delete a given key, returning the previous value.

func (*Copy) Del

func (c *Copy) Del(ver uint64, key []byte) []byte

Del is used to delete a given key, returning the previous value.

func (*Copy) Get

func (c *Copy) Get(ver uint64, key []byte) []byte

Get is used to retrieve a specific key, returning the current value.

func (*Copy) Put

func (c *Copy) Put(ver uint64, key, val []byte) []byte

Put is used to insert a specific key, returning the previous value.

func (*Copy) Root

func (c *Copy) Root() *Node

Root returns the root of the radix tree within this tree copy.

func (*Copy) Size

func (c *Copy) Size() int

Size is used to return the total number of elements in the tree.

func (*Copy) Tree

func (c *Copy) Tree() *Tree

Tree returns a new tree with the changes committed in memory.

type Cursor

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

Cursor represents an iterator that can traverse over all key-value pairs in a tree in sorted order. Cursors can be obtained from a transaction and are valid as long as the transaction is open. Changing data while traversing with a cursor may cause it to be invalidated and return unexpected keys and/or values. You must reposition your cursor after mutating data.

func (*Cursor) Del

func (c *Cursor) Del() ([]byte, interface{})

Del removes the current item under the cursor from the tree. If the cursor has not yet been positioned using First, Last, or Seek, then no item is deleted and a nil key and value are returned.

func (*Cursor) First

func (c *Cursor) First() ([]byte, *Item)

First moves the cursor to the first item in the tree and returns its key and value. If the tree is empty then a nil key and value are returned.

func (*Cursor) Last

func (c *Cursor) Last() ([]byte, *Item)

Last moves the cursor to the last item in the tree and returns its key and value. If the tree is empty then a nil key and value are returned.

func (*Cursor) Next

func (c *Cursor) Next() ([]byte, *Item)

Next moves the cursor to the next item in the tree and returns its key and value. If the tree is empty then a nil key and value are returned, and if the cursor is at the end of the tree then a nil key and value are returned. If the cursor has not yet been positioned using First, Last, or Seek, then a nil key and value are returned.

func (*Cursor) Prev

func (c *Cursor) Prev() ([]byte, *Item)

Prev moves the cursor to the previous item in the tree and returns its key and value. If the tree is empty then a nil key and value are returned, and if the cursor is at the start of the tree then a nil key and value are returned. If the cursor has not yet been positioned using First, Last, or Seek, then a nil key and value are returned.

func (*Cursor) Seek

func (c *Cursor) Seek(key []byte) ([]byte, *Item)

Seek moves the cursor to a given key in the tree and returns it. If the specified key does not exist then the next key in the tree is used. If no keys follow, then a nil key and value are returned.

type Item

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

Item represents a collection of versions and values, stored in order of version number.

func (*Item) Del

func (i *Item) Del(ver uint64) []byte

Del deletes a value with the specified version number, or the nearest latest value prior to the specified version.

func (*Item) Get

func (i *Item) Get(ver uint64) []byte

Get selects a value with the specified version number, or the nearest latest value prior to the specified version. If '0' is specified for the version, then the latest item will be returned.

func (*Item) Max

func (i *Item) Max() []byte

Max returns the value of the maximum version in the list.

func (*Item) Min

func (i *Item) Min() []byte

Min returns the value of the minium version in the list.

func (*Item) Put

func (i *Item) Put(ver uint64, val []byte) []byte

Put inserts a value with the specified version number. It returns the previous value, or nil if it does not exist.

func (*Item) Seek

func (i *Item) Seek(ver uint64) (uint64, []byte)

Seek searches for a value prior to the specified version number, and returns its version and value. If math.MinInt64 is specified for the version, then the first item will be returned, and if math.MaxInt64 is used then the latest item will be returned.

func (*Item) Walk

func (i *Item) Walk(fn func(ver uint64, val []byte) bool)

Walk iterates through all of the versions and values in the list, in order of version, starting at the first version.

type Node

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

Node represents an immutable node in the radix tree which can be either an edge node or a leaf node.

func (*Node) Max

func (n *Node) Max() ([]byte, *Item)

Max returns the key and value of the maximum item in the subtree of the current node.

func (*Node) Min

func (n *Node) Min() ([]byte, *Item)

Min returns the key and value of the minimum item in the subtree of the current node.

func (*Node) Path

func (n *Node) Path(k []byte, f Walker)

Path is used to recurse over the tree only visiting nodes which are above this node in the tree.

func (*Node) Subs

func (n *Node) Subs(k []byte, f Walker)

Subs is used to recurse over the tree only visiting nodes which are directly under this node in the tree.

func (*Node) Walk

func (n *Node) Walk(k []byte, f Walker)

Walk is used to recurse over the tree only visiting nodes which are under this node in the tree.

type Tree

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

Tree represents an immutable versioned radix tree.

func New

func New() *Tree

New returns an empty Tree

func (*Tree) Copy

func (t *Tree) Copy() *Copy

Copy starts a new transaction that can be used to mutate the tree

func (*Tree) Size

func (t *Tree) Size() int

Size is used to return the number of elements in the tree.

type Walker

type Walker func(key []byte, val *Item) (exit bool)

Walker represents a callback function which is to be used when iterating through the tree using Path, Subs, or Walk. It will be populated with the key and list of the current item, and returns a bool signifying if the iteration should be terminated.

Jump to

Keyboard shortcuts

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