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
merged 1 commit into from Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/index.js
Expand Up @@ -171,12 +171,12 @@ internals.Topo.prototype._sort = function () {
const visited = {};
const sorted = [];

for (let i = 0; i < this._items.length; ++i) {
for (let i = 0; i < this._items.length; ++i) { // Really looping thru item.seq values out of order
let next = i;

if (ancestors[i]) {
next = null;
for (let j = 0; j < this._items.length; ++j) {
for (let j = 0; j < this._items.length; ++j) { // As above, these are item.seq values
if (visited[j] === true) {
continue;
}
Expand All @@ -188,7 +188,7 @@ internals.Topo.prototype._sort = function () {
const shouldSeeCount = ancestors[j].length;
let seenCount = 0;
for (let k = 0; k < shouldSeeCount; ++k) {
if (sorted.indexOf(ancestors[j][k]) >= 0) {
if (visited[ancestors[j][k]]) {
++seenCount;
}
}
Expand All @@ -201,7 +201,6 @@ internals.Topo.prototype._sort = function () {
}

if (next !== null) {
next = next.toString(); // Normalize to string TODO: replace with seq
visited[next] = true;
sorted.push(next);
}
Expand Down