graph

package
v0.0.0-...-09d313d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxVertices is the maximum size of the adjacent matrix
	MaxVertices = 1000
)

Variables

View Source
var (
	// ErrLowBound when the vertex's index is smaller than 0
	ErrLowBound = errors.New("vertex out of range: lower bound violation")
	// ErrUpBound when the vertex's index is bigger than the maximum
	ErrUpBound = errors.New("vertex out of range: upper bound violation")
)

Functions

func BoundCheck

func BoundCheck(g Interface, v int) error

BoundCheck checks whether the vertex index exceeds the allowed bound by the graph. This is an helper function the client graph package can use to check bound

Also see MustBoundCheck

func Loads

func Loads(graphCFn createGraphFunc)

Loads loads the graph constructor for this package

func MustBoundCheck

func MustBoundCheck(g Interface, v int)

MustBoundCheck is BoundCheck, but panics when error is not nil

Types

type Interface

type Interface interface {
	// returns the total number of vertices in the graph
	Nvertices() int
	// Weight returns the weight of the edge between 2 vertices. If
	// no edge exists, weight returns false as the second argument
	Weight(x, y int) (int, bool)
	// InDegree returns the in-degree of a vertex
	InDegree(v int) int
	// OutDegree returns the out-degree of a vertex
	OutDegree(v int) int
	// InsertEdge adds an edge to the graph.
	// If the inserted edge is directed, only one edge is inserted.
	// Otherwise, two edges (x,y) and (y,x) are inserted.
	// If the inserted edge is out of bound the total number of vertices is
	// scaled up and limited to graph.MaxVertices.
	InsertEdge(x, y, weight int, directed bool)
	// DeleteEdge removes an edge. If the inserted edge is directed, only one edge
	// is deleted. Otherwise, two edges are deleted.
	DeleteEdge(x, y int, directed bool)
}

Interface represents a directed graph

func New

func New(nvertices int) (Interface, error)

New creates a new graph

Directories

Path Synopsis
mst
path
traversal
bfs
dfs

Jump to

Keyboard shortcuts

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