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

Added read path information to read info dialog #382

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

ducku
Copy link
Collaborator

@ducku ducku commented Jan 8, 2024

Closes #363

Copy link
Member

@adamnovak adamnovak left a comment

Choose a reason for hiding this comment

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

This looks like it should work, but I think the logic to build the string has a bigger O() runtime than is really justifiable.


for (const nodeID of track.sequence) {
// Node is approached backwards if "-" is present
if (Array.from(nodeID)[0] === "-") {
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a weird way to see if the string starts with "-", even though it looks like StackOverflow recommends it, since this looks to convert the whole string to an array just to check the first character. I would probably try the startsWith method instead.

Suggested change
if (Array.from(nodeID)[0] === "-") {
if (nodeID.startsWith("-")) {

Comment on lines 3932 to 3934
result = result.concat("<", nodeID.substring(1));
} else {
result = result.concat(">", nodeID);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it is going to be an O(n^2) algorithm when it doesn't need to be. Building the new version of result is going to copy the original contents of result into a new string that also has the </> character and the node ID. But that copy takes some unit of time for each character in result, and as you make result longer the number of characters to be copied increases at each step.

You probably want to build an array of all the pieces you want in the final string, by mutably appending to the array with push() (which doesn't take longer to do as the array gets longer). Then you can use .join("") on the array to turn it into a combined string all at once, in linear time.

Copy link
Member

@adamnovak adamnovak left a comment

Choose a reason for hiding this comment

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

This looks good to me, and I manually tested it.

If redundant nodes are off, we get the path through the modified graph and not the original graph before the node compression. I'm not entirely sure which way is better, so I guess we can ship this and change it if we decide the other way is actually better.

@adamnovak adamnovak merged commit 6675f7b into vgteam:master Jan 10, 2024
1 check passed
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.

Add read path information to read info dialog
2 participants