-
Notifications
You must be signed in to change notification settings - Fork 26
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
Added read path information to read info dialog #382
Conversation
There was a problem hiding this 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.
src/util/tubemap.js
Outdated
|
||
for (const nodeID of track.sequence) { | ||
// Node is approached backwards if "-" is present | ||
if (Array.from(nodeID)[0] === "-") { |
There was a problem hiding this comment.
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.
if (Array.from(nodeID)[0] === "-") { | |
if (nodeID.startsWith("-")) { |
src/util/tubemap.js
Outdated
result = result.concat("<", nodeID.substring(1)); | ||
} else { | ||
result = result.concat(">", nodeID); |
There was a problem hiding this 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 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.
There was a problem hiding this 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.
Closes #363