Documentation ¶
Index ¶
Constants ¶
const ( TrieEdge bool = true FailEdge bool = false )
const PrimeRK = 16777619
PrimeRK is the prime base used in Rabin-Karp algorithm.
Variables ¶
This section is empty.
Functions ¶
func RollingHash ¶
calculate the rolling murmurHash of given string
Types ¶
type ACAutomaton ¶
type ACAutomaton struct {
// contains filtered or unexported fields
}
func NewACAutomaton ¶
func NewACAutomaton() *ACAutomaton
func (*ACAutomaton) Add ¶
func (ac *ACAutomaton) Add(domain string, t Type)
func (*ACAutomaton) Build ¶
func (ac *ACAutomaton) Build()
func (*ACAutomaton) Match ¶
func (ac *ACAutomaton) Match(s string) bool
type IndexMatcher ¶
type IndexMatcher interface { // Match returns the index of a matcher that matches the input. It returns empty array if no such matcher exists. Match(input string) []uint32 }
IndexMatcher is the interface for matching with a group of matchers.
type Matcher ¶
type Matcher interface { // Match returns true if the given string matches a predefined pattern. Match(string) bool String() string }
Matcher is the interface to determine a string matches a pattern.
type MphMatcherGroup ¶
type MphMatcherGroup struct {
// contains filtered or unexported fields
}
A MphMatcherGroup is divided into three parts: 1. `full` and `domain` patterns are matched by Rabin-Karp algorithm and minimal perfect hash table; 2. `substr` patterns are matched by ac automaton; 3. `regex` patterns are matched with the regex library.
func NewMphMatcherGroup ¶
func NewMphMatcherGroup() *MphMatcherGroup
func (*MphMatcherGroup) AddFullOrDomainPattern ¶
func (g *MphMatcherGroup) AddFullOrDomainPattern(pattern string, t Type)
func (*MphMatcherGroup) AddPattern ¶
func (g *MphMatcherGroup) AddPattern(pattern string, t Type) (uint32, error)
AddPattern adds a pattern to MphMatcherGroup
func (*MphMatcherGroup) Build ¶
func (g *MphMatcherGroup) Build()
Build builds a minimal perfect hash table and ac automaton from insert rules
func (*MphMatcherGroup) Lookup ¶
func (g *MphMatcherGroup) Lookup(h uint32, s string) bool
Lookup searches for s in t and returns its index and whether it was found.
func (*MphMatcherGroup) Match ¶
func (g *MphMatcherGroup) Match(pattern string) []uint32
Match implements IndexMatcher.Match.
type Type ¶
type Type byte
Type is the type of the matcher.
const ( // Full is the type of matcher that the input string must exactly equal to the pattern. Full Type = iota // Substr is the type of matcher that the input string must contain the pattern as a sub-string. Substr // Domain is the type of matcher that the input string must be a sub-domain or itself of the pattern. Domain // Regex is the type of matcher that the input string must matches the regular-expression pattern. Regex )