graff

package module
v0.0.0-...-6444aa5 Latest Latest
Warning

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

Go to latest
Published: May 10, 2018 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCyclicGraph = errors.New("The graph cannot be cyclic")
)

Errors relating to the DFSSorter.

View Source
var (
	ErrDependencyOrder = errors.New("The topological dependency order is incorrect")
)

Errors relating to the CoffmanGrahamSorter.

Functions

This section is empty.

Types

type CoffmanGrahamSorter

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

CoffmanGrahamSorter sorts a graph's nodes into a sequence of levels, arranging so that a node which comes after another in the order is assigned to a lower level, and that a level never exceeds the width. See https://en.wikipedia.org/wiki/Coffman–Graham_algorithm

func NewCoffmanGrahamSorter

func NewCoffmanGrahamSorter(graph *DirectedGraph, width int) *CoffmanGrahamSorter

NewCoffmanGrahamSorter returns a new Coffman-Graham sorter.

func (*CoffmanGrahamSorter) Sort

func (s *CoffmanGrahamSorter) Sort() ([][]Node, error)

Sort returns the sorted nodes.

type DFSSorter

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

DFSSorter topologically sorts a directed graph's nodes based on the directed edges between them using the Depth-first search algorithm.

func NewDFSSorter

func NewDFSSorter(graph *DirectedGraph) *DFSSorter

NewDFSSorter returns a new DFS sorter.

func (*DFSSorter) Sort

func (s *DFSSorter) Sort() ([]Node, error)

Sort returns the sorted nodes.

type DirectedGraph

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

DirectedGraph is a graph supporting directed edges between nodes.

func NewDirectedGraph

func NewDirectedGraph() *DirectedGraph

NewDirectedGraph creates a graph of nodes with directed edges.

func (*DirectedGraph) AddEdge

func (g *DirectedGraph) AddEdge(from Node, to Node)

AddEdge adds the edge to the graph.

func (DirectedGraph) AddNode

func (g DirectedGraph) AddNode(node Node)

AddNode inserts the specified node into the graph. A node can be any value, e.g. int, string, pointer to a struct, map etc. Duplicate nodes are ignored.

func (DirectedGraph) AddNodes

func (g DirectedGraph) AddNodes(nodes ...Node)

AddNodes inserts the specified nodes into the graph. A node can be any value, e.g. int, string, pointer to a struct, map etc. Duplicate nodes are ignored.

func (*DirectedGraph) AdjacencyMatrix

func (g *DirectedGraph) AdjacencyMatrix() map[Node]map[Node]bool

AdjacencyMatrix returns a matrix indicating whether pairs of nodes are adjacent or not within the graph.

func (*DirectedGraph) CoffmanGrahamSort

func (g *DirectedGraph) CoffmanGrahamSort(width int) ([][]Node, error)

CoffmanGrahamSort sorts the graph's nodes into a sequence of levels, arranging so that a node which comes after another in the order is assigned to a lower level, and that a level never exceeds the specified width.

func (*DirectedGraph) Copy

func (g *DirectedGraph) Copy() *DirectedGraph

Copy returns a clone of the directed graph.

func (*DirectedGraph) DFSSort

func (g *DirectedGraph) DFSSort() ([]Node, error)

DFSSort returns the graph's nodes in topological order based on the directed edges between them using the Depth-first search algorithm.

func (*DirectedGraph) DOTGraph

func (g *DirectedGraph) DOTGraph() string

DOTGraph returns a textual representation of the graph in the DOT graph description language.

func (*DirectedGraph) EdgeCount

func (g *DirectedGraph) EdgeCount() int

EdgeCount returns the number of direced edges between nodes.

func (*DirectedGraph) EdgeExists

func (g *DirectedGraph) EdgeExists(from Node, to Node) bool

EdgeExists checks whether the edge exists within the graph.

func (*DirectedGraph) HasEdges

func (g *DirectedGraph) HasEdges(node Node) bool

HasEdges determines whether the graph contains any edges to or from the node.

func (*DirectedGraph) HasIncomingEdges

func (g *DirectedGraph) HasIncomingEdges(node Node) bool

HasIncomingEdges checks whether the graph contains any directed edges pointing to the node.

func (*DirectedGraph) HasOutgoingEdges

func (g *DirectedGraph) HasOutgoingEdges(node Node) bool

HasOutgoingEdges checks whether the graph contains any directed edges pointing from the node.

func (*DirectedGraph) IncomingEdgeCount

func (g *DirectedGraph) IncomingEdgeCount(node Node) int

IncomingEdgeCount returns the number of edges pointing from the specified node (indegree).

func (*DirectedGraph) IncomingEdges

func (g *DirectedGraph) IncomingEdges(node Node) []Node

IncomingEdges returns the nodes belonging to directed edges pointing towards the specified node.

func (*DirectedGraph) IsolatedNodes

func (g *DirectedGraph) IsolatedNodes() []Node

IsolatedNodes finds independent nodes in the graph, i.e. those without edges.

func (DirectedGraph) NodeCount

func (g DirectedGraph) NodeCount() int

NodeCount returns the number of nodes.

func (DirectedGraph) NodeExists

func (g DirectedGraph) NodeExists(node Node) bool

NodeExists determines whether the specified node exists within the graph.

func (DirectedGraph) Nodes

func (g DirectedGraph) Nodes() []Node

Nodes returns the graph's nodes. The slice is mutable for performance reasons but should not be mutated.

func (*DirectedGraph) OutgoingEdgeCount

func (g *DirectedGraph) OutgoingEdgeCount(node Node) int

OutgoingEdgeCount returns the number of edges pointing from the specified node (outdegree).

func (*DirectedGraph) OutgoingEdges

func (g *DirectedGraph) OutgoingEdges(node Node) []Node

OutgoingEdges returns the nodes belonging to directed edges pointing from the specified node.

func (*DirectedGraph) RemoveEdge

func (g *DirectedGraph) RemoveEdge(from Node, to Node)

RemoveEdge removes the edge from the graph.

func (DirectedGraph) RemoveNode

func (g DirectedGraph) RemoveNode(node Node)

RemoveNode removes the specified nodes from the graph. If the node does not exist within the graph the call will fail silently.

func (DirectedGraph) RemoveNodes

func (g DirectedGraph) RemoveNodes(nodes ...Node)

RemoveNodes removes the specified nodes from the graph. If a node does not exist within the graph the call will fail silently.

func (*DirectedGraph) RemoveTransitives

func (g *DirectedGraph) RemoveTransitives()

RemoveTransitives removes any transitive edges so that as fewest possible edges exist while matching the reachability of the original graph.

func (*DirectedGraph) RootNodes

func (g *DirectedGraph) RootNodes() []Node

RootNodes finds the entry-point nodes to the graph, i.e. those without incoming edges.

type Node

type Node = interface{}

Node represents a graph node.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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