github.com/tobgu/qframe@v0.4.0/internal/strings/set.go (about)

     1  package strings
     2  
     3  type StringSet map[string]struct{}
     4  
     5  func NewEmptyStringSet() StringSet {
     6  	return make(StringSet)
     7  }
     8  
     9  func NewStringSet(input []string) StringSet {
    10  	result := make(StringSet, len(input))
    11  	for _, s := range input {
    12  		result.Add(s)
    13  	}
    14  
    15  	return result
    16  }
    17  
    18  func (ss StringSet) Contains(s string) bool {
    19  	_, ok := ss[s]
    20  	return ok
    21  }
    22  
    23  func (ss StringSet) Add(s string) {
    24  	ss[s] = struct{}{}
    25  }
    26  
    27  func (ss StringSet) AsSlice() []string {
    28  	result := make([]string, 0, len(ss))
    29  	for k := range ss {
    30  		result = append(result, k)
    31  	}
    32  
    33  	return result
    34  }