Documentation
¶
Index ¶
- func Build(idx *Index, dlog *dlog.DLog, fromCommit int64) error
- func IndexPatch(idx *Index, e *dlog.Entry, logFile string, pos int64, txSeq int64, ...) error
- func LogSegCompare(a, b LogSegment) int
- func SortLogSegments(segments []*LogSegment)
- func StoreIndex(path string, idx *Index) error
- func StoreIndexWithMetadata(path string, idx *Index, maxCommit int64) error
- func WithinCommitRange(a, b *LogSegment) bool
- type Direction
- type Index
- func (i *Index) Add(seg *LogSegment)
- func (i *Index) GobDecode(data []byte) error
- func (i *Index) GobEncode() ([]byte, error)
- func (i *Index) IterAtPath(kpath string) *IndexIterator
- func (i *Index) ListRange(from, to *int64) []string
- func (i *Index) LookupRange(kpath string, from, to *int64) []LogSegment
- func (i *Index) LookupWithin(kpath string, commit int64) []LogSegment
- func (i *Index) Remove(seg *LogSegment) bool
- type IndexIterator
- func (it *IndexIterator) Commits(dir Direction) func(func(LogSegment) bool)
- func (it *IndexIterator) CommitsAt(commit int64, dir Direction) func(func(LogSegment) bool)
- func (it *IndexIterator) Depth() int
- func (it *IndexIterator) Down(pathKey string) bool
- func (it *IndexIterator) Path() string
- func (it *IndexIterator) ToPath(kpath string) bool
- func (it *IndexIterator) Up() bool
- func (it *IndexIterator) Valid() bool
- type IndexMetadata
- type IndexWithMetadata
- type Iterator
- type LogSegment
- func (s *LogSegment) FromTony(data []byte, opts ...gomap.UnmapOption) error
- func (s *LogSegment) FromTonyIR(node *ir.Node, opts ...gomap.UnmapOption) error
- func (s *LogSegment) String() string
- func (s *LogSegment) ToTony(opts ...gomap.MapOption) ([]byte, error)
- func (s *LogSegment) ToTonyIR(opts ...gomap.MapOption) (*ir.Node, error)
- type Tree
- func (t *Tree[T]) All(f func(T) bool) bool
- func (t *Tree[T]) Commits(dir Direction) func(func(T) bool)
- func (t *Tree[T]) Index(v T) int
- func (t *Tree[T]) Insert(v T) bool
- func (t *Tree[T]) IterAscending() *Iterator[T]
- func (t *Tree[T]) IterDescending() *Iterator[T]
- func (t *Tree[T]) IterRange(r func(T) int, ascending bool) *Iterator[T]
- func (t *Tree[T]) IterSeek(target T, ascending bool) *Iterator[T]
- func (t *Tree[T]) Range(f func(T) bool, r func(T) int) bool
- func (t *Tree[T]) Remove(v T) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IndexPatch ¶ added in v0.0.10
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 ¶
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
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
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 LoadIndexWithMetadata ¶ added in v0.0.10
LoadIndexWithMetadata loads the index along with its metadata. Returns the index and the max commit number, or an error if loading fails.
func (*Index) Add ¶
func (i *Index) Add(seg *LogSegment)
func (*Index) GobEncode ¶
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
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
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
Seek positions the iterator at the first element >= target (if ascending) or <= target (if descending). Direction remains unchanged.
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 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
type Tree ¶
func (*Tree[T]) All ¶
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
Commits returns a function that can be used with for-range to iterate elements in the specified direction.
func (*Tree[T]) IterAscending ¶ added in v0.0.10
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
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
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
IterSeek positions iterator at the first element >= target (if ascending) or <= target (if descending). Next() will advance in the specified direction.