github.com/atrn/dcc@v0.0.0-20220806184050-4470d2553272/stringset.go (about) 1 // dcc - dependency-driven C/C++ compiler front end 2 // 3 // Copyright © A.Newman 2015. 4 // 5 // This source code is released under version 2 of the GNU Public License. 6 // See the file LICENSE for details. 7 // 8 9 package main 10 11 /* 12 * A set of strings. 13 */ 14 type StringSet map[string]struct{} 15 16 /* 17 * Return a StringSet containing the given strings. 18 */ 19 func MakeStringSet(els ...string) StringSet { 20 set := make(StringSet) 21 for _, el := range els { 22 set[el] = struct{}{} 23 } 24 return set 25 } 26 27 /* 28 * Insert an element into a StringSet 29 */ 30 func (s *StringSet) Insert(el string) { 31 (*s)[el] = struct{}{} 32 } 33 34 /* 35 * Return true if a StringSet contains n element 36 */ 37 func (s *StringSet) Contains(el string) bool { 38 _, found := (*s)[el] 39 return found 40 } 41 42 /* 43 * Return true if the receiver is empty. 44 */ 45 func (s *StringSet) IsEmpty() bool { 46 return len(*s) == 0 47 }