Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / hasCycle

Function: hasCycle()

hasCycle(nodes, edges, edge?): boolean

Defined in: packages/chaingraph-types/src/flow/cycleDetection.ts:29

Detect if a given flow has a cycle between its nodes.

This function implements Kahn's topological sorting to detect a cycle in a directed graph.

Parameters

nodes

Iterable<INode>

the set of flow's nodes.

edges

Iterable<Edge>

the set of flow's edges.

edge?

Edge

if present, assume this edge is in the flow, without adding it to avoid side effects.

Returns

boolean

Licensed under BUSL-1.1