forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintset.go
46 lines (38 loc) · 864 Bytes
/
intset.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
package graphview
import (
"sort"
"k8s.io/apimachinery/pkg/util/sets"
)
type IntSet map[int]sets.Empty
// NewIntSet creates a IntSet from a list of values.
func NewIntSet(items ...int) IntSet {
ss := IntSet{}
ss.Insert(items...)
return ss
}
// Insert adds items to the set.
func (s IntSet) Insert(items ...int) {
for _, item := range items {
s[item] = sets.Empty{}
}
}
// Delete removes all items from the set.
func (s IntSet) Delete(items ...int) {
for _, item := range items {
delete(s, item)
}
}
// Has returns true iff item is contained in the set.
func (s IntSet) Has(item int) bool {
_, contained := s[item]
return contained
}
// List returns the contents as a sorted string slice.
func (s IntSet) List() []int {
res := make([]int, 0, len(s))
for key := range s {
res = append(res, key)
}
sort.IntSlice(res).Sort()
return res
}