engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid        = errors.New("invalid argument")
	ErrScanTerminated = errors.New("scan terminated")
	ErrScratchInUse   = errors.New("scratch is already in use")
)

Functions

This section is empty.

Types

type CompileStats

type CompileStats struct {
	Patterns          int
	Accelerated       int
	AlwaysRun         int
	Bounded           int
	SensitiveTriggers int
	CaselessTriggers  int
	MaskTriggers      int
	HashTriggers      int
	HashLiterals      int
	PairTriggers      int
	RunGuards         int
	GuardClasses      int
	DFAPatterns       int
	DFAStates         int
}

CompileStats describes the routing decisions made while compiling a database.

type Database

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

Database is an immutable block-mode multi-pattern database.

func Compile

func Compile(patterns ...*Pattern) (*Database, error)

Compile builds one block database from patterns. Patterns must be trusted; compilation does not enforce resource budgets.

func UnmarshalDatabase

func UnmarshalDatabase(data []byte) (*Database, error)

UnmarshalDatabase loads compiled tables without compiling expressions. It rejects incompatible formats and corrupt data and does not retain data. Only load artifacts produced by a trusted compiler; the checksum is not a signature.

func (*Database) Marshal

func (db *Database) Marshal() ([]byte, error)

Marshal encodes the compiled database in an architecture-independent format. The output can be embedded with go:embed. Format versions are library-specific.

func (*Database) Match

func (db *Database) Match(data []byte, scratch *Scratch) (bool, error)

Match reports whether any expression matches data.

func (*Database) Scan

func (db *Database) Scan(data []byte, scratch *Scratch, handler MatchHandler) error

Scan searches data and calls handler for every reported match.

func (*Database) Size

func (db *Database) Size() int

Size returns the approximate bytes held by the database.

func (*Database) Stats

func (db *Database) Stats() CompileStats

Stats returns counts useful when tuning a pattern set.

type Flags

type Flags uint32

Flags change how an expression is compiled or reported.

const (
	Caseless Flags = 1 << iota
	DotAll
	MultiLine
	SingleMatch
	AllowEmpty
	UTF8
	Prefilter
	SomLeftMost
)

type Match

type Match struct {
	ID    uint
	From  uint64
	To    uint64
	Flags uint
}

Match is reported for one expression occurrence.

type MatchHandler

type MatchHandler func(Match) error

MatchHandler receives matches in engine order. Returning an error stops the scan and returns that error.

type Pattern

type Pattern struct {
	Expression string
	Flags      Flags
	ID         uint
}

Pattern associates an expression and compile flags with an application ID.

func NewPattern

func NewPattern(expression string, flags Flags) *Pattern

NewPattern returns a pattern with the supplied expression and flags.

func (Pattern) Valid

func (p Pattern) Valid() bool

Valid reports whether the pattern can be compiled.

type Scratch

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

Scratch contains mutable scan state. A caller needs one Scratch per concurrent scan. Scanning a larger database grows its buffers as needed.

func NewScratch

func NewScratch(db *Database) *Scratch

NewScratch allocates scan state for db.

func (*Scratch) Clone

func (s *Scratch) Clone() *Scratch

Clone returns independent scan state with the same capacity.

Jump to

Keyboard shortcuts

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