Documentation
¶
Index ¶
- Constants
- func RollingHash(s string) uint32
- type ACAutomaton
- type DomainMatcherGroup
- type Edge
- type FullMatcherGroup
- type IndexMatcher
- type IndexMatcherGroup
- type MatchType
- type Matcher
- type MatcherEntry
- type MatcherGroup
- type MphMatcherGroup
- func (g *MphMatcherGroup) AddFullOrDomainPattern(pattern string, t Type)
- func (g *MphMatcherGroup) AddPattern(pattern string, t Type) (uint32, error)
- func (g *MphMatcherGroup) Build()
- func (g *MphMatcherGroup) Lookup(h uint32, s string) bool
- func (g *MphMatcherGroup) Match(pattern string) []uint32
- func (g *MphMatcherGroup) Serialize(w io.Writer) error
- func (g *MphMatcherGroup) Size() uint32
- type RegexMatcher
- type Type
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 ¶ added in v1.4.3
calculate the rolling murmurHash of given string
Types ¶
type ACAutomaton ¶ added in v1.4.3
func NewACAutomaton ¶ added in v1.4.3
func NewACAutomaton() *ACAutomaton
func (*ACAutomaton) Add ¶ added in v1.4.3
func (ac *ACAutomaton) Add(domain string, t Type)
func (*ACAutomaton) Build ¶ added in v1.4.3
func (ac *ACAutomaton) Build()
func (*ACAutomaton) Match ¶ added in v1.4.3
func (ac *ACAutomaton) Match(s string) bool
type DomainMatcherGroup ¶
type DomainMatcherGroup struct {
// contains filtered or unexported fields
}
DomainMatcherGroup is a IndexMatcher for a large set of Domain matchers. Visible for testing only.
func (*DomainMatcherGroup) Add ¶
func (g *DomainMatcherGroup) Add(domain string, value uint32)
func (*DomainMatcherGroup) Match ¶
func (g *DomainMatcherGroup) Match(domain string) []uint32
type FullMatcherGroup ¶
type FullMatcherGroup struct {
// contains filtered or unexported fields
}
func (*FullMatcherGroup) Add ¶
func (g *FullMatcherGroup) Add(domain string, value uint32)
func (*FullMatcherGroup) Match ¶
func (g *FullMatcherGroup) Match(str string) []uint32
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
// Size returns the number of matchers in the group.
Size() uint32
}
IndexMatcher is the interface for matching with a group of matchers.
type IndexMatcherGroup ¶ added in v1.260131.0
type IndexMatcherGroup struct {
Matchers []IndexMatcher
}
func (*IndexMatcherGroup) Match ¶ added in v1.260131.0
func (g *IndexMatcherGroup) Match(input string) []uint32
func (*IndexMatcherGroup) Size ¶ added in v1.260131.0
func (g *IndexMatcherGroup) Size() uint32
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 MatcherEntry ¶ added in v1.260131.0
type MatcherGroup ¶
type MatcherGroup struct {
// contains filtered or unexported fields
}
MatcherGroup is an implementation of IndexMatcher. Empty initialization works.
func (*MatcherGroup) Add ¶
func (g *MatcherGroup) Add(m Matcher) uint32
Add adds a new Matcher into the MatcherGroup, and returns its index. The index will never be 0.
func (*MatcherGroup) Match ¶
func (g *MatcherGroup) Match(pattern string) []uint32
Match implements IndexMatcher.Match.
func (*MatcherGroup) Size ¶
func (g *MatcherGroup) Size() uint32
Size returns the number of matchers in the MatcherGroup.
type MphMatcherGroup ¶ added in v1.4.3
type MphMatcherGroup struct {
Ac *ACAutomaton
OtherMatchers []MatcherEntry
Rules []string
Level0 []uint32
Level0Mask int
Level1 []uint32
Level1Mask int
Count uint32
RuleMap *map[string]uint32
}
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 ¶ added in v1.4.3
func NewMphMatcherGroup() *MphMatcherGroup
func NewMphMatcherGroupFromBuffer ¶ added in v1.260131.0
func NewMphMatcherGroupFromBuffer(data []byte) (*MphMatcherGroup, error)
func (*MphMatcherGroup) AddFullOrDomainPattern ¶ added in v1.4.3
func (g *MphMatcherGroup) AddFullOrDomainPattern(pattern string, t Type)
func (*MphMatcherGroup) AddPattern ¶ added in v1.4.3
func (g *MphMatcherGroup) AddPattern(pattern string, t Type) (uint32, error)
AddPattern adds a pattern to MphMatcherGroup
func (*MphMatcherGroup) Build ¶ added in v1.4.3
func (g *MphMatcherGroup) Build()
Build builds a minimal perfect hash table and ac automaton from insert rules
func (*MphMatcherGroup) Lookup ¶ added in v1.4.3
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 ¶ added in v1.4.3
func (g *MphMatcherGroup) Match(pattern string) []uint32
Match implements IndexMatcher.Match.
func (*MphMatcherGroup) Serialize ¶ added in v1.260131.0
func (g *MphMatcherGroup) Serialize(w io.Writer) error
func (*MphMatcherGroup) Size ¶ added in v1.260131.0
func (g *MphMatcherGroup) Size() uint32
type RegexMatcher ¶ added in v1.260131.0
type RegexMatcher struct {
Pattern string
// contains filtered or unexported fields
}
func (*RegexMatcher) Match ¶ added in v1.260131.0
func (m *RegexMatcher) Match(s string) bool
func (*RegexMatcher) String ¶ added in v1.260131.0
func (m *RegexMatcher) String() string
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 )