cursor

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxKeyLength   = node.MaxKeyLength
	MaxValueLength = math.MaxUint32
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

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

A Cursor enables storage, retrieval, destruction of, and bidirectional iteration over key-value mappings in a keyspace via its methods. Out of the box, it is not safe for concurrent use; an application intending to do so should implement its own means of ensuring mutual exclusion.

func NewCursor

func NewCursor(medium Medium, offset int) *Cursor

NewCursor is a low-level constructor used by *github.com/voidDB/voidDB.Txn.OpenCursor and *github.com/voidDB/voidDB.Void.BeginTxn.

func (*Cursor) Del

func (cursor *Cursor) Del() (e error)

Del deletes the key-value record indexed by the cursor. To delete a record by key, position the cursor with *Cursor.Get beforehand.

func (*Cursor) Get

func (cursor *Cursor) Get(key []byte) (value []byte, e error)

Get retrieves the value corresponding to key and positions the cursor at the record found.

CAUTION: The value returned is immutable and valid only during the lifetime of the transaction to which the cursor belongs, since the slice merely reflects the relevant section of the memory map containing the value. Hence, any attempt at mutating the slice at any time or accessing it after the transaction has been committed/aborted will result in a fatal syscall.SIGSEGV. (See also runtime/debug.SetPanicOnFault.) Instead, applications should allocate a slice of size equal to len(value) and copy value into the new slice for modification/retention. This also applies to *Cursor.GetFirst, *Cursor.GetLast, *Cursor.GetNext, and *Cursor.GetPrev.

func (*Cursor) GetFirst

func (cursor *Cursor) GetFirst() (key, value []byte, e error)

GetFirst retrieves and positions the cursor at the first key-value record, sorted by key using bytes.Compare.

CAUTION: See *Cursor.Get.

func (*Cursor) GetLast

func (cursor *Cursor) GetLast() (key, value []byte, e error)

GetLast retrieves and positions the cursor at the last key-value record, sorted by key using bytes.Compare.

CAUTION: See *Cursor.Get.

func (*Cursor) GetNext

func (cursor *Cursor) GetNext() (key, value []byte, e error)

GetNext advances the cursor and retrieves the next key-value record, sorted by key using bytes.Compare. On a newly opened cursor, it has the same effect as *Cursor.GetFirst.

CAUTION: See *Cursor.Get.

func (*Cursor) GetPrev

func (cursor *Cursor) GetPrev() (key, value []byte, e error)

GetPrev regresses the cursor and retrieves the previous key-value record, sorted by key using bytes.Compare.

CAUTION: See *Cursor.Get.

func (*Cursor) Put

func (cursor *Cursor) Put(key, value []byte) (e error)

Put stores a key-value pair (or overwrites the corresponding value, if key already exists) and positions the cursor at the inserted record. It returns syscall.EINVAL (“invalid argument”) if the length of key or value is zero, or otherwise exceeds MaxKeyLength or MaxValueLength respectively.

CAUTION: The data in value must not be modified until the transaction has been successfully committed.

func (*Cursor) ToLinkCursor added in v0.1.9

func (cursor *Cursor) ToLinkCursor() *linkCursor

type Medium

type Medium interface {
	Meta() []byte
	Save([]byte) int
	Load(int, int) []byte
	Free(int, int)
	Root(int)
}

Jump to

Keyboard shortcuts

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