graph

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package graph implements a specialised directed acyclic graph (DAG) and the required topological sorting needed for spok's task dependency system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

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

Graph is a DAG designed to hold spok tasks.

func New

func New() *Graph

New constructs and returns a new Graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(parent, child *Vertex) error

AddEdge creates an edge connection from parent to child vertices.

func (*Graph) AddVertex

func (g *Graph) AddVertex(v *Vertex)

AddVertex adds the passed vertex to the graph, if a vertex with that name already exists it will be overwritten.

func (*Graph) ContainsVertex

func (g *Graph) ContainsVertex(name string) bool

ContainsVertex reports whether a graph contains a certain vertex.

func (*Graph) GetVertex

func (g *Graph) GetVertex(name string) (*Vertex, bool)

GetVertex gets a vertex by it's name.

func (*Graph) Size

func (g *Graph) Size() int

Size returns the number of vertices in the graph.

func (*Graph) Sort

func (g *Graph) Sort() ([]*Vertex, error)

Sort topologically sorts the graph and returns a vertex slice in the correct order.

type Vertex

type Vertex struct {
	Name string    // Uniquely identifiable name
	Task task.Task // The actual underlying task represented by this vertex
	// contains filtered or unexported fields
}

Vertex represents a single node in the graph.

func NewVertex

func NewVertex(task task.Task) *Vertex

NewVertex creates and returns a new Vertex.

func (*Vertex) Children

func (v *Vertex) Children() []*Vertex

Children returns the vertices children.

func (*Vertex) Parents

func (v *Vertex) Parents() []*Vertex

Parents returns the vertices parents.

Jump to

Keyboard shortcuts

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