graph

package module
v0.0.0-...-22d451b Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAdjacency

func FormatAdjacency(g Graph) string

FormatAdjacency formats the graph as an adjacency list on multiple lines.

func FormatGrid

func FormatGrid(g Graph) string

FormatGrid formats the graph as a grid on multiple lines.

func FormatGridLabeled

func FormatGridLabeled(g Graph, labels []string) string

FormatGridLabeled formats a graph as an ASCII grid with row and column labels.

func FormatList

func FormatList(g Graph) string

FormatList formats the graph as a list of edges on a single line.

func FormatMatrix

func FormatMatrix(g Graph) string

FormatMatrix formats a graph as a matrix on multiple lines using extending Unicode brackets.

Types

type Graph

type Graph interface {
	Add(i, j uint)
	AddUndirected(i, j uint)
	Clear(i, j uint)
	Swap(i, j uint)
	Has(i, j uint) bool
	Copy() Graph
	Reverse() Graph
	OutDegree(i uint) int
	InDegree(i uint) int
	Len() int
	String() string
}

Graph is a directed graph.

func Generate

func Generate(g Graph) []Graph

Generate generates all possible directed graphs of a maximum rank starting with a given empty graph.

func GenerateUndirected

func GenerateUndirected(g Graph) []Graph

GenerateUndirected generates all possible undirected graphs of a maximum rank starting with a given empty graph.

func NewGraph

func NewGraph(rank uint) Graph

NewGraph constructs a graph with a given number of nodes, selecting the type closest to the rank.

type Graph16

type Graph16 []uint16

Graph16 is a directed graph with at most 16 nodes.

func NewGraph16

func NewGraph16(rank uint) Graph16

NewGraph16 constructs a graph with a given number of nodes.

func (Graph16) Add

func (g Graph16) Add(i, j uint)

Add adds a directed edge from node i to j.

func (Graph16) AddUndirected

func (g Graph16) AddUndirected(i, j uint)

AddUndirected adds an undirected edge between nodes i and j.

func (Graph16) Clear

func (g Graph16) Clear(i, j uint)

Clear removes the directed edge from node i to j.

func (Graph16) Copy

func (g Graph16) Copy() Graph

Copy creates a copy of the graph.

func (Graph16) Has

func (g Graph16) Has(i, j uint) bool

Has returns whether an edge connects node i to j.

func (Graph16) InDegree

func (g Graph16) InDegree(i uint) int

InDegree returns the number of edges directed to the given node.

func (Graph16) Len

func (g Graph16) Len() int

Len returns the number of nodes in the graph.

func (Graph16) OutDegree

func (g Graph16) OutDegree(i uint) int

OutDegree returns the number of edges directed from the given node.

func (Graph16) Reverse

func (g Graph16) Reverse() Graph

Reverse creates a graph with reversed edges.

func (Graph16) String

func (g Graph16) String() string

String formats the graph as a list of edges on a single line.

func (Graph16) Swap

func (g Graph16) Swap(i, j uint)

Swap isomorphically swaps nodes i and j.

type Graph8

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

Graph8 is a directed graph with 8 nodes with operations in constant time.

func NewGraph8

func NewGraph8(rank uint) *Graph8

NewGraph8 constructs a graph with a given number of nodes.

func (*Graph8) Add

func (g *Graph8) Add(i, j uint)

Add adds a directed edge from node i to j.

func (*Graph8) AddUndirected

func (g *Graph8) AddUndirected(i, j uint)

AddUndirected adds an undirected edge between nodes i and j.

func (*Graph8) Clear

func (g *Graph8) Clear(i, j uint)

Clear removes the directed edge from node i to j.

func (*Graph8) Copy

func (g *Graph8) Copy() Graph

Copy creates a copy of the graph.

func (*Graph8) Has

func (g *Graph8) Has(i, j uint) bool

Has returns whether an edge connects node i to j.

func (*Graph8) InDegree

func (g *Graph8) InDegree(i uint) int

InDegree returns the number of edges directed to the given node.

func (*Graph8) Len

func (g *Graph8) Len() int

Len returns the number of nodes in the graph.

func (*Graph8) OutDegree

func (g *Graph8) OutDegree(i uint) int

OutDegree returns the number of edges directed from the given node.

func (*Graph8) Reverse

func (g *Graph8) Reverse() Graph

Reverse creates a graph with reversed edges.

func (*Graph8) String

func (g *Graph8) String() string

String formats the graph as a list of edges on a single line.

func (*Graph8) Swap

func (g *Graph8) Swap(i, j uint)

Swap isomorphically swaps nodes i and j.

type GraphN

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

GraphN is a directed graph with an arbitrary number of nodes.

func NewGraphN

func NewGraphN(rank uint) *GraphN

NewGraphN constructs a graph with the given number of nodes.

func (*GraphN) Add

func (g *GraphN) Add(i, j uint)

Add adds a directed edge from node i to j.

func (*GraphN) AddUndirected

func (g *GraphN) AddUndirected(i, j uint)

AddUndirected adds an undirected edge between nodes i and j.

func (*GraphN) Clear

func (g *GraphN) Clear(i, j uint)

Clear removes the directed edge from node i to j.

func (*GraphN) Copy

func (g *GraphN) Copy() Graph

Copy creates a copy of the graph.

func (*GraphN) Has

func (g *GraphN) Has(i, j uint) bool

Has returns whether an edge connects node i to j.

func (*GraphN) InDegree

func (g *GraphN) InDegree(i uint) int

InDegree is unimplemented.

func (*GraphN) Len

func (g *GraphN) Len() int

Len returns the number of nodes in the graph.

func (*GraphN) OutDegree

func (g *GraphN) OutDegree(i uint) int

OutDegree is unimplemented.

func (GraphN) Reverse

func (g GraphN) Reverse() Graph

Reverse creates a graph with reversed edges.

func (*GraphN) String

func (g *GraphN) String() string

func (*GraphN) Swap

func (g *GraphN) Swap(i, j uint)

Swap is unimplemented.

Jump to

Keyboard shortcuts

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