index

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogSegCompare

func LogSegCompare(a, b LogSegment) int

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.

Types

type Index

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

func Build

func Build(root string, extract func(path string) (*LogSegment, error)) (*Index, error)

Build reconstructs the index from the filesystem rooted at root. extract is a closure that takes a filesystem path and returns a LogSegment if the file represents one. If extract returns nil, the file is ignored.

func LoadIndex

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

LoadIndex loads the index from the given path.

func NewIndex

func NewIndex(name 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) List

func (i *Index) List() []string

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

func (*Index) LookupRange

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

func (*Index) Remove

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

type LogSegment

type LogSegment struct {
	StartCommit int64
	StartTx     int64
	EndCommit   int64
	EndTx       int64
	RelPath     string
}

func PointLogSegment

func PointLogSegment(c, tx int64, p string) *LogSegment

func (*LogSegment) IsPoint

func (s *LogSegment) IsPoint() bool

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]) Index

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

func (*Tree[T]) Insert

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

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