Graphity for TypeScript 3.0.0
    Preparing search index...

    The type of every edge of a graph in a depth-first search: tree, back, forward or cross edge, as EdgeType defines them.

    The types depend on the search. Uses a depth-first search, without recursion. The search starts at the nodes in ascending order and takes the out-nodes of each node in ascending order, as DfsTraverser.run does. EdgeTypes.typeOf returns the type of one edge, and Edges.of collects the edges of one type. Here, cfg is the control flow of a method with a loop and a branch: the edge next -> header closes the loop, and body -> next skips then:

    const types = EdgeTypes.of(cfg);
    const loopEdge = types.typeOf(cfg.edgeIndexOf(next, header));
    const forwardEdges = Edges.of(types, EdgeType.FORWARD);
    // loopEdge: EdgeType.BACK
    // forwardEdges: body -> next

    A graph is a DAG (directed acyclic graph) exactly if it has no back edge. For the back edges alone, BackEdges.of saves the classification of the other edges.

    Instances are immutable.

    Memory: 1 byte per edge; an instance also keeps a reference to its graph.

    Index
    • Returns the type of edge edgeIndex.

      Time: O(1).

      Parameters

      • edgeIndex: number

        edge index in 0..edgeCount-1

      Returns EdgeType

      edge type

      RangeError if edgeIndex is out of range

    • Returns the type of every edge of graph, from one depth-first search.

      Time: O(nodeCount + edgeCount). Memory: edgeCount bytes for the result; while it runs, 4 bytes and 2 bits per node, and up to 8 x nodeCount bytes for the stack, which grows with the deepest path.

      Parameters

      • graph: Graph

        the graph to classify

      Returns EdgeTypes

      the edge types

      Error if a depth-first path is longer than 2^30 - 5 nodes