Documentation ¶
Index ¶
- Variables
- func BFS[K comparable](g Graph[K], entry K, while func(vertex K, depth uint) bool) error
- func DFS[K comparable](g Graph[K], entry K, while func(vertex K) bool) error
- type Graph
- type GraphReadWriter
- type Grid
- func (g *Grid) AddEdges(edges ...[2][2]int) error
- func (g *Grid) AddVertices(vertices ...[2]int) error
- func (g *Grid) Adjacency(vertex [2]int) [][2]int
- func (g *Grid) DeleteEdges(edges ...[2][2]int)
- func (g *Grid) DeleteVertices(vertices ...[2]int)
- func (g *Grid) Order() int
- func (g *Grid) Vertices() [][2]int
- type Indexed
- func (g *Indexed[U]) AddEdges(edges ...[2]U) error
- func (g *Indexed[U]) AddVertices(vertices ...U) error
- func (g *Indexed[U]) Adjacency(vertex U) []U
- func (g *Indexed[U]) DeleteEdges(edges ...[2]U)
- func (g *Indexed[U]) DeleteVertices(vertices ...U)
- func (g *Indexed[U]) Order() int
- func (g *Indexed[U]) Vertices() []U
- type Mapped
- type Number
- type Reader
- type WeightedGraph
- type Writer
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLoop = errors.New("simple graph can't contain loops")
View Source
var ErrNilVertex = errors.New("nil vertex")
View Source
var ErrVertexExists = errors.New("vertex already exists")
Functions ¶
Types ¶
type Graph ¶
type Graph[K comparable] interface { // There are three possible outputs Adjacency method has: // Nil slice: there in no a such vertex in the graph; // Empty slice: given vertex does not have neighbors; // Slice with values: all neighbors of the vertex. Adjacency(vertex K) []K }
Graph is the interface that wraps the basic Adjacency method.
type GraphReadWriter ¶
type GraphReadWriter[K comparable] interface { Graph[K] Reader[K] Writer[K] }
type Grid ¶
type Grid struct {
// contains filtered or unexported fields
}
func (*Grid) AddVertices ¶
func (*Grid) DeleteEdges ¶
func (*Grid) DeleteVertices ¶
type Indexed ¶
type Indexed[U unsigned] struct {
// contains filtered or unexported fields
}
Unstable - vertex deletion, moves the last vertex to the place of the deleted one.
func NewIndexed ¶
func NewIndexed[U unsigned]() *Indexed[U]
func (*Indexed[U]) AddVertices ¶
If only one vertex passed, increases slice size by its value. If more than one passed, increases slice size by amount of vertices passed.
func (*Indexed[U]) DeleteEdges ¶
func (g *Indexed[U]) DeleteEdges(edges ...[2]U)
func (*Indexed[U]) DeleteVertices ¶
func (g *Indexed[U]) DeleteVertices(vertices ...U)
Deleted vertices get replaced by last ones.
type Mapped ¶
type Mapped[K comparable] struct { // contains filtered or unexported fields }
func NewMapped ¶
func NewMapped[K comparable]() *Mapped[K]
func (*Mapped[K]) AddVertices ¶
func (*Mapped[K]) DeleteEdges ¶
func (g *Mapped[K]) DeleteEdges(edges ...[2]K)
func (*Mapped[K]) DeleteVertices ¶
func (g *Mapped[K]) DeleteVertices(vertices ...K)
type Reader ¶
type Reader[K comparable] interface { // Returns all vertices in the graph. // Must not return nil. // Infinite graph should return vertices that can't be procedural calculated. Vertices() []K // Returns amount of vertices in graph. // Infinite graph should return -1. Order() int }
Reader is the interface that defines graph data read methods.
type WeightedGraph ¶
type WeightedGraph[K comparable, N Number] interface { Graph[K] VerticesValues(vertices ...K) []N EdgesValues(vertices ...[2]K) []N }
type Writer ¶
type Writer[K comparable] interface { AddVertices(vertices ...K) error DeleteVertices(vertices ...K) AddEdges(edges ...[2]K) error DeleteEdges(edges ...[2]K) }
Reader is the interface that defines methods that allow modify graph data.
Click to show internal directories.
Click to hide internal directories.