Graphity for TypeScript 3.0.0
    Preparing search index...

    The SCCs (strongly connected components) of a graph, as Components.sccsOf returns them.

    It is a NodePartition whose groups are the SCCs, numbered by SCC ID 0..sccCount-1. Sccs.sccOf returns the SCC of a node and NodePartition.nodesOf the nodes of an SCC. Sccs.containsCycle distinguishes the SCCs with a cycle from those of a single node without one. NodePartition.condense returns the DAG (directed acyclic graph) of the SCCs.

    Every node is in exactly one SCC; a node that lies on no cycle is an SCC of its own. SCC IDs are in reverse topological order: every edge between two SCCs goes from the higher SCC ID to the lower one, so SCC 0 has no edges to other SCCs. The nodes of each SCC are in ascending order. Here, dependencies are the dependencies between the packages of a program, and names holds the names of the packages. The example groups the packages by SCC, in the order of the SCC IDs. In this order, each package comes after the packages it uses, and the packages that use each other come together:

    // The SCCs in reverse topological order, each as the names of its packages.
    const sccs = Components.sccsOf(dependencies);
    const buildOrder: string[][] = [];
    for (let scc = 0; scc < sccs.sccCount; scc++) {
    buildOrder.push(Array.from(sccs.nodesOf(scc), (node) => names[node]));
    }
    // buildOrder: [[util], [cli], [json], [model, storage], [service], [ui], [app]]

    Instances are immutable.

    Memory: 4 x (2 x nodeCount + sccCount) bytes; the graph is shared, not copied.

    Hierarchy (View Summary)

    Index
    • get indexCount(): number

      The number of indices this mapping maps from, mapped or not.

      It is the length of the arrays that gather returns and that reduce takes.

      Time: O(1).

      Returns number

    • get isPartial(): boolean

      Whether some index is not mapped. Equivalent to mappedCount < indexCount.

      Time: O(1).

      Returns boolean

    • get isStronglyConnected(): boolean

      Whether the graph is strongly connected: whether it has at most one SCC. Equivalent to sccCount <= 1.

      A graph without nodes counts as strongly connected.

      Time: O(1).

      Returns boolean

    • get mappedCount(): number

      The number of indices that are mapped; in a partition, the number of indices that belong to a group.

      Time: O(1).

      Returns number

    • Returns the condensed graph, with a node for each group and an edge between two groups wherever an edge of the partitioned graph runs between them.

      The node IDs of the condensed graph are the group IDs. It has the edge g -> h if a node in group g has an out-node in group h and g !== h. Edges within a group and edges from or to a node in no group are left out. The edges from one group to another become a single edge. Graphs.edgePartition tells which edges are behind each edge of the condensed graph. For an Sccs, the condensed graph is acyclic.

      The condensed graph is built anew on every call, not cached: keep the result to use it more than once.

      Time: O(nodeCount + edgeCount + groupCount), plus O(d log d) for each group with d out-nodes in the result. Memory: 4 x (groupCount + condensedEdgeCount) bytes for the result, where condensedEdgeCount is its edge count; while it runs, 1 bit per group and up to 6 x condensedEdgeCount bytes more.

      Returns Graph

      the condensed graph

    • Returns whether SCC sccId contains a cycle: whether it has more than one node, or a single node with a self-loop.

      Time: O(1) for an SCC of more than one node, O(log outDegree(v)) for an SCC of a single node v.

      Parameters

      • sccId: number

        SCC ID in 0..sccCount-1

      Returns boolean

      true if the SCC contains a cycle

      RangeError if sccId is out of range

    • Returns the index that id maps to, or -1 if id is not mapped.

      In a partition, it is the group of id.

      Time: O(1).

      Parameters

      • id: number

        index in 0..indexCount-1

      Returns number

      index that id maps to, or -1

      RangeError if id is out of range

    • Returns whether id is mapped. Equivalent to get(id) !== -1.

      Time: O(1).

      Parameters

      • id: number

        index in 0..indexCount-1

      Returns boolean

      true if id is mapped

      RangeError if id is out of range

    • Returns the nodes in group groupId, in ascending order. Equivalent to indicesOf(groupId).

      The result is a view of this partition's own array, not a copy.

      Time: O(1).

      Parameters

      • groupId: number

        group ID in 0..groupCount-1

      Returns SortedIntView

      nodes in the group

      RangeError if groupId is out of range

    • Returns one value per group, combined from the values of its indices. The result is a typed array of the type of values (Java: the int[] and double[] forms; here any typed array of numbers).

      For each group, starts from identity and combines the result so far with the value of each index in the group, in ascending order of the indices. A group without indices gets identity, and the values of indices in no group are left out. Each step is stored in the element type, so an Int32Array wraps at 32 bits like Java's int, and a Float64Array computes in double like Java. Here, byPackageCall groups the calls between the methods of a program by the call between packages that each belongs to (see EdgePartition), and the call sites in siteCount are summed per call between packages:

      const packageSiteCount = byPackageCall.reduce(
      siteCount,
      0,
      (sum, count) => sum + count,
      );
      // 2 for app -> ui, app -> service, service -> model and service -> storage,
      // 1 for app -> cli and ui -> model

      Time: O(indexCount + groupCount). Memory: one element per group for the result: 4 x groupCount bytes for an Int32Array, 8 x groupCount bytes for a Float64Array.

      Type Parameters

      • A extends
            | Int8Array<ArrayBufferLike>
            | Uint8Array<ArrayBufferLike>
            | Uint8ClampedArray<ArrayBufferLike>
            | Int16Array<ArrayBufferLike>
            | Uint16Array<ArrayBufferLike>
            | Int32Array<ArrayBufferLike>
            | Uint32Array<ArrayBufferLike>
            | Float32Array<ArrayBufferLike>
            | Float64Array<ArrayBufferLike>

      Parameters

      • values: A

        the value of each index; length IndexMapping.indexCount

      • identity: number

        the start value of each group

      • combine: (accumulated: number, value: number) => number

        called with the result so far and the value of the next index, returns the two combined

      Returns A

      one value per group, by group ID

      Error if values.length !== indexCount

    • Returns one value per group, combined from the values of its indices, as the Int32Array form does. Each step is stored in a BigInt64Array, so it wraps at 64 bits like Java's long.

      Time: O(indexCount + groupCount). Memory: 8 x groupCount bytes for the result.

      Parameters

      • values: BigInt64Array

        the value of each index; length IndexMapping.indexCount

      • identity: bigint

        the start value of each group

      • combine: (accumulated: bigint, value: bigint) => bigint

        called with the result so far and the value of the next index, returns the two combined

      Returns BigInt64Array

      one value per group, by group ID

      Error if values.length !== indexCount

    • Returns one value per group, combined from the values of its indices, as the BigInt64Array form does. This is the form for unsigned 64-bit values. It is not in Java, which has no unsigned long.

      Time: O(indexCount + groupCount). Memory: 8 x groupCount bytes for the result.

      Parameters

      • values: BigUint64Array
      • identity: bigint
      • combine: (accumulated: bigint, value: bigint) => bigint

      Returns BigUint64Array

      Error if values.length !== indexCount

    • Writes one value per group into groupValues, combined from the values of the indices of that group. This is the form of reduce for values of any kind (Java: the T[] form). The second argument selects this form, as in Java's overload resolution: the values may be in any array-like, also in a typed array.

      For each group, starts from the value of its first index and combines the result so far with the value of each further index, in ascending order of the indices. A group without indices keeps its entry in groupValues, and the values of indices in no group are left out.

      Time: O(indexCount + groupCount).

      Type Parameters

      • T

      Parameters

      • values: ArrayLike<T>

        the value of each index; length IndexMapping.indexCount

      • groupValues: T[]

        receives one value per group, by group ID; length IndexPartition.groupCount, and not the same array as values

      • combine: (accumulated: T, value: T) => T

        called with the result so far and the value of the next index, returns the two combined

      Returns void

      Error if values.length !== indexCount, groupValues.length !== groupCount, or both are the same array

    • Returns the SCC ID of node. Equivalent to get(node).

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      SCC ID

      RangeError if node is out of range

    • Returns the number of indices in group groupId.

      Time: O(1).

      Parameters

      • groupId: number

        group ID in 0..groupCount-1

      Returns number

      size of the group

      RangeError if groupId is out of range

    • Returns a partition of the nodes of graph into groups of the caller's choice.

      groupOf[node] is the group of each node, in 0..groupCount-1, or -1 for a node in no group; the array is copied. A group may have no nodes: it becomes a node without edges in NodePartition.condense, so that group IDs from a numbering of the caller stay valid. Here, packageOf holds the package of each method of calls as a node ID of the package graph dependencies, and the condensed graph shows which packages call which:

      const byPackage = NodePartition.of(calls, packageOf, dependencies.nodeCount);
      const packageCalls = byPackage.condense();
      // packageCalls: app -> [cli, ui, service], ui -> [model], service -> [model, storage]

      Time: O(nodeCount + groupCount). Memory: 4 x (nodeCount + mappedCount + groupCount) bytes for the result.

      Parameters

      • graph: Graph

        the graph whose nodes are partitioned

      • groupOf: ArrayLike<number>

        the group of each node, or -1; length graph.nodeCount; any array of numbers

      • groupCount: number

        the number of groups, at most as many as a graph can have nodes

      Returns NodePartition

      the partition

      RangeError if a group is not in -1..groupCount-1, which includes one that is not an integer

      Error if groupOf.length !== graph.nodeCount, or groupCount is not an integer, is negative or larger than a graph can have nodes