check_graph_for_cycles.js — svelte Source File
Architecture documentation for check_graph_for_cycles.js, a javascript file in the svelte codebase. 0 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR 0033223e_723b_4eb4_cdb3_607c6df9a36c["check_graph_for_cycles.js"] 4aa8a188_84d4_0274_ed83_cac0ab1d3572["index.js"] 4aa8a188_84d4_0274_ed83_cac0ab1d3572 --> 0033223e_723b_4eb4_cdb3_607c6df9a36c f3fad5a9_6b91_ed4f_9331_7f9fc18491c3["utils.js"] f3fad5a9_6b91_ed4f_9331_7f9fc18491c3 --> 0033223e_723b_4eb4_cdb3_607c6df9a36c style 0033223e_723b_4eb4_cdb3_607c6df9a36c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* @template T
* @param {Array<[T, T]>} edges
* @returns {Array<T>|undefined}
*/
export default function check_graph_for_cycles(edges) {
/** @type {Map<T, T[]>} */
const graph = edges.reduce((g, edge) => {
const [u, v] = edge;
if (!g.has(u)) g.set(u, []);
if (!g.has(v)) g.set(v, []);
g.get(u).push(v);
return g;
}, new Map());
const visited = new Set();
/** @type {Set<T>} */
const on_stack = new Set();
/** @type {Array<Array<T>>} */
const cycles = [];
/**
* @param {T} v
*/
function visit(v) {
visited.add(v);
on_stack.add(v);
graph.get(v)?.forEach((w) => {
if (!visited.has(w)) {
visit(w);
} else if (on_stack.has(w)) {
cycles.push([...on_stack, w]);
}
});
on_stack.delete(v);
}
graph.forEach((_, v) => {
if (!visited.has(v)) {
visit(v);
}
});
return cycles[0];
}
Domain
Subdomains
Functions
Imported By
Source
Frequently Asked Questions
What does check_graph_for_cycles.js do?
check_graph_for_cycles.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in check_graph_for_cycles.js?
check_graph_for_cycles.js defines 1 function(s): check_graph_for_cycles.
What files import check_graph_for_cycles.js?
check_graph_for_cycles.js is imported by 2 file(s): index.js, utils.js.
Where is check_graph_for_cycles.js in the architecture?
check_graph_for_cycles.js is located at packages/svelte/src/compiler/phases/2-analyze/utils/check_graph_for_cycles.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/2-analyze/utils).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free