matchergroup_full.go 800 B

123456789101112131415161718192021222324252627282930
  1. package strmatcher
  2. // FullMatcherGroup is an implementation of MatcherGroup.
  3. // It uses a hash table to facilitate exact match lookup.
  4. type FullMatcherGroup struct {
  5. matchers map[string][]uint32
  6. }
  7. // AddFullMatcher implements MatcherGroupForFull.AddFullMatcher.
  8. func (g *FullMatcherGroup) AddFullMatcher(matcher FullMatcher, value uint32) {
  9. if g.matchers == nil {
  10. g.matchers = make(map[string][]uint32)
  11. }
  12. domain := matcher.Pattern()
  13. g.matchers[domain] = append(g.matchers[domain], value)
  14. }
  15. // Match implements MatcherGroup.Match.
  16. func (g *FullMatcherGroup) Match(input string) []uint32 {
  17. if g.matchers == nil {
  18. return nil
  19. }
  20. return g.matchers[input]
  21. }
  22. // MatchAny implements MatcherGroup.Any.
  23. func (g *FullMatcherGroup) MatchAny(input string) bool {
  24. return len(g.Match(input)) > 0
  25. }