Last active
June 25, 2020 07:02
-
-
Save linusnorton/f3280c42a84283b5edc6c6a1fc3ad58b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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