graph

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package graph provides a generic implementation of a Graph data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge[T any] struct {
	To    int
	Value T
}

Edge represents an edge in a Graph.

type Graph

type Graph[T any] struct {
	// for optimization this is public
	Edges [][]Edge[T]
	// contains filtered or unexported fields
}

Graph is a generic graph structure where each edge holds a value of type T.

func New

func New[T any](size int, isDirected bool) *Graph[T]

New creates and returns a new instance of Graph with the specified size.

func (*Graph[T]) AddEdge

func (g *Graph[T]) AddEdge(from, to int, value T)

AddEdge adds a new edge to the graph.

func (*Graph[T]) AddEdgeDefault

func (g *Graph[T]) AddEdgeDefault(from, to int)

AddEdgeDefault adds a new edge to the graph with a default value of T.

func (*Graph[T]) AddEdges

func (g *Graph[T]) AddEdges(vertex int, edges []Edge[T])

AddEdges adds a slice of edges to the graph at the specified vertex int.

func (*Graph[T]) AddEdgesDefault added in v0.2.0

func (g *Graph[T]) AddEdgesDefault(from int, to ...int)

AddEdgesDefault adds new edges to the graph with a default value of T.

func (*Graph[T]) IsDirected

func (g *Graph[T]) IsDirected() bool

IsDirected checks and returns whether the graph is directed or not.

func (*Graph[T]) Size

func (g *Graph[T]) Size() int

Size returns the size of the graph which is the number of edges it has.

Jump to

Keyboard shortcuts

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