-
Notifications
You must be signed in to change notification settings - Fork 1
/
result.go
80 lines (64 loc) · 1.18 KB
/
result.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package groph
type Results struct {
results map[interface{}]Data
position int
}
func NewResults() *Results {
return &Results{
results: make(map[interface{}]Data),
}
}
func (r *Results) AddIfNotExists(i Data) {
if i != nil {
if r.results[i.GetID()] == nil {
r.results[i.GetID()] = i
}
}
}
func (r *Results) GetEdge(i interface{}) *Edge {
if r.results[i] != nil {
return r.results[i].(*Edge)
}
return nil
}
func (r *Results) GetVertex(i interface{}) *Vertex {
if r.results[i] != nil {
return r.results[i].(*Vertex)
}
return nil
}
func (r *Results) Get(i interface{}) Data {
return r.results[i]
}
func (r *Results) Vertices() (res Vertices) {
if len(r.results) > 0 {
for _, v := range r.results {
if _, ok := v.(*Vertex); !ok {
return
}
break
}
res = make([]*Vertex, 0)
for _, v := range r.results {
vertex := v.(*Vertex)
res = append(res, vertex)
}
}
return
}
func (r *Results) Edges() (res Edges) {
if len(r.results) > 0 {
for _, e := range r.results {
if _, ok := e.(*Edge); !ok {
return
}
break
}
res = make([]*Edge, 0)
for _, e := range r.results {
edge := e.(*Edge)
res = append(res, edge)
}
}
return
}