2015-01-06 03:21:03 +01:00
|
|
|
package token
|
2014-12-17 19:57:05 +01:00
|
|
|
|
|
|
|
// StringSet is a useful type for looking up strings.
|
2015-01-06 03:21:03 +01:00
|
|
|
type stringSet map[string]struct{}
|
2014-12-17 19:57:05 +01:00
|
|
|
|
|
|
|
// NewStringSet creates a new StringSet with the given strings.
|
2015-01-06 03:21:03 +01:00
|
|
|
func newStringSet(keys ...string) stringSet {
|
|
|
|
ss := make(stringSet, len(keys))
|
|
|
|
ss.add(keys...)
|
2014-12-17 19:57:05 +01:00
|
|
|
return ss
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add inserts the given keys into this StringSet.
|
2015-01-06 03:21:03 +01:00
|
|
|
func (ss stringSet) add(keys ...string) {
|
2014-12-17 19:57:05 +01:00
|
|
|
for _, key := range keys {
|
|
|
|
ss[key] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contains returns whether the given key is in this StringSet.
|
2015-01-06 03:21:03 +01:00
|
|
|
func (ss stringSet) contains(key string) bool {
|
2014-12-17 19:57:05 +01:00
|
|
|
_, ok := ss[key]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keys returns a slice of all keys in this StringSet.
|
2015-01-06 03:21:03 +01:00
|
|
|
func (ss stringSet) keys() []string {
|
2014-12-17 19:57:05 +01:00
|
|
|
keys := make([]string, 0, len(ss))
|
|
|
|
|
|
|
|
for key := range ss {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys
|
|
|
|
}
|