Graphity for TypeScript 3.0.0
    Preparing search index...

    Variable CsrConst

    Csr: {
        inAdjacency(graph: BiAdjacentGraph): Int32Array;
        inAdjacencyStart(graph: BiAdjacentGraph): Int32Array;
        outAdjacency(graph: Graph): Int32Array;
        outAdjacencyStart(graph: Graph): Int32Array;
    } = ...

    Access to the arrays in which a graph keeps its edges, for algorithm code that loops over all edges. These arrays are called the CSR (compressed sparse row) layout of the graph.

    Each method returns the graph's own array, not a copy. The out-nodes of node v are outAdjacency[outAdjacencyStart[v]..outAdjacencyStart[v + 1] - 1], in ascending order, and the position of an out-node in outAdjacency is the edge index of its edge. outAdjacencyStart has nodeCount + 1 values, from 0 to edgeCount. A loop loads the two arrays into local variables once and reads them without a method call or an argument check per edge. Here, calls holds the calls between the methods of a program, and the loop counts the callers of each method:

    const start = Csr.outAdjacencyStart(calls);
    const callees = Csr.outAdjacency(calls);
    const callerCount = new Int32Array(calls.nodeCount);
    for (let method = 0; method < calls.nodeCount; method++) {
    for (let edge = start[method], end = start[method + 1]; edge < end; edge++) {
    callerCount[callees[edge]]++;
    }
    }
    // callerCount: 3 for format, 2 for parse, 0 for main, 1 for every other method

    A BiAdjacentGraph also holds the in-nodes of every node, called its in-adjacency. The in-adjacency has the same layout, in Csr.inAdjacencyStart and Csr.inAdjacency. A position in inAdjacency is not an edge index of the graph, though, but of its transposed graph; Graphs.transposedEdgeMapping translates all of them in one pass.

    The arrays must not be modified. Nothing prevents a write, but it changes the graph for everyone who holds it and breaks what every algorithm relies on: that the graph is immutable, and that the out-nodes of each node are sorted. The algorithms of this library read the arrays the same way. Code that reads the out-nodes of a few nodes is better served by Graph.outNodes and the edge index methods of Graph, which check their arguments.

    Type Declaration

    • inAdjacency: function
      • Returns the in-nodes of all nodes, node after node.

        A position in this array is the edge index of the edge in the transposed graph, not in graph.

        Time: O(1).

        Parameters

        Returns Int32Array

        the graph's own array, of length edgeCount; not to be modified

    • inAdjacencyStart: function
    • outAdjacency: function
      • Returns the out-nodes of all nodes, node after node, at the positions of their edge indices.

        Time: O(1).

        Parameters

        Returns Int32Array

        the graph's own array, of length edgeCount; not to be modified

    • outAdjacencyStart: function
      • Returns where the out-nodes of each node start in Csr.outAdjacency, followed by edgeCount.

        Time: O(1).

        Parameters

        Returns Int32Array

        the graph's own array, of length nodeCount + 1; not to be modified