graphs

package
v0.0.0-...-e1e1ce8 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicGraph

type BasicGraph struct {
	Vertices map[string][]string
}

func NewBasicGraph

func NewBasicGraph() *BasicGraph

func (*BasicGraph) AddEdge

func (g *BasicGraph) AddEdge(vertex1, vertex2 string)

func (*BasicGraph) GetNeighbors

func (g *BasicGraph) GetNeighbors(vertex string) []string

func (*BasicGraph) HasEdge

func (g *BasicGraph) HasEdge(vertex1, vertex2 string) bool

func (*BasicGraph) RemoveEdge

func (g *BasicGraph) RemoveEdge(vertex1, vertex2 string)

type DirectedGraph

type DirectedGraph struct {
	Vertices map[string][]string
}

func NewDirectedGraph

func NewDirectedGraph() *DirectedGraph

func (*DirectedGraph) AddEdge

func (g *DirectedGraph) AddEdge(vertex1, vertex2 string)

func (*DirectedGraph) GetNeighbors

func (g *DirectedGraph) GetNeighbors(vertex string) []string

func (*DirectedGraph) HasEdge

func (g *DirectedGraph) HasEdge(vertex1, vertex2 string) bool

func (*DirectedGraph) RemoveEdge

func (g *DirectedGraph) RemoveEdge(vertex1, vertex2 string)

type Graph

type Graph interface {
	AddEdge(vertex1, vertex2 string, weight ...int)
	RemoveEdge(vertex1, vertex2 string)
	GetNeighbors(vertex string) []string
	HasEdge(vertex1, vertex2 string) bool
	GetEdgeWeight(vertex1, vertex2 string) (int, bool)
}

type MultiGraph

type MultiGraph struct {
	Vertices map[string]map[string]int
}

func NewMultiGraph

func NewMultiGraph() *MultiGraph

func (*MultiGraph) AddEdge

func (g *MultiGraph) AddEdge(vertex1, vertex2 string)

func (*MultiGraph) GetNeighbors

func (g *MultiGraph) GetNeighbors(vertex string) []string

func (*MultiGraph) HasEdge

func (g *MultiGraph) HasEdge(vertex1, vertex2 string) bool

func (*MultiGraph) RemoveEdge

func (g *MultiGraph) RemoveEdge(vertex1, vertex2 string)

func (*MultiGraph) String

func (g *MultiGraph) String() string

type WeightedEdge

type WeightedEdge struct {
	U      string
	V      string
	Weight int
}

WeightedEdge represents an edge in a weighted graph.

Fields:

U: The name of the first vertex (string).
V: The name of the second vertex (string).
Weight: The weight of the edge (int).

type WeightedGraph

type WeightedGraph struct {
	Vertices map[string]map[string]int
}

func NewWeightedGraph

func NewWeightedGraph() *WeightedGraph

func (*WeightedGraph) AddEdge

func (g *WeightedGraph) AddEdge(vertex1, vertex2 string, weight int)

func (*WeightedGraph) GetEdgeWeight

func (g *WeightedGraph) GetEdgeWeight(vertex1, vertex2 string) (int, bool)

func (*WeightedGraph) GetEdges

func (g *WeightedGraph) GetEdges() []WeightedEdge

Returns a slice of all edges in the graph.

IMPORTANT: The order of edges in the returned slice is NOT guaranteed to be deterministic.

The function relies on the invariant of the Vertices map (u < v for any edge (u, v)) to ensure that it only adds one representation of each undirected edge to the result.

func (*WeightedGraph) GetNeighbors

func (g *WeightedGraph) GetNeighbors(vertex string) map[string]int

func (*WeightedGraph) HasEdge

func (g *WeightedGraph) HasEdge(vertex1, vertex2 string) bool

func (*WeightedGraph) RemoveEdge

func (g *WeightedGraph) RemoveEdge(vertex1, vertex2 string)

type WeightedOrientedGraph

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

func NewWeightedOrientedGraph

func NewWeightedOrientedGraph() *WeightedOrientedGraph

func (*WeightedOrientedGraph) AddEdge

func (g *WeightedOrientedGraph) AddEdge(vertex1, vertex2 string, weight int)

func (*WeightedOrientedGraph) GetEdgeWeight

func (g *WeightedOrientedGraph) GetEdgeWeight(vertex1, vertex2 string) (int, bool)

func (*WeightedOrientedGraph) GetNeighbors

func (g *WeightedOrientedGraph) GetNeighbors(vertex string) map[string]int

func (*WeightedOrientedGraph) HasEdge

func (g *WeightedOrientedGraph) HasEdge(vertex1, vertex2 string) bool

func (*WeightedOrientedGraph) RemoveEdge

func (g *WeightedOrientedGraph) RemoveEdge(vertex1, vertex2 string)

Jump to

Keyboard shortcuts

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