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

Cleanup sort routine, clarify usage of seq vs index #26

merged 1 commit into from Nov 29, 2016


Copy link

devinivy commented Nov 29, 2016

There's been a long-standing TODO in topo (pre-dating my involvement) that I think is finally resolved. Beyond that there is some minor code cleanup in the sort routine. Two things to cover,

  1. I use a visited dictionary lookup rather than sorted.indexOf() to check for visited nodes. This is preferable because it's quicker/cleaner and because it allows us to get rid of the confusing next = next.toString() line. That line existed to account for the ancestors values being item.seq values (numbers) that were taken from Object.keys() (so actually, numbers coerced into to strings). Now we simply continue to deal with object keys, where the string conversion occurs implicitly.

  2. I added some comments to the main topo-sort loops, clarifying that looping over the item indices is the same as looping over the item.seq values, just "out of order." The item.seq values are always assigned as the current length of the items list, so there's a one-to-one correspondence between item.seq values and item list indices. I believe this clarification is good enough to nix the TODO in the codebase.

Since TODOs are not allowed by the hapi style guide, let's simply create an issue if this does not in fact resolve the pre-existing TODO.

@hueniverse I put this up as a PR in case you might have time to take a peek, given that it deals with a fairly nuanced area of topo and because you added the original TODO.

@hueniverse hueniverse self-assigned this Nov 29, 2016
@hueniverse hueniverse added the feature label Nov 29, 2016
@hueniverse hueniverse merged commit 80ce6ca into master Nov 29, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed
@hueniverse hueniverse added this to the 2.0.3 milestone Nov 29, 2016
@hueniverse hueniverse deleted the sort-cleanup branch Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.