dag

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVertexNotFound represents vertex not found.
	ErrVertexNotFound = errors.New("vertex not found")

	// ErrVertexAlreadyExists represents vertex already exists.
	ErrVertexAlreadyExists = errors.New("vertex already exists")

	// ErrParnetAlreadyExists represents parent of vertex already exists.
	ErrParnetAlreadyExists = errors.New("parent of vertex already exists")

	// ErrChildAlreadyExists represents child of vertex already exists.
	ErrChildAlreadyExists = errors.New("child of vertex already exists")

	// ErrCycleBetweenVertices represents cycle between vertices.
	ErrCycleBetweenVertices = errors.New("cycle between vertices")
)

Functions

This section is empty.

Types

type DAG

type DAG[T comparable] interface {
	// AddVertex adds vertex to graph.
	AddVertex(id string, value T) error

	// DeleteVertex deletes vertex graph.
	DeleteVertex(id string)

	// GetVertex gets vertex from graph.
	GetVertex(id string) (*Vertex[T], error)

	// GetVertices returns map of vertices.
	GetVertices() map[string]*Vertex[T]

	// GetRandomVertices returns random map of vertices.
	GetRandomVertices(n uint) []*Vertex[T]

	// GetVertexKeys returns keys of vertices.
	GetVertexKeys() []string

	// GetSourceVertices returns source vertices.
	GetSourceVertices() []*Vertex[T]

	// GetSinkVertices returns sink vertices.
	GetSinkVertices() []*Vertex[T]

	// VertexCount returns count of vertices.
	VertexCount() int

	// AddEdge adds edge between two vertices.
	AddEdge(fromVertexID, toVertexID string) error

	// DeleteEdge deletes edge between two vertices.
	DeleteEdge(fromVertexID, toVertexID string) error

	// CanAddEdge finds whether there are circles through depth-first search.
	CanAddEdge(fromVertexID, toVertexID string) bool
}

DAG is the interface used for directed acyclic graph.

func NewDAG

func NewDAG[T comparable]() DAG[T]

New returns a new DAG interface.

type Vertex

type Vertex[T comparable] struct {
	ID       string
	Value    T
	Parents  set.SafeSet[*Vertex[T]]
	Children set.SafeSet[*Vertex[T]]
}

Vertex is a vertex of the directed acyclic graph.

func NewVertex

func NewVertex[T comparable](id string, value T) *Vertex[T]

New returns a new Vertex instance.

func (*Vertex[T]) Degree

func (v *Vertex[T]) Degree() int

Degree returns the degree of vertex.

func (*Vertex[T]) DeleteInEdges

func (v *Vertex[T]) DeleteInEdges()

DeleteInEdges deletes inedges of vertex.

func (*Vertex[T]) DeleteOutEdges

func (v *Vertex[T]) DeleteOutEdges()

DeleteOutEdges deletes outedges of vertex.

func (*Vertex[T]) InDegree

func (v *Vertex[T]) InDegree() int

InDegree returns the indegree of vertex.

func (*Vertex[T]) OutDegree

func (v *Vertex[T]) OutDegree() int

OutDegree returns the outdegree of vertex.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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