Documentation ¶
Index ¶
- func JSON2Dot(r io.Reader) ([]byte, error)
- func StronglyConnected(g *Graph) [][]Vertex
- func VertexName(raw Vertex) string
- type AcyclicGraph
- func (g *AcyclicGraph) Ancestors(v Vertex) (*Set, error)
- func (g *AcyclicGraph) Cycles() [][]Vertex
- func (g *AcyclicGraph) DepthFirstWalk(start []Vertex, f DepthWalkFunc) error
- func (g *AcyclicGraph) Descendents(v Vertex) (*Set, error)
- func (g *AcyclicGraph) DirectedGraph() Grapher
- func (g *AcyclicGraph) ReverseDepthFirstWalk(start []Vertex, f DepthWalkFunc) error
- func (g *AcyclicGraph) Root() (Vertex, error)
- func (g *AcyclicGraph) TransitiveReduction()
- func (g *AcyclicGraph) Validate() error
- func (g *AcyclicGraph) Walk(cb WalkFunc) error
- type DebugOperationEnd
- type DepthWalkFunc
- type DotNode
- type DotOpts
- type Edge
- type Graph
- func (g *Graph) Add(v Vertex) Vertex
- func (g *Graph) Connect(edge Edge)
- func (g *Graph) DebugEdgeInfo(e Edge, info string)
- func (g *Graph) DebugOperation(operation string, info string) DebugOperationEnd
- func (g *Graph) DebugVertexInfo(v Vertex, info string)
- func (g *Graph) DebugVisitInfo(v Vertex, info string)
- func (g *Graph) DirectedGraph() Grapher
- func (g *Graph) Dot(opts *DotOpts) []byte
- func (g *Graph) DownEdges(v Vertex) *Set
- func (g *Graph) Edges() []Edge
- func (g *Graph) EdgesFrom(v Vertex) []Edge
- func (g *Graph) EdgesTo(v Vertex) []Edge
- func (g *Graph) HasEdge(e Edge) bool
- func (g *Graph) HasVertex(v Vertex) bool
- func (g *Graph) MarshalJSON() ([]byte, error)
- func (g *Graph) Remove(v Vertex) Vertex
- func (g *Graph) RemoveEdge(edge Edge)
- func (g *Graph) Replace(original, replacement Vertex) bool
- func (g *Graph) SetDebugWriter(w io.Writer)
- func (g *Graph) String() string
- func (g *Graph) StringWithNodeTypes() string
- func (g *Graph) UpEdges(v Vertex) *Set
- func (g *Graph) Vertices() []Vertex
- type GraphNodeDotter
- type Grapher
- type Hashable
- type NamedVertex
- type Set
- type Subgrapher
- type Vertex
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JSON2Dot ¶ added in v0.8.2
JSON2Dot reads a Graph debug log from and io.Reader, and converts the final graph dot format.
TODO: Allow returning the output at a certain point during decode.
Encode extra information from the json log into the Dot.
func StronglyConnected ¶
StronglyConnected returns the list of strongly connected components within the Graph g. This information is primarily used by this package for cycle detection, but strongly connected components have widespread use.
Types ¶
type AcyclicGraph ¶
type AcyclicGraph struct {
Graph
}
AcyclicGraph is a specialization of Graph that cannot have cycles. With this property, we get the property of sane graph traversal.
func (*AcyclicGraph) Ancestors ¶
func (g *AcyclicGraph) Ancestors(v Vertex) (*Set, error)
Returns a Set that includes every Vertex yielded by walking down from the provided starting Vertex v.
func (*AcyclicGraph) Cycles ¶ added in v0.5.0
func (g *AcyclicGraph) Cycles() [][]Vertex
func (*AcyclicGraph) DepthFirstWalk ¶ added in v0.5.0
func (g *AcyclicGraph) DepthFirstWalk(start []Vertex, f DepthWalkFunc) error
depthFirstWalk does a depth-first walk of the graph starting from the vertices in start. This is not exported now but it would make sense to export this publicly at some point.
func (*AcyclicGraph) Descendents ¶
func (g *AcyclicGraph) Descendents(v Vertex) (*Set, error)
Returns a Set that includes every Vertex yielded by walking up from the provided starting Vertex v.
func (*AcyclicGraph) DirectedGraph ¶ added in v0.8.2
func (g *AcyclicGraph) DirectedGraph() Grapher
func (*AcyclicGraph) ReverseDepthFirstWalk ¶ added in v0.5.0
func (g *AcyclicGraph) ReverseDepthFirstWalk(start []Vertex, f DepthWalkFunc) error
reverseDepthFirstWalk does a depth-first walk _up_ the graph starting from the vertices in start.
func (*AcyclicGraph) Root ¶
func (g *AcyclicGraph) Root() (Vertex, error)
Root returns the root of the DAG, or an error.
Complexity: O(V)
func (*AcyclicGraph) TransitiveReduction ¶
func (g *AcyclicGraph) TransitiveReduction()
TransitiveReduction performs the transitive reduction of graph g in place. The transitive reduction of a graph is a graph with as few edges as possible with the same reachability as the original graph. This means that if there are three nodes A => B => C, and A connects to both B and C, and B connects to C, then the transitive reduction is the same graph with only a single edge between A and B, and a single edge between B and C.
The graph must be valid for this operation to behave properly. If Validate() returns an error, the behavior is undefined and the results will likely be unexpected.
Complexity: O(V(V+E)), or asymptotically O(VE)
func (*AcyclicGraph) Validate ¶
func (g *AcyclicGraph) Validate() error
Validate validates the DAG. A DAG is valid if it has a single root with no cycles.
func (*AcyclicGraph) Walk ¶
func (g *AcyclicGraph) Walk(cb WalkFunc) error
Walk walks the graph, calling your callback as each node is visited. This will walk nodes in parallel if it can. Because the walk is done in parallel, the error returned will be a multierror.
type DebugOperationEnd ¶ added in v0.8.2
type DebugOperationEnd func(string)
The DebugOperationEnd func type provides a way to call an End function via a method call, allowing for the chaining of methods in a defer statement.
func (DebugOperationEnd) End ¶ added in v0.8.2
func (e DebugOperationEnd) End(info string)
End calls function e with the info parameter, marking the end of this operation in the logs.
type DepthWalkFunc ¶ added in v0.5.0
DepthWalkFunc is a walk function that also receives the current depth of the walk as an argument
type DotNode ¶ added in v0.8.2
DotNode provides a structure for Vertices to return in order to specify their dot format.
type DotOpts ¶ added in v0.8.2
type DotOpts struct { // Allows some nodes to decide to only show themselves when the user has // requested the "verbose" graph. Verbose bool // Highlight Cycles DrawCycles bool // How many levels to expand modules as we draw MaxDepth int // contains filtered or unexported fields }
DotOpts are the options for generating a dot formatted Graph.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is used to represent a dependency graph.
func (*Graph) Add ¶
Add adds a vertex to the graph. This is safe to call multiple time with the same Vertex.
func (*Graph) Connect ¶
Connect adds an edge with the given source and target. This is safe to call multiple times with the same value. Note that the same value is verified through pointer equality of the vertices, not through the value of the edge itself.
func (*Graph) DebugEdgeInfo ¶ added in v0.8.2
DebugEdgeInfo encodes arbitrary information about an edge in the graph debug logs.
func (*Graph) DebugOperation ¶ added in v0.8.2
func (g *Graph) DebugOperation(operation string, info string) DebugOperationEnd
DebugOperation marks the start of a set of graph transformations in the debug log, and returns a DebugOperationEnd func, which marks the end of the operation in the log. Additional information can be added to the log via the info parameter.
The returned func's End method allows this method to be called from a single defer statement:
defer g.DebugOperationBegin("OpName", "operating").End("")
The returned function must be called to properly close the logical operation in the logs.
func (*Graph) DebugVertexInfo ¶ added in v0.8.2
DebugVertexInfo encodes arbitrary information about a vertex in the graph debug logs.
func (*Graph) DebugVisitInfo ¶ added in v0.8.2
DebugVisitInfo records a visit to a Vertex during a walk operation.
func (*Graph) DirectedGraph ¶ added in v0.8.2
func (*Graph) EdgesFrom ¶ added in v0.7.8
EdgesFrom returns the list of edges from the given source.
func (*Graph) HasVertex ¶ added in v0.6.11
HasVertex checks if the given Vertex is present in the graph.
func (*Graph) MarshalJSON ¶ added in v0.8.2
MarshalJSON returns a JSON representation of the entire Graph.
func (*Graph) Remove ¶
Remove removes a vertex from the graph. This will also remove any edges with this vertex as a source or target.
func (*Graph) RemoveEdge ¶
RemoveEdge removes an edge from the graph.
func (*Graph) Replace ¶
Replace replaces the original Vertex with replacement. If the original does not exist within the graph, then false is returned. Otherwise, true is returned.
func (*Graph) SetDebugWriter ¶ added in v0.8.2
SetDebugWriter sets the io.Writer where the Graph will record debug information. After this is set, the graph will immediately encode itself to the stream, and continue to record all subsequent operations.
func (*Graph) StringWithNodeTypes ¶ added in v0.6.15
String outputs some human-friendly output for the graph structure.
type GraphNodeDotter ¶ added in v0.8.2
type GraphNodeDotter interface { // Dot is called to return the dot formatting for the node. // The first parameter is the title of the node. // The second parameter includes user-specified options that affect the dot // graph. See GraphDotOpts below for details. DotNode(string, *DotOpts) *DotNode }
GraphNodeDotter can be implemented by a node to cause it to be included in the dot graph. The Dot method will be called which is expected to return a representation of this node.
type Grapher ¶ added in v0.8.2
type Grapher interface {
DirectedGraph() Grapher
}
A Grapher is any type that returns a Grapher, mainly used to identify dag.Graph and dag.AcyclicGraph. In the case of Graph and AcyclicGraph, they return themselves.
type Hashable ¶
type Hashable interface {
Hashcode() interface{}
}
Hashable is the interface used by set to get the hash code of a value. If this isn't given, then the value of the item being added to the set itself is used as the comparison value.
type NamedVertex ¶
NamedVertex is an optional interface that can be implemented by Vertex to give it a human-friendly name that is used for outputting the graph.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a set data structure.
func (*Set) Intersection ¶
Intersection computes the set intersection with other.
type Subgrapher ¶ added in v0.8.2
type Subgrapher interface {
Subgraph() Grapher
}
Subgrapher allows a Vertex to be a Graph itself, by returning a Grapher.
type Vertex ¶
type Vertex interface{}
Vertex of the graph.
func AsVertexList ¶ added in v0.5.0
simple convenience helper for converting a dag.Set to a []Vertex