Skip to content

Conversation

@krm35
Copy link
Contributor

@krm35 krm35 commented Aug 3, 2023

Better to check if the link really exists before deletion otherwise it can create unwanted links at the end

Copy link
Member

@curran curran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! I have a few suggestions here.

src/index.ts Outdated
removeEdge(path[0], path[1]);
removeEdge(path[1], path[0]);
removedEdges.push([path[0], path[1]]);
[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code creates many new arrays and one new closure each time it runs, which could degrade performance as all of those things need to be garbage collected.

I would suggest the following refactoring:

    const u = path[0];
    const v = path[1];

    if (hasEdge(u, v)) {
        removedEdges.push({ u, v, weight: getEdgeWeight(u, v) });
        removeEdge(u, v);
    }

    if (hasEdge(v, u)) {
        removedEdges.push({ u: v, v: u, weight: getEdgeWeight(v, u) });
        removeEdge(v, u);
    }

return d === item;
}).length > 0
);
return arr.includes(item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

src/index.ts Outdated
let path = shortestPath(source, destination);
const paths = [path],
removedEdges = [],
removedEdges: any = [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet it's possible to add proper types here.

Copy link
Member

@curran curran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you.

@curran curran merged commit 4610bed into datavis-tech:master Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants