tree

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

Functions

This section is empty.

Types

type CursorItem

type CursorItem struct {
	PageID uint64
	Node   node.Node
	Index  int
}

type Iterator

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

func (*Iterator) Close

func (it *Iterator) Close() error

func (*Iterator) Domain

func (it *Iterator) Domain() (start, end []byte)

func (*Iterator) Error

func (it *Iterator) Error() error

func (*Iterator) IsDeleted

func (it *Iterator) IsDeleted() bool

func (*Iterator) Key

func (it *Iterator) Key() []byte

func (*Iterator) KeyCopy

func (it *Iterator) KeyCopy(dst []byte) []byte

func (*Iterator) Next

func (it *Iterator) Next()

func (*Iterator) Seek

func (it *Iterator) Seek(key []byte)

func (*Iterator) UnsafeEntry

func (it *Iterator) UnsafeEntry() ([]byte, page.ValuePtr, byte)

func (*Iterator) UnsafeKey

func (it *Iterator) UnsafeKey() []byte

func (*Iterator) UnsafeValue

func (it *Iterator) UnsafeValue() []byte

func (*Iterator) Valid

func (it *Iterator) Valid() bool

func (*Iterator) Value

func (it *Iterator) Value() []byte

func (*Iterator) ValueCopy

func (it *Iterator) ValueCopy(dst []byte) []byte

type IteratorMode added in v0.4.0

type IteratorMode uint8

IteratorMode controls value materialization behavior while scanning.

const (
	// IteratorModeFull resolves inline and pointer-backed values on demand.
	IteratorModeFull IteratorMode = iota
	// IteratorModeKeysOnly skips value materialization entirely.
	IteratorModeKeysOnly
	// IteratorModePointerProjection keeps pointer metadata visible via UnsafeEntry
	// but skips pointer payload decoding.
	IteratorModePointerProjection
)

type IteratorOptions added in v0.4.0

type IteratorOptions struct {
	Mode IteratorMode
	// IncludeTombstones keeps tombstone rows visible to iteration callers.
	// Default false preserves user-facing behavior (tombstones hidden).
	IncludeTombstones bool
}

IteratorOptions configures scan-time value materialization behavior.

type ReadPathStats added in v0.4.0

type ReadPathStats struct {
	GetAppendInlineHitsTotal   uint64
	GetAppendInlineBytesTotal  uint64
	GetAppendPointerHitsTotal  uint64
	GetAppendPointerBytesTotal uint64
}

func ReadPathStatsSnapshot added in v0.4.0

func ReadPathStatsSnapshot() ReadPathStats

type SlabReader

type SlabReader interface {
	Read(ptr page.ValuePtr) ([]byte, error)
	ReadUnsafe(ptr page.ValuePtr) ([]byte, error)
}

type Tree

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

func New

func New(p *pager.Pager, sr SlabReader, root uint64) *Tree

func (*Tree) CollectPageIDs

func (t *Tree) CollectPageIDs() ([]uint64, error)

CollectPageIDs returns the sorted set of pager-backed page IDs reachable from the Tree root. Leaf pages stored in the value log (LeafRef IDs) are excluded.

func (*Tree) Get

func (t *Tree) Get(key []byte) ([]byte, error)

Get returns the value for key.

When the stored value is non-empty, Get returns an owned, mutable copy of that value.

If the key is missing or tombstoned, Get returns ErrKeyNotFound. For compatibility with the long-standing TreeDB API, when the stored value is zero-length but the key is present, Get returns (nil, nil).

func (*Tree) GetAppend added in v0.4.0

func (t *Tree) GetAppend(key, dst []byte) ([]byte, error)

GetAppend appends the value for key to dst and returns the grown slice. If key is missing/tombstoned, it returns dst and ErrKeyNotFound.

func (*Tree) GetEntry

func (t *Tree) GetEntry(key []byte) (node.LeafEntry, error)

GetEntry returns the persisted leaf entry for key.

CAUTION: Returned entry Key/Value might point directly to mmap memory. Do not modify or hold reference for long.

func (*Tree) GetEntryExact added in v0.4.0

func (t *Tree) GetEntryExact(key []byte) (node.LeafEntry, error)

GetEntryExact is an alias for GetEntry.

func (*Tree) GetUnsafe

func (t *Tree) GetUnsafe(key []byte) ([]byte, error)

func (*Tree) Has

func (t *Tree) Has(key []byte) (bool, error)

func (*Tree) Iterator

func (t *Tree) Iterator(start, end []byte) iterator.UnsafeIterator

func (*Tree) IteratorWithOptions added in v0.4.0

func (t *Tree) IteratorWithOptions(start, end []byte, opts IteratorOptions) iterator.UnsafeIterator

IteratorWithOptions returns a forward iterator over [start, end) using the provided value materialization mode.

func (*Tree) Reset

func (t *Tree) Reset(p *pager.Pager, sr SlabReader, root uint64)

Reset re-initializes the tree with new parameters for reuse.

func (*Tree) ReverseIterator

func (t *Tree) ReverseIterator(start, end []byte) iterator.UnsafeIterator

func (*Tree) ReverseIteratorWithOptions added in v0.4.0

func (t *Tree) ReverseIteratorWithOptions(start, end []byte, opts IteratorOptions) iterator.UnsafeIterator

ReverseIteratorWithOptions returns a reverse iterator over [start, end) using the provided value materialization mode.

func (*Tree) SetRoot

func (t *Tree) SetRoot(root uint64)

SetRoot updates the root page ID.

func (*Tree) UpdateValuePtrInPlace

func (t *Tree) UpdateValuePtrInPlace(key []byte, oldPtr, newPtr page.ValuePtr) (updated bool, leafPageID uint64, err error)

UpdateValuePtrInPlace rewrites a pointer value in-place inside the current tree by updating the leaf page that contains key.

This is intended for maintenance operations (e.g. value-log compaction) that want to avoid full copy-on-write path rewrites. Callers must ensure snapshot safety (i.e. no readers are pinned to the current index generation) before using it.

Returns (updated=true, leafPageID) when the entry existed as a pointer and matched oldPtr. If the key is missing or has changed since oldPtr, it returns updated=false with a nil error.

func (*Tree) WalkPages

func (t *Tree) WalkPages(fn func(pageID uint64, n node.Node) error) error

WalkPages visits each pager-backed page reachable from the Tree's current root exactly once. Leaf pages stored in the value log (LeafRef IDs) are skipped. It is primarily intended for diagnostics, vacuuming, and tests.

Jump to

Keyboard shortcuts

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