graph

package
v0.0.0-...-73e22f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2020 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package graph provides a Graph data structure (directed & weighted)

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
}

Graph : represents a Graph

Example
graph := New()
node0 := graph.AddNode()
node1 := graph.AddNode()
node2 := graph.AddNode()

graph.AddEdge(node0, node1, 1)

fmt.Println(node0)
fmt.Println(node1)
fmt.Println(node2)
fmt.Println(graph.Nodes())
graph.AddEdge(node0, node2, 5)
graph.Neighbors(node0)
Output:

0
1
2
[0 1 2]

func New

func New() *Graph

New : returns a new instance of a Graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(n1, n2 int, w int)

AddEdge : adds a directional edge together with a weight

func (*Graph) AddNode

func (g *Graph) AddNode() (id int)

AddNode : adds a new node to the Graph

func (*Graph) Edges

func (g *Graph) Edges() [][3]int

Edges : returns a list of edges with weights

func (*Graph) Neighbors

func (g *Graph) Neighbors(id int) []int

Neighbors : returns a list of node IDs that are linked to this node

func (*Graph) Nodes

func (g *Graph) Nodes() []int

Nodes : returns a list of node IDs

type GraphNode

type GraphNode struct {
	// contains filtered or unexported fields
}

GraphNode : represents a Graph node

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL