graph

package
v0.0.0-...-7d464a8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: EUPL-1.2 Imports: 4 Imported by: 0

Documentation

Overview

Package graph implements a (directed) graph of orderable values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Digraph

type Digraph[T cmp.Ordered] map[T]*set.Set[T]

Digraph relates orderable values in a directional way.

func (Digraph[T]) AddEdge

func (dg Digraph[T]) AddEdge(from, to T) Digraph[T]

AddEdge adds a connection from `from` to `to`. Both vertices must be added before. Otherwise the function may panic.

func (Digraph[T]) AddEgdes

func (dg Digraph[T]) AddEgdes(edges EdgeSlice[T]) Digraph[T]

AddEgdes adds all given `Edge`s to the digraph.

In contrast to `AddEdge` the vertices must not exist before.

func (Digraph[T]) AddVertex

func (dg Digraph[T]) AddVertex(v T) Digraph[T]

AddVertex adds an edge / vertex to the digraph.

func (Digraph[T]) Clone

func (dg Digraph[T]) Clone() Digraph[T]

Clone a digraph.

func (Digraph[T]) Edges

func (dg Digraph[T]) Edges() (es EdgeSlice[T])

Edges returns an unsorted slice of the edges of the digraph.

func (Digraph[T]) Equal

func (dg Digraph[T]) Equal(other Digraph[T]) bool

Equal returns true if both digraphs have the same vertices and edges.

func (Digraph[T]) HasVertex

func (dg Digraph[T]) HasVertex(v T) bool

HasVertex returns true, if `v` is a vertex of the digraph.

func (Digraph[T]) IsDAG

func (dg Digraph[T]) IsDAG() (T, bool)

IsDAG returns a vertex and false, if the graph has a cycle containing the vertex.

func (Digraph[T]) Originators

func (dg Digraph[T]) Originators() *set.Set[T]

Originators will return the set of all vertices that are not referenced at the to-part of an edge.

func (Digraph[T]) ReachableVertices

func (dg Digraph[T]) ReachableVertices(startV T) (tc *set.Set[T])

ReachableVertices calculates the set of all vertices that are reachable from the given vertex `startV`.

func (Digraph[T]) RemoveVertex

func (dg Digraph[T]) RemoveVertex(v T)

RemoveVertex removes a vertex and all its edges from the digraph.

func (Digraph[T]) Reverse

func (dg Digraph[T]) Reverse() (revDg Digraph[T])

Reverse returns a graph with reversed edges.

func (Digraph[T]) SortReverse

func (dg Digraph[T]) SortReverse() (sl []T)

SortReverse returns a deterministic, topological, reverse sort of the digraph.

Works only if digraph is a DAG. Otherwise the algorithm will not terminate or returns an arbitrary value.

func (Digraph[T]) Terminators

func (dg Digraph[T]) Terminators() (terms *set.Set[T])

Terminators returns the set of all vertices that does not reference other vertices.

func (Digraph[T]) TransitiveClosure

func (dg Digraph[T]) TransitiveClosure(v T) (tc Digraph[T])

TransitiveClosure calculates the sub-graph that is reachable from `v`.

func (Digraph[T]) Vertices

func (dg Digraph[T]) Vertices() *set.Set[T]

Vertices returns the set of all vertices.

type Edge

type Edge[T cmp.Ordered] struct {
	From, To T
}

Edge is a pair of two vertices.

type EdgeSlice

type EdgeSlice[T cmp.Ordered] []Edge[T]

EdgeSlice is a slice of Edges

func (EdgeSlice[T]) Equal

func (es EdgeSlice[T]) Equal(other EdgeSlice[T]) bool

Equal return true if both slices are the same.

func (EdgeSlice[T]) Sort

func (es EdgeSlice[T]) Sort() EdgeSlice[T]

Sort the slice.

Jump to

Keyboard shortcuts

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