kv

package
v0.0.0-...-189a543 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

KV provides a set of key value operations that implement data structures such as a b-tree to efficiently access the page cache. KV implements an abstraction called a cursor to efficiently seek and scan the btree. Each B tree is referenced with a page number assigned by the catalog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(v []byte) ([]any, error)

func DecodeKey

func DecodeKey(v []byte) (any, error)

func Encode

func Encode(v []interface{}) ([]byte, error)

func EncodeKey

func EncodeKey(v any) ([]byte, error)

Types

type Cursor

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

Cursor is an abstraction that can seek and scan ranges of a btree.

func (*Cursor) Count

func (c *Cursor) Count() int

Count returns the count of the current b trees leaf node entries.

Count does this not by scanning each individual tuple, but scanning each page and summing the computed counter on the page.

func (*Cursor) DeleteCurrent

func (c *Cursor) DeleteCurrent()

DeleteCurrent deletes the current tuple the cursor is pointing to. This leaves the cursor pointing at the next tuple in which case calling GotoNext will be a no-op. If the next tuple is the end of the table GotoNext will also be aware of this. This is all to facilitate execution plans which delete in a loop.

func (*Cursor) Exists

func (c *Cursor) Exists(key []byte) bool

Exists will probe the specified key and return true or false if the key exists or not.

func (*Cursor) Get

func (c *Cursor) Get(key []byte) ([]byte, bool)

Get returns a byte array corresponding to the key and a bool indicating if the key was found. The pageNumber has to do with the root page of the corresponding table. The system catalog uses the page number 1.

func (*Cursor) GetKey

func (c *Cursor) GetKey() []byte

GetKey returns the key of the current tuple.

func (*Cursor) GetValue

func (c *Cursor) GetValue() []byte

GetValue returns the value of the current pointed to tuple

func (*Cursor) GotoFirstRecord

func (c *Cursor) GotoFirstRecord() bool

GotoFirstRecord moves the cursor to the first tuple in ascending order. It returns true if the table has values. It returns false if the table is empty.

func (*Cursor) GotoKey

func (c *Cursor) GotoKey(key []byte) bool

func (*Cursor) GotoLastRecord

func (c *Cursor) GotoLastRecord() bool

GotoLastRecord moves the cursor to the last tuple in the last page (descending ordering). It returns true if the table has values otherwise false.

func (*Cursor) GotoNext

func (c *Cursor) GotoNext() bool

GotoNext moves the cursor to the next tuple in ascending order. If there is no next tuple this function will return false otherwise it will return true.

GotoNext may have special behavior if a DeleteCurrent has been previously invoked. GotoNext will essentially be a noop that makes the illusion it did the job that was already done by DeleteCurrent.

func (*Cursor) NewRowID

func (c *Cursor) NewRowID() int

NewRowID returns the highest unused key in a table for the rootPageNumber. For a integer key it is the largest integer key plus one.

func (*Cursor) Set

func (c *Cursor) Set(key, value []byte)

Set inserts or updates the value for the given key. The pageNumber has to do with the root page of the corresponding table. The system catalog uses the page number 1.

type KV

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

KV is an abstraction on the pager module that provides efficient reads and writes through b tree indexes.

func New

func New(useMemory bool, filename string) (*KV, error)

New creates an instance of kv

func (*KV) BeginReadTransaction

func (kv *KV) BeginReadTransaction() error

BeginReadTransaction begins a read transaction.

func (*KV) BeginWriteTransaction

func (kv *KV) BeginWriteTransaction() error

BeginWriteTransaction begins a write transaction.

func (*KV) EndReadTransaction

func (kv *KV) EndReadTransaction()

EndReadTransaction ends a read transaction.

func (*KV) EndWriteTransaction

func (kv *KV) EndWriteTransaction() error

EndWriteTransaction ends a write transaction.

func (*KV) GetCatalog

func (kv *KV) GetCatalog() *catalog.Catalog

GetCatalog returns and instance of the system catalog.

func (*KV) NewBTree

func (kv *KV) NewBTree() int

NewBTree creates an empty BTree and returns the new tree's root page number.

func (*KV) NewCursor

func (kv *KV) NewCursor(rootPageNumber int) *Cursor

NewCursor creates a cursor with the given object's rootPageNumber.

func (*KV) ParseSchema

func (kv *KV) ParseSchema() error

ParseSchema updates the system catalog by reading the schema table.

func (*KV) RollbackWrite

func (kv *KV) RollbackWrite()

RollbackWrite rolls back and ends a write transaction.

Jump to

Keyboard shortcuts

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