graphs

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWeightIsNegative = errors.New("dijkstra algorithms, the weight cannot be a negative value")
)

Functions

func FloydWarshall

func FloydWarshall(g GraphFloydWarshall) [][]int

Types

type EdgeDijkstra

type EdgeDijkstra struct {
	To     int
	Weight int
}

Edge represents a structure for the edges of a graph

type GraphBFS

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

func NewGraphBFS

func NewGraphBFS() *GraphBFS

func (*GraphBFS) AddEdge

func (g *GraphBFS) AddEdge(v, w int)

adds an edge to the graph

func (*GraphBFS) BFS

func (g *GraphBFS) BFS(start int) []int

BFS performs a breadth-first search

type GraphDFS

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

represents a graph using an adjacency list

func NewGraphDFS

func NewGraphDFS() *GraphDFS

creates a new graph

func (*GraphDFS) AddEdge

func (g *GraphDFS) AddEdge(v, w int)

adds an edge to the graph

func (*GraphDFS) DFSIterative

func (g *GraphDFS) DFSIterative(start int) []int

func (*GraphDFS) DFSRecursive

func (g *GraphDFS) DFSRecursive(start int, visited map[int]bool, result *[]int)

type GraphDijkstra

type GraphDijkstra struct {
	Vertices int
	Edges    map[int][]EdgeDijkstra
}

Graph is represented as a structure containing an adjacency list

func (*GraphDijkstra) Dijkstra

func (g *GraphDijkstra) Dijkstra(start int) ([]int, error)

Dijkstra performs Dijkstra's algorithm

type GraphFloydWarshall

type GraphFloydWarshall struct {
	Graph [][]int
}

type ItemDijkstra

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

Item represents an element in a priority queue

type PriorityQueue

type PriorityQueue []*ItemDijkstra

PriorityQueue implements a priority queue data structure

func (*PriorityQueue) Len

func (pq *PriorityQueue) Len() int

Len, Less, Swap, Push и Pop реализуют интерфейс heap.Interface

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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