Skip to content

Commit

Permalink
Merge pull request #410 from RohitPaul0007/patch-53
Browse files Browse the repository at this point in the history
Update cross-count.js
  • Loading branch information
rustedgrail authored Sep 11, 2023
2 parents b58e54c + 8c3bd02 commit 25b481f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/order/cross-count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var zipObject = require("../util").zipObject;
let zipObject = require("../util").zipObject;

module.exports = crossCount;

Expand All @@ -21,8 +21,8 @@ module.exports = crossCount;
* This algorithm is derived from Barth, et al., "Bilayer Cross Counting."
*/
function crossCount(g, layering) {
var cc = 0;
for (var i = 1; i < layering.length; ++i) {
let cc = 0;
for (let i = 1; i < layering.length; ++i) {
cc += twoLayerCrossCount(g, layering[i-1], layering[i]);
}
return cc;
Expand All @@ -32,26 +32,26 @@ function twoLayerCrossCount(g, northLayer, southLayer) {
// Sort all of the edges between the north and south layers by their position
// in the north layer and then the south. Map these edges to the position of
// their head in the south layer.
var southPos = zipObject(southLayer, southLayer.map((v, i) => i));
var southEntries = northLayer.flatMap(v => {
let southPos = zipObject(southLayer, southLayer.map((v, i) => i));
let southEntries = northLayer.flatMap(v => {
return g.outEdges(v).map(e => {
return { pos: southPos[e.w], weight: g.edge(e).weight };
}).sort((a, b) => a.pos - b.pos);
});

// Build the accumulator tree
var firstIndex = 1;
let firstIndex = 1;
while (firstIndex < southLayer.length) firstIndex <<= 1;
var treeSize = 2 * firstIndex - 1;
let treeSize = 2 * firstIndex - 1;
firstIndex -= 1;
var tree = new Array(treeSize).fill(0);
let tree = new Array(treeSize).fill(0);

// Calculate the weighted crossings
var cc = 0;
let cc = 0;
southEntries.forEach(entry => {
var index = entry.pos + firstIndex;
let index = entry.pos + firstIndex;
tree[index] += entry.weight;
var weightSum = 0;
let weightSum = 0;
while (index > 0) {
if (index % 2) {
weightSum += tree[index + 1];
Expand Down

0 comments on commit 25b481f

Please sign in to comment.