Graphity for TypeScript 3.0.0
    Preparing search index...

    Module @kobayami/graphity-core

    Directed graphs and their analysis, for tools that see a program as graphs: components, orders and cycles, reachability, trees and dominators, and graphs derived from other graphs.

    This package is the counterpart of the Java module graphity-core; the packages @kobayami/graphity-controlflow, @kobayami/graphity-dot and @kobayami/graphity-mermaid build on it and are released with it at the same version. A Graph has the nodes 0..nodeCount-1 and holds nothing but its edges, in 4 bytes per node and per edge; names and other data on nodes and edges stay in arrays of the caller, indexed by node ID or edge index. GraphBuilder builds a graph from a model of the caller, and the algorithms take the graph and return immutable results. None of them recurses, so a deep graph does not overflow the call stack. Here, the packages of a small program and the packages each of them uses become a graph, which has a cycle:

    // The packages are the nodes 0..7, and uses[p] lists the packages that package p uses.
    const names = ["app", "cli", "ui", "service", "model", "storage", "json", "util"];
    const uses = [[1, 2, 3], [7], [3, 4, 7], [4, 5], [5], [4, 6, 7], [7], []];

    // Build the graph: an edge p -> q for every package q that p uses.
    const builder = new GraphBuilder();
    builder.addNodes(uses.length);
    for (let pkg = 0; pkg < uses.length; pkg++) {
    builder.addOutEdges(pkg, uses[pkg]);
    }
    const dependencies = builder.build();

    // Find a cycle.
    const cycle = Graphs.findCycle(dependencies);
    // cycle: [4, 5] - model and storage use each other
    • Graph - a directed graph with the out-nodes of every node; BiAdjacentGraph - one that also holds the in-nodes, for the algorithms that follow edges against their direction. It gives the transposed graph as well.
    • GraphBuilder - builds a graph from edges in any order; Graph.of takes the arrays of its CSR (compressed sparse row) layout, which Csr hands to algorithm code of your own.
    • Graph.writeTo and Graph.readFrom - store a graph and load it again.
    • SortedIntView - the sorted list of node IDs or edge indices that lookups such as Graph.outNodes return; Edges - a list of edges, each with its source, target and edge index.
    • Graphs.adjacencyListOf, Graphs.topologyHash and Graphs.diff - a whole graph as text, a hash to keep, and the edges added and removed between two versions of a graph.

    Loops, dominance frontiers, control dependence and the placement of phi-nodes are in the package @kobayami/graphity-controlflow. The package @kobayami/graphity-mermaid writes a graph as a Mermaid flowchart, and @kobayami/graphity-dot writes it as text in DOT (the language of Graphviz).

    The errors keep Java's distinction and Java's messages: a RangeError where Java throws an IndexOutOfBoundsException, a plain Error where it throws an IllegalArgumentException, an IllegalStateException, a NoSuchElementException or an IOException. A number that is not an integer in the 32-bit range, where the library expects a node ID, an index or a count, fails the range check of its parameter.

    @kobayami/graphity-core

    This package is the core of Graphity: the graph, the builder, and every algorithm that applies to any directed graph. The algorithms compute, for example, strongly and weakly connected components, bridges and articulation points, topological order and levels, cycles and edge classification, breadth-first distances and reachability, lowest common ancestors, dominators and condensed graphs. The graph is compact and immutable, in a compressed sparse row (CSR) layout of 4 bytes per node and per edge.

    It is a package of Graphity for TypeScript, which is the TypeScript implementation of the Java library Graphity. Its counterpart in Java is the module graphity-core. The README of the repository shows how to use it and how its API relates to Java's.

    npm install @kobayami/graphity-core
    

    Licensed under the Apache License 2.0; see the files LICENSE and NOTICE in the package.

    Ancestry
    BfsDistances
    BiAdjacentGraph
    Biconnectivity
    BitSet
    DfsEdgeTraverser
    DfsTraverser
    Dominators
    EdgeMapping
    EdgePartition
    Edges
    EdgeTypes
    FrontierTraverser
    Graph
    GraphBuilder
    GraphDiff
    IndexMapping
    IndexPartition
    NodeMapping
    NodePartition
    PreorderAncestry
    Sccs
    SortedIntView
    StrongConnectivity
    TopOrderAndLevels
    ByteSink
    EdgeAction
    EdgeConsumer
    EdgeType
    IntList
    TargetState
    TypedArray
    BackEdges
    Components
    Csr
    EdgeAction
    EdgeType
    Graphs
    IntLists
    TargetState
    TopOrder