index

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StorePrefix is the prefix used to name the index store.
	StorePrefix = "i" + string(separator)
)

Variables

View Source
var (
	// ErrDuplicate is returned when a value is already associated with a key
	ErrDuplicate = errors.New("duplicate")
)

Functions

func EncodeFieldToIndexValue added in v0.5.0

func EncodeFieldToIndexValue(val document.Value) ([]byte, error)

EncodeFieldToIndexValue returns a byte array that represents the value in such a way that can be compared for ordering and indexing

Types

type Index

type Index interface {
	// Set associates a value with a key.
	Set(val document.Value, key []byte) error

	// Delete all the references to the key from the index.
	Delete(val document.Value, key []byte) error

	// AscendGreaterOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in increasing order and calls the given function for each pair.
	// If the given function returns an error, the iteration stops and returns that error.
	// If the pivot is nil, starts from the beginning.
	AscendGreaterOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

	// DescendLessOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in descreasing order and calls the given function for each pair.
	// If the given function returns an error, the iteration stops and returns that error.
	// If the pivot is nil, starts from the end.
	DescendLessOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

	// Truncate deletes all the index data.
	Truncate() error
}

An Index associates encoded values with keys. It is sorted by value following the lexicographic order.

type ListIndex added in v0.4.0

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

ListIndex is an implementation that associates a value with a list of keys.

func NewListIndex added in v0.4.0

func NewListIndex(tx engine.Transaction, idxName string) *ListIndex

NewListIndex creates an index that associates a value with a list of keys.

func (*ListIndex) AscendGreaterOrEqual added in v0.4.0

func (i *ListIndex) AscendGreaterOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

AscendGreaterOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in increasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the beginning.

func (*ListIndex) Delete added in v0.4.0

func (i *ListIndex) Delete(val document.Value, key []byte) error

Delete all the references to the key from the index.

func (*ListIndex) DescendLessOrEqual added in v0.4.0

func (i *ListIndex) DescendLessOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

DescendLessOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in descreasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the end.

func (*ListIndex) Set added in v0.4.0

func (i *ListIndex) Set(val document.Value, key []byte) error

Set associates a value with a key. It is possible to associate multiple keys for the same value but a key can be associated to only one value.

func (*ListIndex) Truncate added in v0.4.0

func (i *ListIndex) Truncate() error

Truncate deletes all the index data.

type Pivot added in v0.4.0

type Pivot struct {
	Value document.Value
	// contains filtered or unexported fields
}

A Pivot is a value that is used to seek for a particular value in an index. A Pivot is typed and can only be used to seek for values of the same type.

func EmptyPivot added in v0.3.0

func EmptyPivot(t document.ValueType) *Pivot

EmptyPivot returns a pivot that starts at the beginning of any indexed values compatible with the given type.

type Type added in v0.3.0

type Type byte

Type of the index. Values are stored in different sub indexes depending on their types. They are automatically converted to one of the following types:

Text and Blob values are stored in Bytes indexes. Signed, unsigned integers, and floats are stored in Float indexes. Booleans are stores in Bool indexes.

const (
	Null Type = iota + 1
	Bool
	Float
	Bytes
)

index value types

func NewTypeFromValueType added in v0.3.0

func NewTypeFromValueType(t document.ValueType) Type

NewTypeFromValueType returns the right index type associated with t.

type UniqueIndex added in v0.4.0

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

UniqueIndex is an implementation that associates a value with a exactly one key.

func NewUniqueIndex added in v0.4.0

func NewUniqueIndex(tx engine.Transaction, idxName string) *UniqueIndex

NewUniqueIndex creates an index that associates a value with a exactly one key.

func (*UniqueIndex) AscendGreaterOrEqual added in v0.4.0

func (i *UniqueIndex) AscendGreaterOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

AscendGreaterOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in increasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the beginning.

func (*UniqueIndex) Delete added in v0.4.0

func (i *UniqueIndex) Delete(val document.Value, key []byte) error

Delete all the references to the key from the index.

func (*UniqueIndex) DescendLessOrEqual added in v0.4.0

func (i *UniqueIndex) DescendLessOrEqual(pivot *Pivot, fn func(val document.Value, key []byte) error) error

DescendLessOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in descreasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the end.

func (*UniqueIndex) Set added in v0.4.0

func (i *UniqueIndex) Set(val document.Value, key []byte) error

Set associates a value with exactly one key. If the association already exists, it returns an error.

func (*UniqueIndex) Truncate added in v0.4.0

func (i *UniqueIndex) Truncate() error

Truncate deletes all the index data.

Jump to

Keyboard shortcuts

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