github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/strmatcher/matchergroup_full.go (about)

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