-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdepset.go
59 lines (49 loc) · 937 Bytes
/
depset.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
48
49
50
51
52
53
54
55
56
57
58
59
package main
type DepSet map[Hash]struct{}
func (s DepSet) Has(hash Hash) bool {
_, ok := s[hash]
return ok
}
func (s DepSet) Len() int {
return len(s)
}
func (s DepSet) Elms() []Hash {
elms := make([]Hash, 0, len(s))
for el, _ := range s {
elms = append(elms, el)
}
return elms
}
func (s DepSet) Add(toAdd ...Hash) int {
origLen := len(s)
for _, hash := range toAdd {
s[hash] = struct{}{}
}
return len(s) - origLen
}
func (s DepSet) Del(toDel ...Hash) int {
origLen := len(s)
for _, hash := range toDel {
delete(s, hash)
}
return origLen - len(s)
}
func (s DepSet) Clone() DepSet {
new := DepSet{}
for el, _ := range s {
new.Add(el)
}
return new
}
type NameSet map[string]struct{}
func (s NameSet) Has(hash string) bool {
_, ok := s[hash]
return ok
}
func (s NameSet) Add(toAdd ...string) int {
origLen := len(s)
for _, hash := range toAdd {
s[hash] = struct{}{}
}
return len(s) - origLen
}