Documentation ¶
Overview ¶
Package graph implements a simple graph data structure and supporting API to allow implementing graph alogirthms on top.
Example (Usage) ¶
Creates a simple graph, and prints the degree of each vertex.
package main import ( "fmt" "gopkg.in/karalabe/cookiejar.v2/graph" ) func main() { // Create a star shaped 5 vertex graph g := graph.New(5) g.Connect(0, 2) g.Connect(0, 3) g.Connect(1, 3) g.Connect(1, 4) g.Connect(2, 4) // For each vertex, count the outgoing edges for v := 0; v < g.Vertices(); v++ { degree := 0 g.Do(v, func(peer interface{}) { degree++ }) fmt.Printf("%v: %v\n", v, degree) } }
Output: 0: 2 1: 2 2: 2 3: 2 4: 2
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Data structure for representing a graph.
func (*Graph) Disconnect ¶
Disconnects two vertices of a graph (may be a loopback).
Directories ¶
Path | Synopsis |
---|---|
Package bfs implements the breadth-first-search algorithm for the graphs.
|
Package bfs implements the breadth-first-search algorithm for the graphs. |
Package dfs implements the depth-first-search algorithm for the graphs.
|
Package dfs implements the depth-first-search algorithm for the graphs. |
Click to show internal directories.
Click to hide internal directories.