Generic implementation of graph data structure
Types
Graph[Id] = object isDirected*: bool edges: OrderedTable[Id, seq[Id]]
- Source Edit
GraphCyclesError = ref object of GraphError
- Source Edit
GraphError = ref object of CatchableError
- Source Edit
Procs
func computeInDegrees[Id](graph: Graph[Id]): CountTable[Id]
- Source Edit
proc connectedComponents[Id](graph: Graph[Id]; overrideDirected: bool = false): seq[ HashSet[Id]]
- Return nodes forming strongly connected components Source Edit
proc findCycles[Id](graph: Graph[Id]; ignoreSelf: bool = false; overrideDirected: bool = false; yieldMultiedge: bool = false): seq[ Path[Id]]
- Source Edit
proc getNoIncoming[Id](graph: Graph[Id]): seq[Id]
- Get all nodes with zero in degree of zero Source Edit
func inDeg[Id](graph: Graph[Id]; node: Id): int {.inline.}
- Return in degree for @arg{node} Source Edit
proc removeEdge[Id](graph: var Graph[Id]; edge: GraphEdge[Id])
- Remove edge from graph. Note that starting/ending nodes will not be removed. Source Edit
proc removeNode[Id](graph: var Graph[Id]; node: Id)
-
Remove node from graph.
Note that all edges that node is part of are removed too.
Source Edit
Iterators
iterator breadthFirst[Id](graph: Graph[Id]; root: Id): Id
- Perform breadth-first iteration of parent graph, starting from node Source Edit
iterator depthFirst[Id](graph: Graph[Id]; root: Id): tuple[id: Id, depth: int]
- Perform depth-first iteration of mutable nodes in graph, starting from node Source Edit
iterator inEdges[Id](graph: Graph[Id]; target: Id): GraphEdge[Id]
- Iterate over ingoing edges for target Source Edit