tree

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key []byte

func NewKey

func NewKey(values ...types.Value) (Key, error)

func NewMaxKeyForType

func NewMaxKeyForType(t types.ValueType) Key

func NewMinKeyForType

func NewMinKeyForType(t types.ValueType) Key

func (Key) Decode

func (key Key) Decode() ([]types.Value, error)

func (Key) String

func (k Key) String() string

type Keys

type Keys []Key

func (Keys) Len

func (a Keys) Len() int

func (Keys) Less

func (a Keys) Less(i, j int) bool

func (Keys) Swap

func (a Keys) Swap(i, j int)

type Range

type Range struct {
	Min, Max  Key
	Exclusive bool
}

A Range of keys to iterate on. By default, Min and Max are inclusive. If Exclusive is true, Min and Max are excluded from the results. If Type is provided, the results will be filtered by that type.

type Tree

type Tree struct {
	Store engine.Store
	Codec encoding.Codec
}

A Tree is an abstraction over a k-v store that allows manipulating data using high level keys and values of the Genji type system. Trees are used as the basis for tables and indexes. The key of a tree is a composite combination of several values, while the value can be any value of Genji's type system. The tree ensures all keys are sort-ordered according to the rules of the types package operators. A Tree doesn't support duplicate keys.

func New

func New(store engine.Store, codec encoding.Codec) *Tree

func (*Tree) Delete

func (t *Tree) Delete(key Key) error

Delete a key from the tree. If the key doesn't exist, it returns engine.ErrKeyNotFound.

func (*Tree) Get

func (t *Tree) Get(key Key) (value types.Value, err error)

Get a key from the tree. If the key doesn't exist, it returns engine.ErrKeyNotFound.

func (*Tree) Iterate

func (t *Tree) Iterate(pivot Key, reverse bool, fn func(Key, types.Value) error) error

Iterate over the tree. If the pivot is nil and reverse is false, it iterates from the lowest key onwards. If the pivot is nil and reverse if true, it iterates from the highest key downwards. If the pivot is not nil, it seeks that key in the tree before iterating over anything equal, and higher or lower depending on if reverse is false or true.

func (*Tree) IterateOnRange

func (t *Tree) IterateOnRange(rng *Range, reverse bool, fn func(Key, types.Value) error) error

IterateOnRange iterates on all keys that are in the given range. Depending on the direction, the range is translated to the following table: | SQL | Range | Direction | Seek | End | | ----- | ---------------- | --------- | ------- | ------- | | = 10 | Min: 10, Max: 10 | ASC | 10 | 10 | | > 10 | Min: 10, Excl | ASC | 10+0xFF | nil | | >= 10 | Min: 10 | ASC | 10 | nil | | < 10 | Max: 10, Excl | ASC | nil | 10 excl | | <= 10 | Max: 10 | ASC | nil | 10 | | = 10 | Min: 10, Max: 10 | DESC | 10+0xFF | 10 | | > 10 | Min: 10, Excl | DESC | nil | 10 excl | | >= 10 | Min: 10 | DESC | nil | 10 | | < 10 | Max: 10, Excl | DESC | 10 | nil | | <= 10 | Max: 10 | DESC | 10+0xFF | nil |

func (*Tree) Put

func (t *Tree) Put(key Key, value types.Value) error

Put adds or replaces a key-value combination to the tree. If the key already exists, its value will be replaced by the given value.

func (*Tree) Truncate

func (t *Tree) Truncate() error

Truncate the tree.

type Value

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

Value is an implementation of the types.Value interface returned by Tree. It is used to lazily decode values from the underlying store.

func (*Value) MarshalJSON

func (v *Value) MarshalJSON() ([]byte, error)

func (*Value) MarshalText

func (v *Value) MarshalText() ([]byte, error)

func (*Value) String

func (v *Value) String() string

func (*Value) Type

func (v *Value) Type() types.ValueType

func (*Value) V

func (v *Value) V() interface{}

Jump to

Keyboard shortcuts

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