index

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(idx *Index, dlog *dlog.DLog, fromCommit int64) error

func IndexPatch added in v0.0.10

func IndexPatch(idx *Index, e *dlog.Entry, logFile string, pos int64, txSeq int64, diff *ir.Node) error

func LogSegCompare

func LogSegCompare(a, b LogSegment) int

LogSegCompare compares 2 log segments by their start commit, start-tx, end-commit, end-tx, and path.

func SortLogSegments

func SortLogSegments(segments []*LogSegment)

SortLogSegments sorts a slice of LogSegment pointers by commit count, then tx.

func StoreIndex

func StoreIndex(path string, idx *Index) error

StoreIndex persists the index to the given path. It writes to a temporary file first and then atomically renames it to the target path.

func StoreIndexWithMetadata added in v0.0.10

func StoreIndexWithMetadata(path string, idx *Index, maxCommit int64) error

StoreIndexWithMetadata persists the index along with metadata (max commit number). This allows incremental rebuilds on startup by scanning logs from MaxCommit + 1 forward.

func WithinCommitRange added in v0.0.9

func WithinCommitRange(a, b *LogSegment) bool

Types

type Direction added in v0.0.10

type Direction int

Direction specifies the iteration direction for commits

const (
	// Up iterates commits in ascending order (smallest to largest)
	Up Direction = iota
	// Down iterates commits in descending order (largest to smallest)
	Down
)

type Index

type Index struct {
	sync.RWMutex
	PathKey  string // eg "" for root
	Commits  *Tree[LogSegment]
	Children map[string]*Index // map from subdir names to sub indices
}

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex loads the index from the given path.

func LoadIndexWithMetadata added in v0.0.10

func LoadIndexWithMetadata(path string) (*Index, int64, error)

LoadIndexWithMetadata loads the index along with its metadata. Returns the index and the max commit number, or an error if loading fails.

func NewIndex

func NewIndex(pathKey string) *Index

func (*Index) Add

func (i *Index) Add(seg *LogSegment)

func (*Index) GobDecode

func (i *Index) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface.

func (*Index) GobEncode

func (i *Index) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface. It flattens the Index into a list of LogSegments for serialization.

func (*Index) IterAtPath added in v0.0.10

func (i *Index) IterAtPath(kpath string) *IndexIterator

IterAtPath creates an iterator positioned at the specified path Path is relative to root (e.g., "foo.bar" or "" for root) If path doesn't exist, iterator is invalid Caller must hold RLock on root index

func (*Index) ListRange added in v0.0.9

func (i *Index) ListRange(from, to *int64) []string

ListRange returns the immediate child names at this index level. Returns the keys of the Children map.

func (*Index) LookupRange

func (i *Index) LookupRange(kpath string, from, to *int64) []LogSegment

func (*Index) LookupWithin added in v0.0.10

func (i *Index) LookupWithin(kpath string, commit int64) []LogSegment

LookupWithin finds all segments at the given kpath where the commit is within the segment's commit range (StartCommit <= commit <= EndCommit). Returns ancestors and exact matches, just like LookupRange.

func (*Index) Remove

func (i *Index) Remove(seg *LogSegment) bool

type IndexIterator added in v0.0.10

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

IndexIterator provides hierarchical navigation and iteration over an Index

func (*IndexIterator) Commits added in v0.0.10

func (it *IndexIterator) Commits(dir Direction) func(func(LogSegment) bool)

Commits returns a function that can be used with for-range to iterate commits at the current level in the specified direction. Caller must hold RLock on current index.

func (*IndexIterator) CommitsAt added in v0.0.10

func (it *IndexIterator) CommitsAt(commit int64, dir Direction) func(func(LogSegment) bool)

CommitsAt returns a function that can be used with for-range to iterate commits at the current level starting from the specified commit in the specified direction. For dir=Down, seeks to the first segment <= commit and iterates downward (larger to smaller commits). For dir=Up, seeks to the first segment >= commit and iterates upward (smaller to larger commits). Caller must hold RLock on current index.

func (*IndexIterator) Depth added in v0.0.10

func (it *IndexIterator) Depth() int

Depth returns the depth in the hierarchy (0 for root)

func (*IndexIterator) Down added in v0.0.10

func (it *IndexIterator) Down(pathKey string) bool

Down navigates into a child index by path key (kpath segment) Returns true if child exists and navigation succeeded Caller must hold RLock on current index

func (*IndexIterator) Path added in v0.0.10

func (it *IndexIterator) Path() string

Path returns the current path in the hierarchy (e.g., "foo.bar" or "" for root) Uses kpath-aware joining to properly reconstruct the path. ir.Join() joins a single segment (prefix) with a path (suffix), so we build from right to left.

func (*IndexIterator) ToPath added in v0.0.10

func (it *IndexIterator) ToPath(kpath string) bool

ToPath navigates to the specified path from root Returns true if path exists Caller must hold RLock on root index

func (*IndexIterator) Up added in v0.0.10

func (it *IndexIterator) Up() bool

Up navigates to the parent index Returns true if parent exists (false if already at root)

func (*IndexIterator) Valid added in v0.0.10

func (it *IndexIterator) Valid() bool

Valid returns whether the iterator is positioned at a valid index

type IndexMetadata added in v0.0.10

type IndexMetadata struct {
	MaxCommit int64 // Highest commit number in the index
}

IndexMetadata contains metadata about the persisted index.

type IndexWithMetadata added in v0.0.10

type IndexWithMetadata struct {
	Index    *Index
	Metadata IndexMetadata
}

IndexWithMetadata wraps an index with its metadata for persistence.

type Iterator added in v0.0.10

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator provides caller-driven iteration over a Tree[T] Direction is fixed at creation (ascending or descending)

func (*Iterator[T]) Next added in v0.0.10

func (it *Iterator[T]) Next() bool

Next advances the iterator to the next element in the iterator's direction For ascending iterators, moves to next larger element For descending iterators, moves to next smaller element Returns true if a valid element was found, false if iteration is complete

func (*Iterator[T]) Seek added in v0.0.10

func (it *Iterator[T]) Seek(target T) bool

Seek positions the iterator at the first element >= target (if ascending) or <= target (if descending). Direction remains unchanged.

func (*Iterator[T]) Valid added in v0.0.10

func (it *Iterator[T]) Valid() bool

Valid returns whether the iterator is positioned at a valid element

func (*Iterator[T]) Value added in v0.0.10

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

Value returns the current element Panics if iterator is not valid

type LogSegment

type LogSegment struct {
	StartCommit   int64
	StartTx       int64
	EndCommit     int64
	EndTx         int64
	KindedPath    string   // Full kinded path from root (e.g., "a.b.c", "resources("joe")", "" for root)
	ArrayKey      *ir.Node // Key value for !key arrays (e.g., ir.FromString("joe")) - nil if not keyed
	ArrayKeyField string   // Kpath to key field for !key arrays (e.g., "name", "address.city") - empty if not keyed
	LogFile       string   // "A" or "B" - which log file contains this segment
	LogPosition   int64    // Byte offset in log file

}

func NewLogSegmentFromPatchEntry added in v0.0.10

func NewLogSegmentFromPatchEntry(e *dlog.Entry, kpath string, logFile string, pos int64, txID int64) *LogSegment

func PointLogSegment

func PointLogSegment(commit, txSeq int64, kpath string) *LogSegment

PointLogSegment creates a LogSegment for a patch at the given commit. Assumes LastCommit = commit-1, so StartCommit = LastCommit = commit-1, EndCommit = commit. For test purposes, this represents a patch where Commit - LastCommit == 1.

func (*LogSegment) FromTony added in v0.0.9

func (s *LogSegment) FromTony(data []byte, opts ...gomap.UnmapOption) error

FromTony parses Tony format bytes and populates LogSegment.

func (*LogSegment) FromTonyIR added in v0.0.9

func (s *LogSegment) FromTonyIR(node *ir.Node, opts ...gomap.UnmapOption) error

FromTonyIR populates LogSegment from a Tony IR node.

func (*LogSegment) String added in v0.0.9

func (s *LogSegment) String() string

func (*LogSegment) ToTony added in v0.0.9

func (s *LogSegment) ToTony(opts ...gomap.MapOption) ([]byte, error)

ToTony converts LogSegment to Tony format bytes.

func (*LogSegment) ToTonyIR added in v0.0.9

func (s *LogSegment) ToTonyIR(opts ...gomap.MapOption) (*ir.Node, error)

ToTonyIR converts LogSegment to a Tony IR node.

type Tree

type Tree[T any] struct {
	Less func(a, b T) bool
	// contains filtered or unexported fields
}

func NewTree

func NewTree[T any](less func(a, b T) bool) *Tree[T]

func (*Tree[T]) All

func (t *Tree[T]) All(f func(T) bool) bool

All applies f to all elements in T in ascending order until f returns false. All returns whether or not f returns false

func (*Tree[T]) Commits added in v0.0.10

func (t *Tree[T]) Commits(dir Direction) func(func(T) bool)

Commits returns a function that can be used with for-range to iterate elements in the specified direction.

func (*Tree[T]) Index

func (t *Tree[T]) Index(v T) int

func (*Tree[T]) Insert

func (t *Tree[T]) Insert(v T) bool

func (*Tree[T]) IterAscending added in v0.0.10

func (t *Tree[T]) IterAscending() *Iterator[T]

IterAscending returns an iterator positioned at the first element (minimum) Next() will advance through elements in ascending order

func (*Tree[T]) IterDescending added in v0.0.10

func (t *Tree[T]) IterDescending() *Iterator[T]

IterDescending returns an iterator positioned at the last element (maximum) Next() will advance through elements in descending order

func (*Tree[T]) IterRange added in v0.0.10

func (t *Tree[T]) IterRange(r func(T) int, ascending bool) *Iterator[T]

IterRange positions iterator at the first element matching the range predicate Next() will advance in the specified direction.

func (*Tree[T]) IterSeek added in v0.0.10

func (t *Tree[T]) IterSeek(target T, ascending bool) *Iterator[T]

IterSeek positions iterator at the first element >= target (if ascending) or <= target (if descending). Next() will advance in the specified direction.

func (*Tree[T]) Range

func (t *Tree[T]) Range(f func(T) bool, r func(T) int) bool

Range applies f to all elements e such that r(e) == 0. r should return a negative integer for elements less than those such that r(e) == 0 and likewise a positive integer for those elements greater than those such that r(e) == 0

func (*Tree[T]) Remove

func (t *Tree[T]) Remove(v T) bool

Jump to

Keyboard shortcuts

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