ahocorasick

package
v3.68.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AhoCorasickCore

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

AhoCorasickCore encapsulates the operations and data structures used for keyword matching via the Aho-Corasick algorithm. It is responsible for constructing and managing the trie for efficient substring searches, as well as mapping keywords to their associated detectors for rapid lookups.

func NewAhoCorasickCore

func NewAhoCorasickCore(allDetectors []detectors.Detector) *AhoCorasickCore

NewAhoCorasickCore allocates and initializes a new instance of AhoCorasickCore. It uses the provided detector slice to create a map from keywords to detectors and build the Aho-Corasick prefilter trie.

func (*AhoCorasickCore) GetDetectorByKey added in v3.67.1

func (ac *AhoCorasickCore) GetDetectorByKey(key DetectorKey) detectors.Detector

GetDetectorByKey returns the detector associated with the given key. If no detector is found, it returns nil.

func (*AhoCorasickCore) PopulateMatchingDetectors

func (ac *AhoCorasickCore) PopulateMatchingDetectors(chunkData string, dts map[DetectorKey]detectors.Detector) []DetectorInfo

PopulateMatchingDetectors populates the given detector slice with all the detectors matching the provided input. This method populates an existing map rather than allocating a new one because it will be called once per chunk and that many allocations has a noticeable performance cost. It returns a slice of unique 'DetectorInfo' corresponding to the matched detectors. This slice is constructed to prevent duplications by utilizing an internal map to track already processed detectors.

type DetectorInfo added in v3.67.0

type DetectorInfo struct {
	Key DetectorKey
	detectors.Detector
}

DetectorInfo represents a detected pattern's metadata in a data chunk. It encapsulates the key identifying a specific detector and the detector instance itself.

type DetectorKey

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

DetectorKey is used to identify a detector in the keywordsToDetectors map. Multiple detectors can have the same detector type but different versions. This allows us to identify a detector by its type and version. An additional (optional) field is provided to disambiguate multiple custom detectors. This type is exported even though none of its fields are so that the AhoCorasickCore can populate passed-in maps keyed on this type without exposing any of its internals to consumers.

func CreateDetectorKey added in v3.67.0

func CreateDetectorKey(d detectors.Detector) DetectorKey

CreateDetectorKey creates a unique key for each detector from its type, version, and, for custom regex detectors, its name.

func (DetectorKey) Type added in v3.67.2

Type returns the detector type of the key.

Jump to

Keyboard shortcuts

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