-
Notifications
You must be signed in to change notification settings - Fork 2
/
set.go
55 lines (48 loc) · 782 Bytes
/
set.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
package main
import (
"container/vector"
)
type set vector.Vector
func (self *set) Push(i int) bool {
if self.IndexOf(i) != -1 {
return false
}
(*vector.Vector)(self).Push(i)
return true
}
func (self *set) IndexOf(t int) int {
for i, w := range *self {
word := w.(int)
if word == t {
return i
}
}
return -1
}
func (self *set) Union(s *set) bool {
changed := false
for _, w := range *s {
word := w.(int)
changed = self.Push(word) || changed
}
return changed
}
func (self *set) NoE() (output *set) {
output = new(set)
for _, w := range *self {
word := w.(int)
if word != 0 {
output.Push(word)
}
}
return
}
func (self *set) HasE() bool {
for _, w := range *self {
word := w.(int)
if word == 0 {
return true
}
}
return false
}