function detectCycles(nodes, links, flatlinks = true) {
let cycles = [];
nodes.forEach(function (n) {
let cycle = findCycle(nodes[n.id], links, flatlinks);
if (cycle != null) {
cycle.forEach(function (c) {
let node = (flatlinks) ? nodes[c.node] : nodes[c.node.id];
node.alloc = true;
const item = c.item;
node.item = item;
const next = c.li;
cycles.push({ node, item, next });
});
};
});
return cycles;
}