strings.go 538 B

12345678910111213141516171819202122232425
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package set
  5. // Strings represents a set of strings.
  6. type Strings map[string]struct{}
  7. func (ss *Strings) Len() int {
  8. return len(*ss)
  9. }
  10. func (ss *Strings) Has(s string) bool {
  11. _, ok := (*ss)[s]
  12. return ok
  13. }
  14. func (ss *Strings) Set(s string) {
  15. if *ss == nil {
  16. *ss = make(map[string]struct{})
  17. }
  18. (*ss)[s] = struct{}{}
  19. }
  20. func (ss *Strings) Clear(s string) {
  21. delete(*ss, s)
  22. }