tree

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 8 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 struct {
	Encoded []byte
	// contains filtered or unexported fields
}

func NewEncodedKey

func NewEncodedKey(enc []byte) *Key

func NewKey

func NewKey(values ...types.Value) *Key

func (*Key) Decode

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

func (*Key) Encode

func (k *Key) Encode(ns Namespace, order SortOrder) ([]byte, error)

func (*Key) String

func (k *Key) String() string

type Namespace

type Namespace uint64

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.

type SortOrder

type SortOrder uint64

SortOrder is a 64-bit unsigned integer that represents the sort order (ASC or DESC) of each value in a key. By default, all values are sorted in ascending order. Each bit represents the sort order of the corresponding value in the key. SortOrder is used in a tree to encode keys. It can only support up to 64 values.

func (SortOrder) IsDesc

func (o SortOrder) IsDesc(i int) bool

func (SortOrder) SetAsc

func (o SortOrder) SetAsc(i int) SortOrder

func (SortOrder) SetDesc

func (o SortOrder) SetDesc(i int) SortOrder

type Tree

type Tree struct {
	Session   kv.Session
	Namespace Namespace
	Order     SortOrder
}

A Tree is an abstraction over a k-v store that allows manipulating data using high level keys and values of the Chai 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 Chai'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(session kv.Session, ns Namespace, order SortOrder) *Tree

func NewTransient

func NewTransient(session kv.Session, ns Namespace, order SortOrder) (*Tree, func() error, error)

func (*Tree) Delete

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

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

func (*Tree) Exists

func (t *Tree) Exists(key *Key) (bool, error)

Exists returns true if the key exists in the tree.

func (*Tree) Get

func (t *Tree) Get(key *Key) ([]byte, error)

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

func (*Tree) Insert

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

Insert adds a key-obj combination to the tree. If the key already exists, it returns kv.ErrKeyAlreadyExists.

func (*Tree) IterateOnRange

func (t *Tree) IterateOnRange(rng *Range, reverse bool, fn func(*Key, []byte) error) error

IterateOnRange iterates on all keys that are in the given range.

func (*Tree) NewMaxTypeForType

func (t *Tree) NewMaxTypeForType(tp types.ValueType) byte

func (*Tree) NewMaxTypeForTypeDesc

func (t *Tree) NewMaxTypeForTypeDesc(tp types.ValueType) byte

func (*Tree) NewMinTypeForType

func (t *Tree) NewMinTypeForType(tp types.ValueType) byte

func (*Tree) NewMinTypeForTypeDesc

func (t *Tree) NewMinTypeForTypeDesc(tp types.ValueType) byte

func (*Tree) NewMinValueForType

func (t *Tree) NewMinValueForType(tp types.ValueType) types.Value

func (*Tree) NewMinValueForTypeDesc

func (t *Tree) NewMinValueForTypeDesc(tp types.ValueType) types.Value

func (*Tree) Put

func (t *Tree) Put(key *Key, value []byte) error

Put adds or replaces a key-obj 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.

Jump to

Keyboard shortcuts

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