graph

package module
v0.0.0-...-33e0520 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2014 License: GPL-2.0 Imports: 1 Imported by: 0

README

graph.go

graph.go is an abstracted graphing library for go, currently only containing Dijkstra's Algorithm.

In the future I intend to expand it to enable more versitility, and perhapse a couple of more simple algorithms.

If you decide to improve this library feel free to send a merge request!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNode

func AddNode(g *Graph, node Node, code string)

*

  • Adds a node to a graph
  • @param graph - the graph to add node to
  • @param node - the node to add a graph to
  • @param code - the code to use as the map key

func AddOutEdge

func AddOutEdge(node *Node, edge Edge)

*

  • @param node - the node for the edge to be added to
  • @param edge - an edge to add
  • Adds a edge to a given node

Types

type D_Node

type D_Node struct {
	Node  Node
	Value int
	Back  *D_Node
}

type Edge

type Edge struct {
	Destination *Node
	Weight      float64
	Len         int
}

*

  • Structure represts edges between nodes.

type Graph

type Graph struct {
	Node map[string]Node
	Edge []Edge
}

type Node

type Node struct {
	Code     string
	Data     interface{}
	OutEdges []Edge
}

*

  • Node will take in a string representationa and save
  • the nodes input as an interface. There is then an array
  • of outbound edges, which which will be used to connect with other nodes

func Dijkstra

func Dijkstra(g *Graph, source *Node, destination *Node) ([]Node, int)

*

  • Uses Dijkstra's Algorithm to search through the graph
  • @param g - graph for to search
  • @param source - node to search from (starting node)
  • @param destination - node to search for (end node)
  • @return list of nodes in reverse order

type Queue

type Queue []*D_Node

func (Queue) Len

func (q Queue) Len() int

func (Queue) Less

func (q Queue) Less(i, j int) bool

func (*Queue) Pop

func (q *Queue) Pop() interface{}

func (*Queue) Push

func (q *Queue) Push(x interface{})

func (Queue) Swap

func (q Queue) Swap(i, j int)

Jump to

Keyboard shortcuts

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