graph

package
v0.0.0-...-a19c61f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

Package graph provides a directed graph implementation.

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 directed graph.

func New

func New() *Graph

New returns a new Graph.

func (*Graph) AckChange

func (g *Graph) AckChange()

AckChange acknowledges changes to the Graph, resetting the dirty flag.

func (*Graph) Exists

func (g *Graph) Exists(n *Node) bool

Exists checks whether the Node exists in the graph.

func (*Graph) HasChanged

func (g *Graph) HasChanged() bool

HasChanged returns whether or not the Graph state is dirty.

func (*Graph) NewConnection

func (g *Graph) NewConnection(from, to *Node) error

NewConnection creates a connection between two Nodes.

func (*Graph) NewNode

func (g *Graph) NewNode(v interface{}) *Node

NewNode creates a new Node in the Graph.

func (*Graph) RemoveConnection

func (g *Graph) RemoveConnection(from, to *Node) error

RemoveConnection removes a connection between two Nodes.

func (*Graph) RemoveNode

func (g *Graph) RemoveNode(n *Node) error

RemoveNode removes a Node from the Graph.

func (*Graph) Size

func (g *Graph) Size() int

Size returns the number of nodes in the graph.

func (*Graph) Sorted

func (g *Graph) Sorted() [][]*Node

Sorted returns a topologically sorted list of strongly connected components in the Graph.

type Node

type Node struct {
	Value interface{}
	// contains filtered or unexported fields
}

Node is a member of a Graph

func (*Node) InNeighborCount

func (n *Node) InNeighborCount() int

InNeighborCount returns the count of inbound neighbors

func (*Node) InNeighbors

func (n *Node) InNeighbors() []*Node

InNeighbors returns only neighboring Nodes with an inbound connection to this Node

func (*Node) NeighborCount

func (n *Node) NeighborCount() int

NeighborCount returns the total neighbor count

func (*Node) OutNeighborCount

func (n *Node) OutNeighborCount() int

OutNeighborCount returns the count of outbound neighbors

func (*Node) OutNeighbors

func (n *Node) OutNeighbors() []*Node

OutNeighbors returns only neighboring Nodes with an outbound connection from this Node

type NotInGraphError

type NotInGraphError struct {
	Node *Node
}

NotInGraphError is an error that will be returned if a Node cannot be found in a Graph

func (NotInGraphError) Error

func (n NotInGraphError) Error() string

Jump to

Keyboard shortcuts

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