forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digraph.go
34 lines (27 loc) · 830 Bytes
/
digraph.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
package digraph
// Digraph is used to represent a Directed Graph. This means
// we have a set of nodes, and a set of edges which are directed
// from a source and towards a destination
type Digraph interface {
// Nodes provides all the nodes in the graph
Nodes() []Node
// Sources provides all the source nodes in the graph
Sources() []Node
// Sinks provides all the sink nodes in the graph
Sinks() []Node
// Transpose reverses the edge directions and returns
// a new Digraph
Transpose() Digraph
}
// Node represents a vertex in a Digraph
type Node interface {
// Edges returns the out edges for a given nod
Edges() []Edge
}
// Edge represents a directed edge in a Digraph
type Edge interface {
// Head returns the start point of the Edge
Head() Node
// Tail returns the end point of the Edge
Tail() Node
}