minotor 7.0.0 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,6 @@
1
- # [7.0.0](https://github.com/aubryio/minotor/compare/v6.0.0...v7.0.0) (2025-09-19)
1
+ ## [7.0.2](https://github.com/aubryio/minotor/compare/v7.0.1...v7.0.2) (2025-09-23)
2
2
 
3
3
 
4
4
  ### Performance Improvements
5
5
 
6
- * optimize loops on the critical path ([#26](https://github.com/aubryio/minotor/issues/26)) ([8504930](https://github.com/aubryio/minotor/commit/85049308f7bbcf4d88f3dcfb47edd2511e9da80d))
7
-
8
-
9
- ### BREAKING CHANGES
10
-
11
- * Timetable binary format was updated and is not compatible with the old one.
6
+ * minor perf improvements ([#28](https://github.com/aubryio/minotor/issues/28)) ([8bd3150](https://github.com/aubryio/minotor/commit/8bd3150669c6d7abee2f2c5759fb0946f3cb509f))
package/dist/cli.mjs CHANGED
@@ -30,18 +30,6 @@ PERFORMANCE OF THIS SOFTWARE.
30
30
  /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
31
31
 
32
32
 
33
- function __rest(s, e) {
34
- var t = {};
35
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
36
- t[p] = s[p];
37
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
38
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
39
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
40
- t[p[i]] = s[p[i]];
41
- }
42
- return t;
43
- }
44
-
45
33
  function __awaiter(thisArg, _arguments, P, generator) {
46
34
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
47
35
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -17094,9 +17082,16 @@ class Time {
17094
17082
  if (times.length === 0) {
17095
17083
  throw new Error('At least one Time instance is required.');
17096
17084
  }
17097
- return times.reduce((maxTime, currentTime) => {
17098
- return currentTime.isAfter(maxTime) ? currentTime : maxTime;
17099
- });
17085
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17086
+ let maxTime = times[0];
17087
+ for (let i = 1; i < times.length; i++) {
17088
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17089
+ if (times[i].minutesSinceMidnight > maxTime.minutesSinceMidnight) {
17090
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17091
+ maxTime = times[i];
17092
+ }
17093
+ }
17094
+ return maxTime;
17100
17095
  }
17101
17096
  /**
17102
17097
  * Computes the minimum Time instance among the provided Time instances.
@@ -17108,9 +17103,16 @@ class Time {
17108
17103
  if (times.length === 0) {
17109
17104
  throw new Error('At least one Time instance is required.');
17110
17105
  }
17111
- return times.reduce((minTime, currentTime) => {
17112
- return currentTime.isBefore(minTime) ? currentTime : minTime;
17113
- });
17106
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17107
+ let minTime = times[0];
17108
+ for (let i = 1; i < times.length; i++) {
17109
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17110
+ if (times[i].minutesSinceMidnight < minTime.minutesSinceMidnight) {
17111
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17112
+ minTime = times[i];
17113
+ }
17114
+ }
17115
+ return minTime;
17114
17116
  }
17115
17117
  /**
17116
17118
  * Determines if the current Time instance is after another Time instance.
@@ -17119,7 +17121,7 @@ class Time {
17119
17121
  * @returns True if the current Time instance is after the other Time instance, otherwise false.
17120
17122
  */
17121
17123
  isAfter(otherTime) {
17122
- return this.minutesSinceMidnight > otherTime.toMinutes();
17124
+ return this.minutesSinceMidnight > otherTime.minutesSinceMidnight;
17123
17125
  }
17124
17126
  /**
17125
17127
  * Determines if the current Time instance is before another Time instance.
@@ -17128,7 +17130,7 @@ class Time {
17128
17130
  * @returns True if the current Time instance is before the other Time instance, otherwise false.
17129
17131
  */
17130
17132
  isBefore(otherTime) {
17131
- return this.minutesSinceMidnight < otherTime.toMinutes();
17133
+ return this.minutesSinceMidnight < otherTime.minutesSinceMidnight;
17132
17134
  }
17133
17135
  /**
17134
17136
  * Determines if the current Time instance is equal to another Time instance.
@@ -17137,7 +17139,7 @@ class Time {
17137
17139
  * @returns True if the current Time instance is equal to the other Time instance, otherwise false.
17138
17140
  */
17139
17141
  equals(otherTime) {
17140
- return this.minutesSinceMidnight === otherTime.toMinutes();
17142
+ return this.minutesSinceMidnight === otherTime.minutesSinceMidnight;
17141
17143
  }
17142
17144
  }
17143
17145
 
@@ -17314,29 +17316,35 @@ let Route$1 = class Route {
17314
17316
  * @returns The index of the earliest trip meeting the criteria, or undefined if no such trip is found.
17315
17317
  */
17316
17318
  findEarliestTrip(stopId, after = Time.origin(), beforeTrip) {
17317
- const maxTripIndex = beforeTrip !== undefined
17318
- ? Math.min(beforeTrip - 1, this.nbTrips - 1)
17319
- : this.nbTrips - 1;
17320
- if (maxTripIndex < 0) {
17319
+ if (this.nbTrips <= 0)
17321
17320
  return undefined;
17322
- }
17323
- let earliestTripIndex;
17324
- let lowTrip = 0;
17325
- let highTrip = maxTripIndex;
17326
- while (lowTrip <= highTrip) {
17327
- const midTrip = Math.floor((lowTrip + highTrip) / 2);
17328
- const departure = this.departureFrom(stopId, midTrip);
17329
- const pickUpType = this.pickUpTypeFrom(stopId, midTrip);
17330
- if ((departure.isAfter(after) || departure.equals(after)) &&
17331
- pickUpType !== 'NOT_AVAILABLE') {
17332
- earliestTripIndex = midTrip;
17333
- highTrip = midTrip - 1;
17321
+ let hi = this.nbTrips - 1;
17322
+ if (beforeTrip !== undefined)
17323
+ hi = Math.min(hi, beforeTrip - 1);
17324
+ if (hi < 0)
17325
+ return undefined;
17326
+ let lo = 0;
17327
+ let lb = -1;
17328
+ while (lo <= hi) {
17329
+ const mid = (lo + hi) >>> 1;
17330
+ const depMid = this.departureFrom(stopId, mid);
17331
+ if (depMid.isBefore(after)) {
17332
+ lo = mid + 1;
17334
17333
  }
17335
17334
  else {
17336
- lowTrip = midTrip + 1;
17335
+ lb = mid;
17336
+ hi = mid - 1;
17337
17337
  }
17338
17338
  }
17339
- return earliestTripIndex;
17339
+ if (lb === -1)
17340
+ return undefined;
17341
+ for (let t = lb; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : this.nbTrips); t++) {
17342
+ const pickup = this.pickUpTypeFrom(stopId, t);
17343
+ if (pickup !== 'NOT_AVAILABLE') {
17344
+ return t;
17345
+ }
17346
+ }
17347
+ return undefined;
17340
17348
  }
17341
17349
  /**
17342
17350
  * Retrieves the index of a stop within the route.
@@ -17571,6 +17579,7 @@ const serializeRouteType = (type) => {
17571
17579
  }
17572
17580
  };
17573
17581
 
17582
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
17574
17583
  const ALL_TRANSPORT_MODES = new Set([
17575
17584
  'TRAM',
17576
17585
  'SUBWAY',
@@ -17675,9 +17684,7 @@ class Timetable {
17675
17684
  if (!serviceRoute) {
17676
17685
  throw new Error(`Service route not found for route ID: ${route.serviceRoute()}`);
17677
17686
  }
17678
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
17679
- const { routes } = serviceRoute, serviceRouteInfo = __rest(serviceRoute, ["routes"]);
17680
- return serviceRouteInfo;
17687
+ return { type: serviceRoute.type, name: serviceRoute.name };
17681
17688
  }
17682
17689
  /**
17683
17690
  * Finds all routes passing through a stop.
@@ -20801,7 +20808,7 @@ class Result {
20801
20808
 
20802
20809
  const UNREACHED = Time.infinity();
20803
20810
  /**
20804
- * A public transportation network router utilizing the RAPTOR algorithm for
20811
+ * A public transportation network router implementing the RAPTOR algorithm for
20805
20812
  * efficient journey planning and routing. For more information on the RAPTOR
20806
20813
  * algorithm, refer to its detailed explanation in the research paper:
20807
20814
  * https://www.microsoft.com/en-us/research/wp-content/uploads/2012/01/raptor_alenex.pdf
@@ -20933,6 +20940,7 @@ class Router {
20933
20940
  // together with corresponding hop on stop index (earliest marked stop)
20934
20941
  const reachableRoutes = this.timetable.findReachableRoutes(markedStops, options.transportModes);
20935
20942
  markedStops.clear();
20943
+ const earliestArrivalAtAnyDestination = this.earliestArrivalAtAnyStop(earliestArrivals, destinations);
20936
20944
  // for each route that can be reached with at least round - 1 trips
20937
20945
  const reachableRoutesArray = Array.from(reachableRoutes.entries());
20938
20946
  for (let i = 0; i < reachableRoutesArray.length; i++) {
@@ -20949,7 +20957,7 @@ class Router {
20949
20957
  const earliestArrivalAtCurrentStop = (_b = (_a = earliestArrivals.get(currentStop)) === null || _a === void 0 ? void 0 : _a.arrival) !== null && _b !== void 0 ? _b : UNREACHED;
20950
20958
  if (currentDropOffType !== 'NOT_AVAILABLE' &&
20951
20959
  currentArrivalTime.isBefore(earliestArrivalAtCurrentStop) &&
20952
- currentArrivalTime.isBefore(this.earliestArrivalAtAnyStop(earliestArrivals, destinations))) {
20960
+ currentArrivalTime.isBefore(earliestArrivalAtAnyDestination)) {
20953
20961
  const bestHopOnDepartureTime = route.departureFrom(currentTrip.bestHopOnStop, currentTrip.tripIndex);
20954
20962
  arrivalsAtCurrentRound.set(currentStop, {
20955
20963
  arrival: currentArrivalTime,
@@ -20976,8 +20984,8 @@ class Router {
20976
20984
  const earliestArrivalOnPreviousRound = (_c = arrivalsAtPreviousRound.get(currentStop)) === null || _c === void 0 ? void 0 : _c.arrival;
20977
20985
  if (earliestArrivalOnPreviousRound !== undefined &&
20978
20986
  (currentTrip === undefined ||
20979
- earliestArrivalOnPreviousRound.isBefore(route.arrivalAt(currentStop, currentTrip.tripIndex)) ||
20980
- earliestArrivalOnPreviousRound.equals(route.arrivalAt(currentStop, currentTrip.tripIndex)))) {
20987
+ earliestArrivalOnPreviousRound.isBefore(route.departureFrom(currentStop, currentTrip.tripIndex)) ||
20988
+ earliestArrivalOnPreviousRound.equals(route.departureFrom(currentStop, currentTrip.tripIndex)))) {
20981
20989
  const earliestTrip = route.findEarliestTrip(currentStop, earliestArrivalOnPreviousRound, currentTrip === null || currentTrip === void 0 ? void 0 : currentTrip.tripIndex);
20982
20990
  if (earliestTrip !== undefined) {
20983
20991
  currentTrip = {