tree

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator added in v0.17.0

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

func (*Iterator) Key added in v0.17.0

func (it *Iterator) Key() *Key

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   engine.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 engine.Session, ns Namespace, order SortOrder) *Tree

func NewTransient

func NewTransient(session engine.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 engine.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 engine.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 engine.ErrKeyAlreadyExists.

func (*Tree) Iterator added in v0.17.0

func (t *Tree) Iterator(rng *Range) (*Iterator, error)

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