graph

package
v0.0.0-...-ad164ee Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain is a method chaining struct for a directed graph.

func NewDirectedGraphChain

func NewDirectedGraphChain() *Chain

func (*Chain) AddEdge

func (c *Chain) AddEdge(start, end string, cost int) *Chain

AddEdge calls addEdge on the graph

func (*Chain) AddNode

func (c *Chain) AddNode(n *Node) *Chain

AddNode calls AddNode on the graph

func (*Chain) DirectedGraph

func (c *Chain) DirectedGraph() (*DirectedGraph, error)

DirectedGraph returns the directed graph built by the chain, or the error if any occurred in building.

func (*Chain) Err

func (c *Chain) Err() error

Err returns the error from the chain, if any exist

type DijkstraSearcher

type DijkstraSearcher struct {
}

func (*DijkstraSearcher) ShortestPath

func (d *DijkstraSearcher) ShortestPath(graph *DirectedGraph, startKey, targetKey string) []*Node

ShortestPath calculates the shortest path (by cost) from start to end.

type DirectedGraph

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

DirectedGraph represents a directed graph as an adjacency list.

func NewDirectedGraph

func NewDirectedGraph() *DirectedGraph

NewDirectedGraph returns an empty directed graph.

func (*DirectedGraph) AddEdge

func (d *DirectedGraph) AddEdge(start, end string, cost int) error

AddEdge adds a new edge to the graph with a cost.

func (*DirectedGraph) AddNode

func (d *DirectedGraph) AddNode(n *Node) error

AddNode adds a new node to the graph.

func (*DirectedGraph) GetEdgeCost

func (d *DirectedGraph) GetEdgeCost(start, end string) (int, error)

GetEdgeCost returns the cost of the edge between start and end nodes

func (*DirectedGraph) GetNode

func (d *DirectedGraph) GetNode(key string) (*Node, error)

AddNode adds a new node to the graph.

func (*DirectedGraph) RemoveEdge

func (d *DirectedGraph) RemoveEdge(start, end string) error

RemoveEdge deletes a an edge from the graph.

func (*DirectedGraph) RemoveNode

func (d *DirectedGraph) RemoveNode(key string) error

RemoveNode deletes a node (by key) and any associated edges from the graph.

type Node

type Node struct {
	Key  string
	Data interface{}
}

type Searcher

type Searcher interface {
	ShortestPath(graph *DirectedGraph, startKey, targetKey string) []*Node
}

Jump to

Keyboard shortcuts

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