aho

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package aho implements a compact Aho-Corasick automaton over integer tokens.

Index

Constants

View Source
const None = ^uint32(0)

None is the sentinel used for absent nodes and outputs.

Variables

This section is empty.

Functions

func BuildFailureLinks(
	edgeStarts []uint32,
	edgeTokens []uint32,
	terminalHeads []uint32,
) ([]uint32, []uint32, error)

BuildFailureLinks derives failure and output links from a breadth-first trie.

Types

type Automaton

type Automaton struct {
	EdgeStarts    []uint32
	EdgeTokens    []uint32
	Failures      []uint32
	OutputLinks   []uint32
	TerminalHeads []uint32
	OutputNext    []uint32
}

Automaton stores a token trie, failure links, and pattern outputs.

func Build

func Build(patterns []Pattern, valueCount int) (Automaton, error)

Build constructs an automaton. Empty patterns are ignored.

func (*Automaton) AppendOutputs

func (a *Automaton) AppendOutputs(values []uint32, state uint32) []uint32

AppendOutputs appends all pattern values ending at state to values.

func (*Automaton) EdgeCount

func (a *Automaton) EdgeCount() int

EdgeCount returns the number of trie edges.

func (*Automaton) Next

func (a *Automaton) Next(state, token uint32) uint32

Next advances state with token, following failure links as needed.

func (*Automaton) NodeCount

func (a *Automaton) NodeCount() int

NodeCount returns the number of trie nodes, including the root.

func (*Automaton) Validate

func (a *Automaton) Validate(valueCount int) error

Validate checks array lengths, references, and edge ordering.

type Pattern

type Pattern struct {
	Tokens []uint32
	Value  uint32
}

Pattern associates a token sequence with a caller-defined value.

Jump to

Keyboard shortcuts

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