Skip to content

Commit

Permalink
Bugfix in priority queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Colpaert committed Jan 18, 2016
1 parent c9d3fb6 commit ad5c1b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/BasicCSA.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var ResultStream = function (query) { //TODO: , footpathsTo) {
this._earliestArrivalTimes = {};
// Priority queue of pending earliest arrival times
this._pending = new PriorityQueue({ comparator: function(connectionA, connectionB) {
return connectionB.arrivalTime.getTime() - connectionA.arrivalTime.getTime();
return connectionA.arrivalTime - connectionB.arrivalTime;
}});

//check the fields of the query object and assign them to the object. Validate them against possible errors
Expand Down Expand Up @@ -76,6 +76,7 @@ ResultStream.prototype._transform = function (connection, encoding, done) {
// When a connection is found whose departure time exceeds the target stop's earliest arrival time, we have found a result
if (!this._hasEmitted && this._earliestArrivalTimes[this._arrivalStop] && connection.departureTime > this._earliestArrivalTimes[this._arrivalStop].arrivalTime) {
this.emit("result", this._reconstructRoute());
this._hasEmitted = true;
}

if (this._earliestArrivalTimes[departureStop] && this._earliestArrivalTimes[departureStop].arrivalTime <= connection.departureTime) {
Expand Down Expand Up @@ -124,6 +125,7 @@ ResultStream.prototype._flush = function (done) {
// If there was no connection with departure time exceeding earliest arrival time
if (!this._hasEmitted && this._earliestArrivalTimes[this._arrivalStop]) {
this.emit("result", this._reconstructRoute());
this._hasEmitted = true;
}
done();
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "csa",
"version": "0.0.9",
"version": "0.0.10",
"description": "Route Planner on top of data published using Connections",
"main": "lib/csa.js",
"keywords": [
Expand Down

0 comments on commit ad5c1b9

Please sign in to comment.