-
Notifications
You must be signed in to change notification settings - Fork 2
/
interface.go
64 lines (55 loc) · 1.44 KB
/
interface.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
package graph
// This file contains interface definitions for Graph and Edge types.
type Edge interface {
// Src returns the source index of the edge
Src() uint32
// Dst returns the destination index of the edge
Dst() uint32
}
// EdgeList is a slice of edges
type EdgeList []Edge
// Len returns the length of an edgelist.
func (e EdgeList) Len() int {
return len(e)
}
func (e EdgeList) Swap(i, j int) {
e[i], e[j] = e[j], e[i]
}
func (e EdgeList) Less(i, j int) bool {
if e[i].Src() < e[j].Src() {
return true
}
if e[i].Src() > e[j].Src() {
return false
}
return e[i].Dst() < e[j].Dst()
}
type EdgeIter interface {
Next() Edge
Done() bool
}
type VertexIter interface {
Next() uint32
Done() bool
}
type Graph interface {
// OutDegree returns the outdegree of vertex u.
OutDegree(u uint32) uint32
// InDegree returns the indegree of vertex u.
InDegree(u uint32) uint32
// OutNeighbors returns the out neighbors of vertex u.
OutNeighbors(u uint32) []uint32
// InNeighbors returns the in neighbors of vertex u.
InNeighbors(u uint32) []uint32
// HasEdge returns true if an edge exists between u and v.
HasEdge(u, v uint32) bool
// IsDirected is true if the graph is directed
IsDirected() bool
// NumEdges returns the number of edges in a graph.
NumEdges() uint64
// NumVertices returns the number of vertices in a graph.
NumVertices() uint32
// Edges returns an iterator to graph edges.
Edges() EdgeIter
Vertices() VertexIter
}