index

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File() string

File returns the name of the index file to use. It is either $CSEARCHINDEX or $HOME/.csearchindex.

func Merge

func Merge(dst, src1, src2 string)

Merge creates a new index in the file dst that corresponds to merging the two indices src1 and src2. If both src1 and src2 claim responsibility for a path, src2 is assumed to be newer and is given preference.

Types

type Buffer

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

A Buffer is a convenience wrapper: a closeable bufio.Writer.

func (*Buffer) Align

func (b *Buffer) Align(n int)

func (*Buffer) Flush

func (b *Buffer) Flush()

func (*Buffer) Offset

func (b *Buffer) Offset() int

Offset returns the current write offset.

func (*Buffer) Write

func (b *Buffer) Write(x []byte)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(x byte) error

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string)

func (*Buffer) WriteTrigram

func (b *Buffer) WriteTrigram(t uint32)

func (*Buffer) WriteUint

func (b *Buffer) WriteUint(x int)

func (*Buffer) WriteVarint

func (b *Buffer) WriteVarint(x int)

type Index

type Index struct {
	Verbose bool
	// contains filtered or unexported fields
}

An Index implements read-only access to a trigram index.

func Open

func Open(file string) *Index

func (*Index) Check

func (ix *Index) Check() error

func (*Index) Name

func (ix *Index) Name(fileid int) Path

Name returns the name corresponding to the given fileid.

func (*Index) Names

func (ix *Index) Names(lo, hi int) iter.Seq[Path]

func (*Index) NamesAt

func (ix *Index) NamesAt(min, max int) *PathReader

NameAt returns a PathReader returning the names for fileids in the range [min, max).

func (*Index) PostingAnd

func (ix *Index) PostingAnd(list []int, trigram uint32) []int

func (*Index) PostingList

func (ix *Index) PostingList(trigram uint32) []int

func (*Index) PostingOr

func (ix *Index) PostingOr(list []int, trigram uint32) []int

func (*Index) PostingQuery

func (ix *Index) PostingQuery(q *Query) []int

func (*Index) PrintStats

func (ix *Index) PrintStats()

func (*Index) Roots

func (ix *Index) Roots() *PathReader

Roots returns the list of indexed roots.

type IndexWriter

type IndexWriter struct {
	LogSkip bool // log information about skipped files
	Verbose bool // log status using package log
	Zip     bool // index content of zip files
	// contains filtered or unexported fields
}

An IndexWriter creates an on-disk index corresponding to a set of files.

func Create

func Create(file string) *IndexWriter

Create returns a new IndexWriter that will write the index to file.

func (*IndexWriter) Add

func (ix *IndexWriter) Add(name string, f io.Reader) error

Add adds the file f to the index under the given name. It logs errors using package log.

func (*IndexWriter) AddFile

func (ix *IndexWriter) AddFile(name string) error

AddFile adds the file with the given name (opened using os.Open) to the index. It logs errors using package log.

func (*IndexWriter) AddRoots

func (ix *IndexWriter) AddRoots(roots []Path)

AddRoots adds the given roots to the index's list of roots.

func (*IndexWriter) Flush

func (ix *IndexWriter) Flush()

Flush flushes the index entry to the target file.

type Path

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

A Path is a Path stored in the index, either in the root list or the file list.

Paths stored in the index are ordered using the [Path.cmp] method.

func MakePath

func MakePath(s string) Path

func (Path) Compare

func (p Path) Compare(q Path) int

Compare returns the comparison of p and q. It is analogous to strings.Compare(p, q) but x/y is ordered before x.foo by treating slashes as if they had byte value 0. On Windows, backslashes are treated as equal to slashes.

func (Path) HasPathPrefix

func (p Path) HasPathPrefix(parent Path) bool

func (Path) String

func (p Path) String() string

type PathReader

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

func NewPathReader

func NewPathReader(version int, data []byte, limit int) *PathReader

func (*PathReader) All

func (r *PathReader) All() iter.Seq[Path]

func (*PathReader) Next

func (r *PathReader) Next() bool

func (*PathReader) NumPaths

func (r *PathReader) NumPaths() int

func (*PathReader) Path

func (r *PathReader) Path() Path

func (*PathReader) Valid

func (r *PathReader) Valid() bool

type PathWriter

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

func NewPathWriter

func NewPathWriter(data, index *Buffer, version, group int) *PathWriter

func (*PathWriter) Collect

func (w *PathWriter) Collect(paths iter.Seq[Path])

Collect iterates over paths and writes all the paths to w.

func (*PathWriter) Count

func (w *PathWriter) Count() int

Count returns the number of paths written to w.

func (*PathWriter) Write

func (w *PathWriter) Write(p Path)

type Query

type Query struct {
	Op      QueryOp
	Trigram []string
	Sub     []*Query
}

A Query is a matching machine, like a regular expression, that matches some text and not other text. When we compute a Query from a regexp, the Query is a conservative version of the regexp: it matches everything the regexp would match, and probably quite a bit more. We can then filter target files by whether they match the Query (using a trigram index) before running the comparatively more expensive regexp machinery.

func RegexpQuery

func RegexpQuery(re *syntax.Regexp) *Query

RegexpQuery returns a Query for the given regexp.

func (*Query) String

func (q *Query) String() string

type QueryOp

type QueryOp int
const (
	QAll  QueryOp = iota // Everything matches
	QNone                // Nothing matches
	QAnd                 // All in Sub and Trigram must match
	QOr                  // At least one in Sub or Trigram must match
)

Jump to

Keyboard shortcuts

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