import flatten_default from "../../../../lodash-es/flatten.js";
import forEach_default from "../../../../lodash-es/forEach.js";
import map_default from "../../../../lodash-es/map.js";
import sortBy_default from "../../../../lodash-es/sortBy.js";
import zipObject_default from "../../../../lodash-es/zipObject.js";
function crossCount(e, n) {
	for (var r = 0, i = 1; i < n.length; ++i) r += twoLayerCrossCount(e, n[i - 1], n[i]);
	return r;
}
function twoLayerCrossCount(a, o, s) {
	for (var c = zipObject_default(s, map_default(s, function(e, n) {
		return n;
	})), l = flatten_default(map_default(o, function(e) {
		return sortBy_default(map_default(a.outEdges(e), function(e) {
			return {
				pos: c[e.w],
				weight: a.edge(e).weight
			};
		}), "pos");
	})), u = 1; u < s.length;) u <<= 1;
	var d = 2 * u - 1;
	--u;
	var f = map_default(Array(d), function() {
		return 0;
	}), p = 0;
	return forEach_default(l.forEach(function(e) {
		var n = e.pos + u;
		f[n] += e.weight;
		for (var r = 0; n > 0;) n % 2 && (r += f[n + 1]), n = n - 1 >> 1, f[n] += e.weight;
		p += e.weight * r;
	})), p;
}
export { crossCount };
