graph

package
v0.0.0-...-a13166e Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

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

Edge represents a weighted connection from one vertex to another.

func (Edge) From

func (e Edge) From() string

From returns the origin vertex ID of the edge.

func (Edge) To

func (e Edge) To() string

To returns the destination vertex ID of the edge.

func (Edge) Weight

func (e Edge) Weight() float64

Weight returns weight value of the edge.

type FilterFunc

type FilterFunc func(v Vertex) bool

FilterFunc type

type Interface

type Interface interface {
	SetDirected(isDirected bool) Interface
	SetDefaultWeight(weight float64) Interface
	Clear() Interface

	Add(id string, value interface{}) bool
	AddMany(vertices ...struct {
		id    string
		value interface{}
	})
	Has(id string) bool
	Get(id string) *Vertex
	Remove(id string) bool
	ResetVertex(id string) bool

	GetEdge(from, to string) *Edge
	AddEdge(from, to string, weight ...float64) bool
	RemoveEdge(from, to string) bool
	GetEdgeWeight(from, to string) float64
	SetEdgeWeight(from, to string, weight float64) bool

	ShortestPath(from, to string, f ...FilterFunc) []*Vertex
	GoDFS(from string, f func(v Vertex) interface{})
	GoBFS(from string, f func(v Vertex) interface{})
}

Interface of a graph

func New

func New() Interface

New returns a graph

type Vertex

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

A Vertex represents a node in a graph. It consists of a unique id with associated data, and a collection of edges connecting it to other vertices.

func (Vertex) Edges

func (v Vertex) Edges() []Edge

Edges returns a slice of edges connected to the vertex.

func (Vertex) ID

func (v Vertex) ID() string

ID returns the unique ID of the vertex.

func (Vertex) Len

func (v Vertex) Len() int

Len returns the number of edges connected to the Vertex.

func (Vertex) Value

func (v Vertex) Value() interface{}

Value returns the value of the vertex.

Jump to

Keyboard shortcuts

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