dag

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAG

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

DAG type implements a Directed Acyclic Graph data structure.

func NewDAG

func NewDAG() *DAG

NewDAG creates a new Directed Acyclic Graph or DAG.

func (*DAG) AddEdge

func (d *DAG) AddEdge(tailVertex *Vertex, headVertex *Vertex) error

AddEdge adds a directed edge between two existing vertices to the graph.

func (*DAG) AddVertex

func (d *DAG) AddVertex(v *Vertex) error

AddVertex adds a vertex to the graph.

func (*DAG) DeleteEdge

func (d *DAG) DeleteEdge(tailVertex *Vertex, headVertex *Vertex) error

DeleteEdge deletes a directed edge between two existing vertices from the graph.

func (*DAG) DeleteVertex

func (d *DAG) DeleteVertex(vertex *Vertex) error

DeleteVertex deletes a vertex and all the edges referencing it from the graph.

func (*DAG) GetVertex

func (d *DAG) GetVertex(id interface{}) (*Vertex, error)

GetVertex return a vertex from the graph given a vertex ID.

func (*DAG) Order

func (d *DAG) Order() int

Order return the number of vertices in the graph.

func (*DAG) Predecessors

func (d *DAG) Predecessors(vertex *Vertex) ([]*Vertex, error)

Predecessors return vertices that are parent of a given vertex.

func (*DAG) SinkVertices

func (d *DAG) SinkVertices() []*Vertex

SinkVertices return vertices with no children defined by the graph edges.

func (*DAG) Size

func (d *DAG) Size() int

Size return the number of edges in the graph.

func (*DAG) SourceVertices

func (d *DAG) SourceVertices() []*Vertex

SourceVertices return vertices with no parent defined by the graph edges.

func (*DAG) String

func (d *DAG) String() string

String implements stringer interface.

Prints an string representation of this instance.

func (*DAG) Successors

func (d *DAG) Successors(vertex *Vertex) ([]*Vertex, error)

Successors return vertices that are children of a given vertex.

type Vertex

type Vertex struct {
	ID       string
	Value    interface{}
	Parents  orders.OrderSet
	Children orders.OrderSet
}

Vertex type implements a vertex of a Directed Acyclic graph or DAG.

func NewVertex

func NewVertex(id string, value interface{}) *Vertex

NewVertex creates a new vertex.

func (*Vertex) Degree

func (v *Vertex) Degree() int

Degree return the number of parents and children of the vertex

func (*Vertex) InDegree

func (v *Vertex) InDegree() int

InDegree return the number of parents of the vertex or the number of edges entering on it.

func (*Vertex) OutDegree

func (v *Vertex) OutDegree() int

OutDegree return the number of children of the vertex or the number of edges leaving it.

func (*Vertex) String

func (v *Vertex) String() string

String implements stringer interface and prints an string representation of this instance.

Jump to

Keyboard shortcuts

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