Documentation ¶
Index ¶
- Variables
- func TestBFS(t *testing.T)
- func TestDFS(t *testing.T)
- type BreadthFirst
- type Builder
- type DebugFunc
- type DebugSelector
- type DebugVisitor
- type DepthFirst
- type Destination
- type Directed
- type Direction
- type Edge
- type Node
- type Origination
- type OriginationMap
- type Selector
- type SelectorFunc
- type Visitor
- type VisitorArray
- type VisitorFunc
- type Walker
Constants ¶
This section is empty.
Variables ¶
var ErrDestNotFound = errors.New("destination not found")
var ErrNodeNotFound = errors.New("node not found")
var ErrOriginNotFound = errors.New("origin not found")
Functions ¶
Types ¶
type BreadthFirst ¶
type BreadthFirst[T Direction] struct { Visitor Selector[T] }
type Builder ¶
type Builder struct {
G Directed
}
adds nodes and edges to a Directed
func (*Builder) AddEdge ¶
func (b *Builder) AddEdge(o Origination, d Destination) error
connects o -> d, if either node doesn't exist they are created
duplicate edges are not added, order isn't guaranteed
func (*Builder) AddEdges ¶
func (b *Builder) AddEdges(e OriginationMap) error
type DebugSelector ¶
calls F on current node, selected and err results from S
type DebugVisitor ¶
type DebugVisitor struct { F DebugFunc V Visitor }
calls F on current node, error from V
type DepthFirst ¶
type DepthFirst[T Direction] struct { Visitor Selector[T] }
type Destination ¶
type Destination Node
an entity in the graph that is the destination for an edge
func (Destination) String ¶
func (d Destination) String() string
type Directed ¶
type Directed struct {
// contains filtered or unexported fields
}
adjanceny list, edges maintain insertion order, nodes do not do not construct directly, use a provided ctor direct usage of Directed is readonly
func FromOriginationMap ¶
func FromOriginationMap(src OriginationMap) Directed
func WithCapacity ¶
func (Directed) Predecessors ¶
func (g Directed) Predecessors(n Node) ([]Origination, error)
given Node n, find all other nodes that point at it
func (Directed) Successors ¶
func (g Directed) Successors(n Node) ([]Destination, error)
given Node n, find all nodes that it points at
type Direction ¶
type Direction interface { Origination | Destination }
allows specifying direction when interacting with a Directed graph
type Edge ¶
type Edge struct { O Origination D Destination }
a connection between two entities in the graph
type Origination ¶
type Origination Node
an entity in the graph that is the origination for an edge
func (Origination) String ¶
func (o Origination) String() string
type OriginationMap ¶
type OriginationMap map[Origination][]Destination
describes a graph as the set of originating edges
type Selector ¶
responsible for determining which nodes to explore next and in which direction to explore
type SelectorFunc ¶
var ( // given Node n, return all nodes it points at Successors SelectorFunc[Destination] = Directed.Successors // given Node n, return all nodes that point at it Predecessors SelectorFunc[Origination] = Directed.Predecessors // visitors should return this err to gracefully exit a walk ErrVisitTerminated = errors.New("visit terminated") )
type Visitor ¶
called with the current node and a context visitors may gracefully end a walk by returning ErrVisitTerminated all other errors terminate the walk and the error is returned to the user