set.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package dbus
  15. type set struct {
  16. data map[string]bool
  17. }
  18. func (s *set) Add(value string) {
  19. s.data[value] = true
  20. }
  21. func (s *set) Remove(value string) {
  22. delete(s.data, value)
  23. }
  24. func (s *set) Contains(value string) (exists bool) {
  25. _, exists = s.data[value]
  26. return
  27. }
  28. func (s *set) Length() int {
  29. return len(s.data)
  30. }
  31. func (s *set) Values() (values []string) {
  32. for val, _ := range s.data {
  33. values = append(values, val)
  34. }
  35. return
  36. }
  37. func newSet() *set {
  38. return &set{make(map[string]bool)}
  39. }