Skip to content

Instantly share code, notes, and snippets.

@linusnorton
Last active June 25, 2020 07:02
Show Gist options
  • Save linusnorton/f3280c42a84283b5edc6c6a1fc3ad58b to your computer and use it in GitHub Desktop.
Save linusnorton/f3280c42a84283b5edc6c6a1fc3ad58b to your computer and use it in GitHub Desktop.
/**
* Return an index of connections that achieve the earliest arrival time at each stop.
*/
function scan(origin: StopID, destination: Stop, date: number, dow: DayOfWeek, departureTime: number): ConnectionIndex {
// set the arrival time at the origin so we have a basis for what is reachable
const earliestArrivals = { [origin]: departureTime };
const bestConnections = {};
const results = { earliestArrivals, bestConnections };
scanTransfers(results, origin);
for (const c of this.connections) {
if (isReachable(results, c) && isBetter(results, c)) {
results.earliestArrivals[c.destination] = c.arrivalTime;
results.bestConnections[c.destination] = c;
}
}
return results.bestConnections;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment