import forEach_default from "../../../lodash-es/forEach.js";
function parentDummyChains(t) {
	var i = postorder(t);
	forEach_default(t.graph().dummyChains, function(e) {
		for (var r = t.node(e), a = r.edgeObj, o = findPath(t, i, a.v, a.w), s = o.path, c = o.lca, l = 0, u = s[l], d = !0; e !== a.w;) {
			if (r = t.node(e), d) {
				for (; (u = s[l]) !== c && t.node(u).maxRank < r.rank;) l++;
				u === c && (d = !1);
			}
			if (!d) {
				for (; l < s.length - 1 && t.node(u = s[l + 1]).minRank <= r.rank;) l++;
				u = s[l];
			}
			t.setParent(e, u), e = t.successors(e)[0];
		}
	});
}
function findPath(e, t, n, r) {
	var i = [], a = [], o = Math.min(t[n].low, t[r].low), s = Math.max(t[n].lim, t[r].lim), c = n, l;
	do
		c = e.parent(c), i.push(c);
	while (c && (t[c].low > o || s > t[c].lim));
	for (l = c, c = r; (c = e.parent(c)) !== l;) a.push(c);
	return {
		path: i.concat(a.reverse()),
		lca: l
	};
}
function postorder(t) {
	var n = {}, r = 0;
	function i(a) {
		var o = r;
		forEach_default(t.children(a), i), n[a] = {
			low: o,
			lim: r++
		};
	}
	return forEach_default(t.children(), i), n;
}
export { parentDummyChains };
