truncindex

package
v1.0.0-beta.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPrefix is returned when key or prefix is empty.
	ErrEmptyPrefix = errors.New("empty prefix not allowed")

	// ErrIllegalChar is returned when key contains spaces.
	ErrIllegalChar = errors.New("illegal character: ' '")

	// ErrNotFound is returned when item is not found in trie.
	ErrNotFound = errors.New("item not found")

	// ErrAlreadyExists is returned when key is already present in index.
	ErrAlreadyExists = errors.New("already exists")
)

Functions

This section is empty.

Types

type ErrAmbiguousPrefix

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

ErrAmbiguousPrefix is returned if the prefix was ambiguous (multiple keys for the prefix).

func (ErrAmbiguousPrefix) Error

func (e ErrAmbiguousPrefix) Error() string

type TruncIndex

type TruncIndex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TruncIndex allows the retrieval of items by associated key or any of it unique prefixes.

func NewTruncIndex

func NewTruncIndex(maxKeyLen int) *TruncIndex

NewTruncIndex creates a new TruncIndex and initializes with a list of IDs. Retured index is tread-safe to use.

func (*TruncIndex) Add

func (idx *TruncIndex) Add(key string, item interface{}) error

Add adds a new key-item pair to the TruncIndex.

func (*TruncIndex) Delete

func (idx *TruncIndex) Delete(key string) error

Delete removes kay and associated item from the TruncIndex. If there are multiple IDs with the given prefix, an error is returned.

func (*TruncIndex) Get

func (idx *TruncIndex) Get(key string) (interface{}, error)

Get retrieves an item from the TruncIndex by key or its prefix. If there are multiple keys with the given prefix, an error is returned.

func (*TruncIndex) Iterate

func (idx *TruncIndex) Iterate(handler func(key string, item interface{}))

Iterate iterates over all stored items and passes each of them to the given handler. Take care that the handler method does not call any public method on truncindex as the internal locking is not reentrant/recursive and will result in deadlock.

Jump to

Keyboard shortcuts

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