forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 2
/
edge.go
61 lines (47 loc) · 1004 Bytes
/
edge.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
60
61
package edge
import . "github.com/onsi/gomega/matchers/support/goraph/node"
type Edge struct {
Node1 Node
Node2 Node
}
type EdgeSet []Edge
func (ec EdgeSet) Free(node Node) bool {
for _, e := range ec {
if e.Node1 == node || e.Node2 == node {
return false
}
}
return true
}
func (ec EdgeSet) Contains(edge Edge) bool {
for _, e := range ec {
if e == edge {
return true
}
}
return false
}
func (ec EdgeSet) FindByNodes(node1, node2 Node) (Edge, bool) {
for _, e := range ec {
if (e.Node1 == node1 && e.Node2 == node2) || (e.Node1 == node2 && e.Node2 == node1) {
return e, true
}
}
return Edge{}, false
}
func (ec EdgeSet) SymmetricDifference(ec2 EdgeSet) EdgeSet {
edgesToInclude := make(map[Edge]bool)
for _, e := range ec {
edgesToInclude[e] = true
}
for _, e := range ec2 {
edgesToInclude[e] = !edgesToInclude[e]
}
result := EdgeSet{}
for e, include := range edgesToInclude {
if include {
result = append(result, e)
}
}
return result
}