Graphity for TypeScript 3.0.0
    Preparing search index...

    A topological order of a DAG (directed acyclic graph) with the level of each node. A root node has level 0, and every other node has one more than the highest level of its in-nodes.

    The level of a node is the number of edges on a longest path to it from a root node, so no path connects two nodes of the same level. TopOrderAndLevels.order lists the nodes level by level, TopOrderAndLevels.levelOf and TopOrderAndLevels.levels return their levels, and TopOrderAndLevels.levelCount the number of levels.

    Uses Kahn's algorithm: TopOrderAndLevels.of starts with the root nodes in ascending order, places a node once all its in-nodes are placed and takes the out-nodes of each node in ascending order, so a graph always gets the same order. For the order alone, TopOrder.of needs less memory.

    Instances are immutable.

    Memory: 8 x nodeCount bytes.

    Index
    • get levelCount(): number

      The number of levels, or 0 for a graph without nodes (Java: levelCount()). It equals the number of nodes on a longest path.

      Time: O(1).

      Returns number

    • get levels(): Int32Array

      The level of every node, by node ID; not to be modified (Java: levels(), an unmodifiable list).

      Time: O(1).

      Returns Int32Array

    • get order(): Int32Array

      The nodes in topological order, level by level: for every edge u -> v, u comes before v; not to be modified (Java: order(), an unmodifiable list).

      Time: O(1).

      Returns Int32Array

    • Returns the level of node. Equivalent to levels[node].

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      level

      RangeError if node is out of range

    • Returns the topological order and the levels of graph.

      On a BiAdjacentGraph, it reads the in-degrees instead of counting them in a pass over the edges.

      Time: O(nodeCount + edgeCount). Memory: 8 x nodeCount bytes for the result; while it runs, 8 x nodeCount bytes more.

      Parameters

      • graph: Graph

        the DAG to sort

      Returns TopOrderAndLevels

      the order and the levels

      Error if graph has a cycle