Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parent-dummy-chains.js #379

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lib/parent-dummy-chains.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module.exports = parentDummyChains;

function parentDummyChains(g) {
var postorderNums = postorder(g);
let postorderNums = postorder(g);

g.graph().dummyChains.forEach(v => {
var node = g.node(v);
var edgeObj = node.edgeObj;
var pathData = findPath(g, postorderNums, edgeObj.v, edgeObj.w);
var path = pathData.path;
var lca = pathData.lca;
var pathIdx = 0;
var pathV = path[pathIdx];
var ascending = true;
let node = g.node(v);
let edgeObj = node.edgeObj;
let pathData = findPath(g, postorderNums, edgeObj.v, edgeObj.w);
let path = pathData.path;
let lca = pathData.lca;
let pathIdx = 0;
let pathV = path[pathIdx];
let ascending = true;

while (v !== edgeObj.w) {
node = g.node(v);
Expand Down Expand Up @@ -44,12 +44,12 @@ function parentDummyChains(g) {
// Find a path from v to w through the lowest common ancestor (LCA). Return the
// full path and the LCA.
function findPath(g, postorderNums, v, w) {
var vPath = [];
var wPath = [];
var low = Math.min(postorderNums[v].low, postorderNums[w].low);
var lim = Math.max(postorderNums[v].lim, postorderNums[w].lim);
var parent;
var lca;
let vPath = [];
let wPath = [];
let low = Math.min(postorderNums[v].low, postorderNums[w].low);
let lim = Math.max(postorderNums[v].lim, postorderNums[w].lim);
let parent;
let lca;

// Traverse up from v to find the LCA
parent = v;
Expand All @@ -70,11 +70,11 @@ function findPath(g, postorderNums, v, w) {
}

function postorder(g) {
var result = {};
var lim = 0;
let result = {};
let lim = 0;

function dfs(v) {
var low = lim;
let low = lim;
g.children(v).forEach(dfs);
result[v] = { low: low, lim: lim++ };
}
Expand Down
Loading