Navigator Prefabricating Marinates
Miss any of our Open RFC calls?Watch the recordings here! »

cycle-test

1.0.0 • Public • Published

cycle-test

cycle-test detects cycles in your directed graph by returning true or false.

Status:

Version: 1.0.0

This is beta software.

Installation:

npm install cycle-test

Use:

Each value of the input array represents a vertex identified by its array index. Each vertex must be undefined (ignored) or an array of zero or more integers, each representing an edge to another vertex.

ct = require('cycle-test');

graph = [[1], [2], [0]];
console.log(ct.hasCycle(graph));
// true

graph = [[1, 2], [2], []];
console.log(ct.hasCycle(graph));
// false

graph = [[0]];
console.log(ct.hasCycle(graph));
// true

graph = [[1], [3], , [0]];
console.log(ct.hasCycle(graph));
// true

Explanation:

For an explanation of the algorithm, see the following stackoverflow comment and GeeksforGeeks article.

Authors:

Andrew Engelbrecht (lead developer and maintainer)

License:

cycle-test is realeased under CC0. (CC0 License)

Install

npm i cycle-test

DownloadsWeekly Downloads

0

Version

1.0.0

License

CC0-1.0

Last publish

Collaborators

  • avatar