@@ -11,35 +11,54 @@ package gogl
11
11
// the varying constraints and implementation needs, but still achieve optimal
12
12
// performance given those constraints.
13
13
14
- // The Edge interface describes a connection between two vertices.
15
- //
16
- // Edge does not have an intrinsic opinion about directionality; gogl treats
17
- // that as a property of the overall Graph object in which the Edge appears
18
- // rather than a property of any individual Edge.
14
+ // Edge describes an undirected connection between two vertices.
19
15
type Edge interface {
16
+ Both () (u Vertex , v Vertex ) // No order consistency is implied.
17
+ }
18
+
19
+ // Arc describes a directed connection between two vertices.
20
+ type Arc interface {
21
+ Both () (u Vertex , v Vertex ) // u is tail/source, v is head/target.
20
22
Source () Vertex
21
23
Target () Vertex
22
- Both () (Vertex , Vertex )
23
24
}
24
25
25
- // A WeightedEdge is an Edge that also has a numerical weight.
26
+ // WeightedEdge describes an Edge that carries a numerical weight.
26
27
type WeightedEdge interface {
27
28
Edge
28
29
Weight () float64
29
30
}
30
31
31
- // A LabeledEdge is an Edge that also has a string label.
32
+ // WeightedArc describes an Arc that carries a numerical weight.
33
+ type WeightedArc interface {
34
+ Arc
35
+ Weight () float64
36
+ }
37
+
38
+ // LabeledEdge describes an Edge that also has a string label.
32
39
type LabeledEdge interface {
33
40
Edge
34
41
Label () string
35
42
}
36
43
37
- // A DataEdge is an Edge that also holds arbitrary data.
44
+ // LabeledArc describes an Arc that also has a string label.
45
+ type LabeledArc interface {
46
+ Arc
47
+ Label () string
48
+ }
49
+
50
+ // DataEdge describes an Edge that also holds arbitrary data.
38
51
type DataEdge interface {
39
52
Edge
40
53
Data () interface {}
41
54
}
42
55
56
+ // DataArc describes an Arc that also holds arbitrary data.
57
+ type DataArc interface {
58
+ Arc
59
+ Data () interface {}
60
+ }
61
+
43
62
/* Base implementations of Edge interfaces */
44
63
45
64
// BaseEdge is a struct used to represent edges and meet the Edge interface
@@ -50,14 +69,6 @@ type baseEdge struct {
50
69
v Vertex
51
70
}
52
71
53
- func (e baseEdge ) Source () Vertex {
54
- return e .u
55
- }
56
-
57
- func (e baseEdge ) Target () Vertex {
58
- return e .v
59
- }
60
-
61
72
func (e baseEdge ) Both () (Vertex , Vertex ) {
62
73
return e .u , e .v
63
74
}
@@ -67,6 +78,23 @@ func NewEdge(u, v Vertex) Edge {
67
78
return baseEdge {u : u , v : v }
68
79
}
69
80
81
+ type baseArc struct {
82
+ baseEdge
83
+ }
84
+
85
+ func (e baseArc ) Source () Vertex {
86
+ return e .u
87
+ }
88
+
89
+ func (e baseArc ) Target () Vertex {
90
+ return e .v
91
+ }
92
+
93
+ // Create a new basic arc.
94
+ func NewArc (u , v Vertex ) Arc {
95
+ return baseArc {baseEdge {u : u , v : v }}
96
+ }
97
+
70
98
// BaseWeightedEdge extends BaseEdge with weight data.
71
99
type baseWeightedEdge struct {
72
100
baseEdge
@@ -82,6 +110,20 @@ func NewWeightedEdge(u, v Vertex, weight float64) WeightedEdge {
82
110
return baseWeightedEdge {baseEdge {u : u , v : v }, weight }
83
111
}
84
112
113
+ type baseWeightedArc struct {
114
+ baseArc
115
+ w float64
116
+ }
117
+
118
+ func (e baseWeightedArc ) Weight () float64 {
119
+ return e .w
120
+ }
121
+
122
+ // Create a new weighted arc.
123
+ func NewWeightedArc (u , v Vertex , weight float64 ) WeightedArc {
124
+ return baseWeightedArc {baseArc {baseEdge {u : u , v : v }}, weight }
125
+ }
126
+
85
127
// BaseLabeledEdge extends BaseEdge with label data.
86
128
type baseLabeledEdge struct {
87
129
baseEdge
@@ -97,6 +139,21 @@ func NewLabeledEdge(u, v Vertex, label string) LabeledEdge {
97
139
return baseLabeledEdge {baseEdge {u : u , v : v }, label }
98
140
}
99
141
142
+ // BaseLabeledArc extends BaseArc with label data.
143
+ type baseLabeledArc struct {
144
+ baseArc
145
+ l string
146
+ }
147
+
148
+ func (e baseLabeledArc ) Label () string {
149
+ return e .l
150
+ }
151
+
152
+ // Create a new labeled arc.
153
+ func NewLabeledArc (u , v Vertex , label string ) LabeledArc {
154
+ return baseLabeledArc {baseArc {baseEdge {u : u , v : v }}, label }
155
+ }
156
+
100
157
// BaseDataEdge extends BaseEdge with arbitrary data.
101
158
type baseDataEdge struct {
102
159
baseEdge
@@ -111,3 +168,18 @@ func (e baseDataEdge) Data() interface{} {
111
168
func NewDataEdge (u , v Vertex , data interface {}) DataEdge {
112
169
return baseDataEdge {baseEdge {u : u , v : v }, data }
113
170
}
171
+
172
+ // BaseDataArc extends BaseArc with arbitrary data.
173
+ type baseDataArc struct {
174
+ baseArc
175
+ d interface {}
176
+ }
177
+
178
+ func (e baseDataArc ) Data () interface {} {
179
+ return e .d
180
+ }
181
+
182
+ // Create a new "data" edge - an edge with arbitrary embedded data.
183
+ func NewDataArc (u , v Vertex , data interface {}) DataArc {
184
+ return baseDataArc {baseArc {baseEdge {u : u , v : v }}, data }
185
+ }
0 commit comments