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.
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-dotand@kobayami/graphity-mermaidbuild on it and are released with it at the same version. A Graph has the nodes0..nodeCount-1and 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:Graphs
Components and connectivity
Orders, cycles and traversals
Reachability and distances
Trees and dominators
Loops, dominance frontiers, control dependence and the placement of phi-nodes are in the package
@kobayami/graphity-controlflow. The package@kobayami/graphity-mermaidwrites a graph as a Mermaid flowchart, and@kobayami/graphity-dotwrites it as text in DOT (the language of Graphviz).Derived graphs and the data on them
Errors
The errors keep Java's distinction and Java's messages: a
RangeErrorwhere Java throws anIndexOutOfBoundsException, a plainErrorwhere it throws anIllegalArgumentException, anIllegalStateException, aNoSuchElementExceptionor anIOException. 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.