mirror-rhinstaller-node-cache/@rtsao/scc
2026-07-21 07:25:14 +00:00
..
index.d.ts dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00
index.js dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00
index.js.flow dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00
LICENSE dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00
package.json dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00
README.md dc62fd92941924495660734286311a3d44d6e15c919694aab2b00ce84bf0c990 package.json 2026-07-21 07:25:14 +00:00

@rtsao/scc

Find strongly connected components of a directed graph using Tarjan's algorithm.

This algorithm efficiently yields both a topological order and list of any cycles.

Installation

yarn add @rtsao/scc
npm install @rtsao/scc

Usage

const scc = require("@rtsao/scc");

const digraph = new Map([
  ["a", new Set(["c", "d"])],
  ["b", new Set(["a"])],
  ["c", new Set(["b"])],
  ["d", new Set(["e"])],
  ["e", new Set()]
]);

const components = scc(digraph);
// [ Set { 'e' }, Set { 'd' }, Set { 'b', 'c', 'a' } ]

Illustration of example input digraph

┌───┐     ┌───┐
│ d │ ◀── │ a │ ◀┐
└───┘     └───┘  │
  │         │    │
  ▼         ▼    │
┌───┐     ┌───┐  │
│ e │     │ c │  │
└───┘     └───┘  │
            │    │
            ▼    │
          ┌───┐  │
          │ b │ ─┘
          └───┘