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