Graphs

package
v0.0.0-...-de9bdf8 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewVertex

func NewVertex(key string) *vertex

initializes a new node and sets its key

Types

type Graph

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

func NewGraph

func NewGraph() *Graph

initialize a new graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(src, dst string, weight float64) (bool, error)

Adds an edge between two vertices

func (*Graph) AddVertex

func (g *Graph) AddVertex(key string) (*vertex, error)

Adds a new vertex to the graph

func (*Graph) GetVertex

func (g *Graph) GetVertex(key string) *vertex

Returns a vertex from the graph

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(src, dst string) (bool, error)

Removes an edge between two nodes

func (*Graph) RemoveVertex

func (g *Graph) RemoveVertex(key string) (bool, error)

Removes a vertex from the graph

func (*Graph) ShortestPath

func (g *Graph) ShortestPath(src *vertex) map[string]float64

Compute the shortest path from a source to all other vertices using Dijkstra's algorithm. Returns a map of vertices and their distances from the source.

Jump to

Keyboard shortcuts

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