graph

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2017 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph struct {
	NodeMap map[string]*Node
}

Our Graph type consists of only a map of Nodes, indexed by strings. The graph's edge data is stored in the Nodes themselves, which makes cycle detection a bit easier.

func New

func New(nodes []Keyer) *Graph

Create a new graph consisting of a set of nodes with no edges.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from Keyer, to Keyer) error

Add an edge from <from> to <to>

func (*Graph) AddNode

func (g *Graph) AddNode(node Keyer)

func (*Graph) TopSort

func (g *Graph) TopSort() ([]string, error)

TopSort creates a topological sort of the Nodes of a Graph. If there is a cycle, an error is returned, otherwise the topological sort is returned as a list of node names.

type Keyer

type Keyer interface {
	Key() string
}

type Node

type Node struct {
	Name     string
	Value    Keyer
	EdgesOut map[string]*Node
	EdgesIn  map[string]*Node
}

A Node of a directed graph, with incoming and outgoing edges.

type StringNode

type StringNode string

func (StringNode) Key

func (s StringNode) Key() string

Jump to

Keyboard shortcuts

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