scanner

package
v0.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferPool

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

BufferPool is a wrapper for sync.Pool that returns variable size buffers. It uses a set of sync.Pools under the hood to bucket the buffers (defined by the startSize and sizeCount). Buffer requests beyond the underlying sync pool will be one-off allocations. Ideally a consumer picks a set of pools/sizes that minimizes the amount of one-off allocations.

func NewBufferPool

func NewBufferPool(startSize, sizeCnt int) *BufferPool

NewBufferPool creates a new BufferPool. startSize indicates the initial bucket's size, which gets doubled for the subsequent buckets, up to the number defined in sizeCnt.

func (*BufferPool) Get

func (bp *BufferPool) Get(size int) []byte

Get returns a buffer of a specific size.

func (*BufferPool) Put

func (bp *BufferPool) Put(buf []byte)

Put discards a specific size bufer back into the pools.

type IndexScanner

type IndexScanner interface {
	ScanIndexFile(file string) error
	ScanIndexFolder(folder string, parallel bool) error
	ScanIndexReader(reader ScipReader) error
	ScanDocumentReader(relativeDocPath string, reader ScipReader) error
}

IndexScanner defines the ways an index can be read.

type IndexScannerImpl

type IndexScannerImpl struct {
	MatchDocumentPath func(string) bool
	MatchSymbol       func([]byte) bool
	MatchOccurrence   func([]byte) bool
	// TODO(IDE-1335): Implement MatchExternalSymbol
	// MatchExternalSymbol func([]byte) bool
	VisitDocument       func(*scip.Document)
	VisitSymbol         func(string, *scip.SymbolInformation)
	VisitOccurrence     func(string, *scip.Occurrence)
	VisitExternalSymbol func(*scip.SymbolInformation)
	Pool                *BufferPool
	MaxConcurrency      int
}

IndexScannerImpl implements the IndexScanner interface. A consumer can instantiate this implementation and implement any subset of the Match* methods, and (optionally) the matching Visit* method. After instantiating the struct, the consumer SHALL call .InitBuffers() Performance Considerations:

  1. When multiple IndexScannerImpl's are expected to be instantiated at the same time, a shared BufferPool can be provided to the struct's Pool property. This improves performance and memory consumption.
  2. The Match* methods use []byte's for performance reasons.
  3. The Visit* method will only be called if: the Visit* method is defined AND the Match* function returns true
  4. Should the consumer only require the monikers (symbol IDs), using the Visit* method and returning false is the recommended method.
  5. Consider the size of the indices, there's an order of magnitude more occurrences than symbols, and more symbols than documents. So if a consumer Matches & Visits every occurrence, or document the performance gains over a traditional proto parser will be limited.

func (*IndexScannerImpl) InitBuffers

func (is *IndexScannerImpl) InitBuffers()

InitBuffers initializes the relevant buffers, and pools

func (*IndexScannerImpl) ScanDocumentReader

func (is *IndexScannerImpl) ScanDocumentReader(docPath string, r ScipReader) error

ScanDocumentReader scans through an individual document. This requires the path of the document only to pass into VisitSymbol/Occurrence methods.

func (*IndexScannerImpl) ScanIndexFile

func (is *IndexScannerImpl) ScanIndexFile(path string) error

ScanIndexFile scans an individual index file.

func (*IndexScannerImpl) ScanIndexFolder

func (is *IndexScannerImpl) ScanIndexFolder(path string, parallel bool) error

ScanIndexFolder scans an entire folder's indices. Good to use when the consumer needs to scan through a bunch of indices for specific symbols.

func (*IndexScannerImpl) ScanIndexReader

func (is *IndexScannerImpl) ScanIndexReader(r ScipReader) error

ScanIndexReader incrementally processes an index by reading input from the io.Reader It skips over any other fields defined in the SCIP index.

type ScipReader

type ScipReader interface {
	io.Reader
	io.Seeker
}

ScipReader defines the minimum interface required for a reader to be passed into the IndexScanner

type SyncPool

type SyncPool interface {
	Get() any
	Put(any)
}

SyncPool is an interface compatible with sync.Pool.

Jump to

Keyboard shortcuts

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