Class SortablePrecedenceGraph<T>

A precedence graph with nodes that are sortable by assigning a numeric priority.

Type Parameters

Hierarchy (view full)

Constructors

  • Create a sortable precedence graph. If a type and precedence graph are given, then remove all nodes that are not of the given type in a way the preserves the original lineage.

    Type Parameters

    Parameters

    • Optionaltype: (new (...args: never[]) => T)

      A type that extends T.

        • new (...args): T
        • Parameters

          • Rest...args: never[]

          Returns T

    • Optionalpg: PrecedenceGraph<unknown>

      A precedence graph.

    Returns SortablePrecedenceGraph<T>

Properties

adjacencyMap: Map<T, Set<T>> = ...

A map from nodes to the set of their upstream neighbors.

numberOfEdges: number = 0

The total number of edges in the graph.

toString: (() => string) = ...

Methods

  • Add all the nodes and edges from the given precedence graph to this one.

    Parameters

    • pg: this

      A precedence graph

    Returns void

  • Add an edge from an upstream node to a downstream one.

    Parameters

    • upstream: T

      The node at which the directed edge starts.

    • downstream: T

      The node at which the directed edge ends.

    Returns void

  • Remove a directed edge from an upstream node to a downstream one.

    Parameters

    • upstream: T

      The node at which the directed edge starts.

    • downstream: T

      The node at which the directed edge ends.

    Returns void

  • Return the size of the graph in terms of number of nodes and edges.

    Returns [number, number]

  • Return a representation that conforms with the syntax of mermaid.js

    Parameters

    • OptionaledgesWithIssue: [T, T][]

      An array containing arrays with [origin, effect]. Denotes edges in the graph that causes issues to the execution, will be visualized as --x in mermaid.

    Returns string

  • Assign priorities to the nodes of the graph such that any two nodes of which one has precedence over the other, the priority of the one node is lower than the other.

    Parameters

    • destructive: boolean = false

      Destroy the graph structure if true, leave it in tact by working on a copy if false (the default).

    • spacing: number = 100

      The minimum spacing between the priorities of two nodes that are in a precedence relationship. The default is 100.

    Returns boolean

    True if priorities were assigned successfully, false if the graph has one or more cycles.