minotor 12.0.0 → 13.0.0

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +4 -4
  2. package/README.md +7 -4
  3. package/dist/cli/perf.d.ts +19 -9
  4. package/dist/cli.mjs +289 -206
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/parser.cjs.js +37 -19
  7. package/dist/parser.cjs.js.map +1 -1
  8. package/dist/parser.esm.js +37 -19
  9. package/dist/parser.esm.js.map +1 -1
  10. package/dist/router.cjs.js +1 -1
  11. package/dist/router.cjs.js.map +1 -1
  12. package/dist/router.d.ts +2 -1
  13. package/dist/router.esm.js +1 -1
  14. package/dist/router.esm.js.map +1 -1
  15. package/dist/router.umd.js +1 -1
  16. package/dist/router.umd.js.map +1 -1
  17. package/dist/routing/rangeResult.d.ts +34 -25
  18. package/dist/routing/result.d.ts +28 -9
  19. package/dist/routing/resultInternals.d.ts +4 -0
  20. package/dist/routing/routingResult.d.ts +29 -0
  21. package/dist/routing/state.d.ts +2 -2
  22. package/dist/stops/stopsIndex.d.ts +1 -1
  23. package/dist/timetable/route.d.ts +2 -0
  24. package/package.json +2 -2
  25. package/src/cli/minotor.ts +20 -3
  26. package/src/cli/perf.ts +98 -111
  27. package/src/cli/repl.ts +1 -1
  28. package/src/router.ts +3 -0
  29. package/src/routing/__tests__/plotter.test.ts +0 -11
  30. package/src/routing/__tests__/rangeResult.test.ts +1470 -46
  31. package/src/routing/__tests__/rangeRouter.test.ts +14 -8
  32. package/src/routing/__tests__/result.test.ts +375 -76
  33. package/src/routing/__tests__/state.test.ts +29 -0
  34. package/src/routing/plainRouter.ts +1 -6
  35. package/src/routing/plotter.ts +6 -5
  36. package/src/routing/rangeResult.ts +67 -52
  37. package/src/routing/rangeRouter.ts +3 -8
  38. package/src/routing/result.ts +95 -36
  39. package/src/routing/resultInternals.ts +5 -0
  40. package/src/routing/routingResult.ts +34 -0
  41. package/src/routing/state.ts +11 -3
  42. package/src/stops/__tests__/stopFinder.test.ts +13 -0
  43. package/src/stops/stopsIndex.ts +13 -19
  44. package/src/timetable/__tests__/io.test.ts +27 -0
  45. package/src/timetable/__tests__/route.test.ts +30 -0
  46. package/src/timetable/io.ts +15 -1
  47. package/src/timetable/route.ts +19 -5
  48. package/src/timetable/timetable.ts +1 -1
package/dist/cli.mjs CHANGED
@@ -61,6 +61,19 @@ function __asyncValues(o) {
61
61
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
62
62
  }
63
63
 
64
+ function __classPrivateFieldGet(receiver, state, kind, f) {
65
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
66
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
67
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
68
+ }
69
+
70
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
71
+ if (kind === "m") throw new TypeError("Private method is not writable");
72
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
73
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
74
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
75
+ }
76
+
64
77
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
65
78
  var e = new Error(message);
66
79
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -16281,7 +16294,7 @@ class StopsIndex {
16281
16294
  this.stops = stops;
16282
16295
  this.sourceStopsMap = new Map();
16283
16296
  const stopsSet = new Map();
16284
- this.stopPoints = [];
16297
+ this.geoStopIds = [];
16285
16298
  for (let id = 0; id < stops.length; id++) {
16286
16299
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16287
16300
  const stop = stops[id];
@@ -16297,11 +16310,7 @@ class StopsIndex {
16297
16310
  });
16298
16311
  }
16299
16312
  if (stop.lat && stop.lon) {
16300
- this.stopPoints.push({
16301
- id: id,
16302
- lat: stop.lat,
16303
- lon: stop.lon,
16304
- });
16313
+ this.geoStopIds.push(id);
16305
16314
  }
16306
16315
  }
16307
16316
  this.textIndex = H({
@@ -16312,11 +16321,12 @@ class StopsIndex {
16312
16321
  });
16313
16322
  const stopsArray = Array.from(stopsSet.values());
16314
16323
  S(this.textIndex, stopsArray);
16315
- this.geoIndex = new KDBush(this.stopPoints.length);
16316
- for (let i = 0; i < this.stopPoints.length; i++) {
16324
+ this.geoIndex = new KDBush(this.geoStopIds.length);
16325
+ for (let i = 0; i < this.geoStopIds.length; i++) {
16317
16326
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16318
- const { lat, lon } = this.stopPoints[i];
16319
- this.geoIndex.add(lon, lat);
16327
+ const stop = this.stops[this.geoStopIds[i]];
16328
+ // Coordinates were checked when collecting geoStopIds.
16329
+ this.geoIndex.add(stop.lon, stop.lat);
16320
16330
  }
16321
16331
  this.geoIndex.finish();
16322
16332
  }
@@ -16358,8 +16368,9 @@ class StopsIndex {
16358
16368
  * @returns An array of Stop objects that match the search query.
16359
16369
  */
16360
16370
  findStopsByName(query, maxResults = 5) {
16361
- const results = R(this.textIndex, query).map((result) => this.stops[result.id]);
16362
- return results.slice(0, maxResults);
16371
+ return R(this.textIndex, query)
16372
+ .slice(0, maxResults)
16373
+ .map((result) => this.stops[result.id]);
16363
16374
  }
16364
16375
  /**
16365
16376
  * Finds stops by their geographic location using latitude and longitude.
@@ -16372,8 +16383,8 @@ class StopsIndex {
16372
16383
  */
16373
16384
  findStopsByLocation(lat, lon, maxResults = 5, radius = 0.5) {
16374
16385
  const nearestStops = around(this.geoIndex, lon, lat, maxResults, radius).map((id) => {
16375
- const stopPoint = this.stopPoints[id];
16376
- return this.stops[stopPoint.id];
16386
+ const stopId = this.geoStopIds[id];
16387
+ return this.stops[stopId];
16377
16388
  });
16378
16389
  return nearestStops;
16379
16390
  }
@@ -17473,11 +17484,14 @@ let Route$1 = class Route {
17473
17484
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17474
17485
  const stopId = stops[i];
17475
17486
  const existingIndices = this.stopIndices.get(stopId);
17476
- if (existingIndices) {
17477
- existingIndices.push(i);
17487
+ if (existingIndices === undefined) {
17488
+ this.stopIndices.set(stopId, i);
17489
+ }
17490
+ else if (typeof existingIndices === 'number') {
17491
+ this.stopIndices.set(stopId, [existingIndices, i]);
17478
17492
  }
17479
17493
  else {
17480
- this.stopIndices.set(stopId, [i]);
17494
+ existingIndices.push(i);
17481
17495
  }
17482
17496
  }
17483
17497
  }
@@ -17758,8 +17772,19 @@ let Route$1 = class Route {
17758
17772
  if (stopIndex === undefined) {
17759
17773
  return [];
17760
17774
  }
17775
+ if (typeof stopIndex === 'number') {
17776
+ // Preserve stable, mutable array results for callers that request all indices.
17777
+ const indices = [stopIndex];
17778
+ this.stopIndices.set(stopId, indices);
17779
+ return indices;
17780
+ }
17761
17781
  return stopIndex;
17762
17782
  }
17783
+ /** Returns the first occurrence without allocating an array. */
17784
+ firstStopRouteIndex(stopId) {
17785
+ const indices = this.stopIndices.get(stopId);
17786
+ return typeof indices === 'number' ? indices : indices === null || indices === void 0 ? void 0 : indices[0];
17787
+ }
17763
17788
  /**
17764
17789
  * Retrieves the id of a stop at a given index in a route.
17765
17790
  * @param stopRouteIndex The route index of the stop.
@@ -17944,11 +17969,17 @@ const deserializeStopsAdjacency = (protoStopsAdjacency) => {
17944
17969
  };
17945
17970
  const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
17946
17971
  const routesAdjacency = [];
17972
+ // Own the compact payload so small protobuf views do not retain the input file.
17973
+ const pickupDropOffStorage = new Uint8Array(protoRoutesAdjacency.reduce((size, route) => size + route.pickupDropOffTypes.byteLength, 0));
17974
+ let pickupOffset = 0;
17947
17975
  for (let i = 0; i < protoRoutesAdjacency.length; i++) {
17948
17976
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17949
17977
  const value = protoRoutesAdjacency[i];
17950
17978
  const stops = bytesToUint32Array(value.stops);
17951
- routesAdjacency.push(new Route$1(i, bytesToUint16Array(value.stopTimes), value.pickupDropOffTypes, stops, value.serviceRouteId));
17979
+ pickupDropOffStorage.set(value.pickupDropOffTypes, pickupOffset);
17980
+ const pickupDropOffTypes = pickupDropOffStorage.subarray(pickupOffset, pickupOffset + value.pickupDropOffTypes.byteLength);
17981
+ pickupOffset += value.pickupDropOffTypes.byteLength;
17982
+ routesAdjacency.push(new Route$1(i, bytesToUint16Array(value.stopTimes), pickupDropOffTypes, stops, value.serviceRouteId));
17952
17983
  }
17953
17984
  return routesAdjacency;
17954
17985
  };
@@ -18270,7 +18301,7 @@ class Timetable {
18270
18301
  if (!serviceRoute || !transportModes.has(serviceRoute.type))
18271
18302
  continue;
18272
18303
  }
18273
- const originStopIndex = route.stopRouteIndices(originStop)[0];
18304
+ const originStopIndex = route.firstStopRouteIndex(originStop);
18274
18305
  const existingHopOnStopIndex = reachableRoutes.get(route);
18275
18306
  if (existingHopOnStopIndex !== undefined) {
18276
18307
  if (originStopIndex < existingHopOnStopIndex) {
@@ -21981,6 +22012,11 @@ class StraightLineTransferGenerator {
21981
22012
  }
21982
22013
  }
21983
22014
 
22015
+ /** Internal plotter access; deliberately not exported from the package entry point. */
22016
+ const resultGraph = Symbol('resultGraph');
22017
+ /** Internal access to query destinations for range result selection. */
22018
+ const resultDestinations = Symbol('resultDestinations');
22019
+
21984
22020
  /**
21985
22021
  * Configuration for DOT graph styling.
21986
22022
  */
@@ -22186,8 +22222,9 @@ class Plotter {
22186
22222
  */
22187
22223
  getStationInfo(stopId) {
22188
22224
  var _a;
22189
- const isOrigin = ((_a = this.result.routingState.graph[0]) === null || _a === void 0 ? void 0 : _a[stopId]) !== undefined;
22190
- const isDestination = this.result.routingState.destinations.includes(stopId);
22225
+ const { graph, destinations } = this.result[resultGraph]();
22226
+ const isOrigin = ((_a = graph[0]) === null || _a === void 0 ? void 0 : _a[stopId]) !== undefined;
22227
+ const isDestination = destinations.includes(stopId);
22191
22228
  return { isOrigin, isDestination };
22192
22229
  }
22193
22230
  /**
@@ -22337,7 +22374,7 @@ class Plotter {
22337
22374
  */
22338
22375
  collectStations() {
22339
22376
  const stations = new Set();
22340
- const graph = this.result.routingState.graph;
22377
+ const graph = this.result[resultGraph]().graph;
22341
22378
  for (const roundEdges of graph) {
22342
22379
  for (let stopId = 0; stopId < roundEdges.length; stopId++) {
22343
22380
  const edge = roundEdges[stopId];
@@ -22383,7 +22420,7 @@ class Plotter {
22383
22420
  collectEdges() {
22384
22421
  const edges = [];
22385
22422
  const continuationEdges = [];
22386
- const graph = this.result.routingState.graph;
22423
+ const graph = this.result[resultGraph]().graph;
22387
22424
  for (let round = 0; round < graph.length; round++) {
22388
22425
  const roundEdges = graph[round];
22389
22426
  if (!roundEdges)
@@ -22665,24 +22702,80 @@ class Route {
22665
22702
  }
22666
22703
  }
22667
22704
 
22705
+ var _Result_routingState;
22706
+ /**
22707
+ * A single-departure routing result.
22708
+ */
22668
22709
  class Result {
22669
- constructor(destinations, routingState, stopsIndex, timetable) {
22670
- this.destinations = destinations;
22671
- this.routingState = routingState;
22710
+ constructor(routingState, stopsIndex, timetable) {
22711
+ _Result_routingState.set(this, void 0);
22712
+ __classPrivateFieldSet(this, _Result_routingState, routingState, "f");
22672
22713
  this.stopsIndex = stopsIndex;
22673
22714
  this.timetable = timetable;
22674
22715
  }
22716
+ /** @internal Default query destinations for range result selection. */
22717
+ [(_Result_routingState = new WeakMap(), resultDestinations)]() {
22718
+ return __classPrivateFieldGet(this, _Result_routingState, "f").destinations;
22719
+ }
22720
+ /** @internal Routing graph and destination metadata for the graph plotter. */
22721
+ [resultGraph]() {
22722
+ return {
22723
+ graph: __classPrivateFieldGet(this, _Result_routingState, "f").graph,
22724
+ destinations: __classPrivateFieldGet(this, _Result_routingState, "f").destinations,
22725
+ };
22726
+ }
22727
+ /**
22728
+ * Iterates over reached stops, yielding each concrete stop ID, its earliest
22729
+ * arrival time, and the number of legs taken to reach it. Unreached stops
22730
+ * are omitted. Destination pruning may limit which stops were reached.
22731
+ * @param maxTransfers Optional transfer limit within retained data.
22732
+ */
22733
+ *arrivals(maxTransfers) {
22734
+ for (const reached of __classPrivateFieldGet(this, _Result_routingState, "f").arrivals()) {
22735
+ if (maxTransfers === undefined) {
22736
+ yield reached;
22737
+ }
22738
+ else {
22739
+ const arrival = this.concreteArrivalAt(reached.stop, maxTransfers);
22740
+ if (arrival !== undefined)
22741
+ yield Object.assign({ stop: reached.stop }, arrival);
22742
+ }
22743
+ }
22744
+ }
22745
+ /** Looks up one concrete stop without expanding equivalent stops. */
22746
+ concreteArrivalAt(stop, maxTransfers) {
22747
+ var _a;
22748
+ const best = __classPrivateFieldGet(this, _Result_routingState, "f").getArrival(stop);
22749
+ if (maxTransfers === undefined ||
22750
+ (best !== undefined && best.legNumber <= maxTransfers + 1)) {
22751
+ return best;
22752
+ }
22753
+ let earliest;
22754
+ const lastRound = Math.min(maxTransfers + 1, __classPrivateFieldGet(this, _Result_routingState, "f").graph.length - 1);
22755
+ for (let round = lastRound; round >= 0; round--) {
22756
+ const edge = (_a = __classPrivateFieldGet(this, _Result_routingState, "f").graph[round]) === null || _a === void 0 ? void 0 : _a[stop];
22757
+ if (edge !== undefined &&
22758
+ (earliest === undefined || edge.arrival < earliest.arrival)) {
22759
+ earliest = { arrival: edge.arrival, legNumber: round };
22760
+ }
22761
+ }
22762
+ return earliest;
22763
+ }
22675
22764
  /**
22676
22765
  * Expands a target stop or stop set to all equivalent concrete stop IDs.
22677
22766
  *
22678
- * When `to` is omitted, defaults to the resolved destinations stored on this
22679
- * result.
22767
+ * When `to` is omitted, defaults to the resolved destinations in the
22768
+ * query.
22680
22769
  *
22681
22770
  * Equivalent stops are expanded here so destination handling has a single
22682
22771
  * source of truth shared by route reconstruction and arrival lookups.
22683
22772
  */
22684
22773
  expandDestinations(to) {
22685
- const targets = to instanceof Set ? to : to !== undefined ? [to] : this.destinations;
22774
+ const targets = to instanceof Set
22775
+ ? to
22776
+ : to !== undefined
22777
+ ? [to]
22778
+ : __classPrivateFieldGet(this, _Result_routingState, "f").destinations;
22686
22779
  const expanded = new Set();
22687
22780
  for (const target of targets) {
22688
22781
  for (const equivalentStop of this.stopsIndex.equivalentStops(target)) {
@@ -22697,9 +22790,10 @@ class Result {
22697
22790
  * destination set)
22698
22791
  *
22699
22792
  * @param to The destination stop by SourceStopId.
22793
+ * @param maxTransfers Optional transfer limit within retained data.
22700
22794
  * @returns a route to the destination stop if it exists.
22701
22795
  */
22702
- bestRouteToSourceStopId(to) {
22796
+ bestRouteToSourceStopId(to, maxTransfers) {
22703
22797
  var _a;
22704
22798
  if (to instanceof Set) {
22705
22799
  const stopIds = new Set();
@@ -22708,10 +22802,14 @@ class Result {
22708
22802
  if (found !== undefined)
22709
22803
  stopIds.add(found.id);
22710
22804
  }
22711
- return stopIds.size === 0 ? undefined : this.bestRoute(stopIds);
22805
+ return stopIds.size === 0
22806
+ ? undefined
22807
+ : this.bestRoute(stopIds, maxTransfers);
22712
22808
  }
22713
22809
  const stopId = (_a = this.stopsIndex.findStopBySourceStopId(to)) === null || _a === void 0 ? void 0 : _a.id;
22714
- return stopId === undefined ? undefined : this.bestRoute(stopId);
22810
+ return stopId === undefined
22811
+ ? undefined
22812
+ : this.bestRoute(stopId, maxTransfers);
22715
22813
  }
22716
22814
  /**
22717
22815
  * Reconstructs the best route to a stop.
@@ -22720,9 +22818,10 @@ class Result {
22720
22818
  *
22721
22819
  * @param to The destination stop. Defaults to this result's resolved
22722
22820
  * destinations.
22821
+ * @param maxTransfers Optional transfer limit within retained data.
22723
22822
  * @returns a route to the destination stop if it exists.
22724
22823
  */
22725
- bestRoute(to) {
22824
+ bestRoute(to, maxTransfers) {
22726
22825
  var _a;
22727
22826
  const destinationStops = this.expandDestinations(to);
22728
22827
  // Find the fastest-reached destination across all equivalent stops.
@@ -22730,7 +22829,7 @@ class Result {
22730
22829
  let fastestArrivalTime = undefined;
22731
22830
  let fastestLegNumber = undefined;
22732
22831
  for (const destination of destinationStops) {
22733
- const arrivalData = this.routingState.getArrival(destination);
22832
+ const arrivalData = this.concreteArrivalAt(destination, maxTransfers);
22734
22833
  if (arrivalData !== undefined &&
22735
22834
  (fastestArrivalTime === undefined ||
22736
22835
  arrivalData.arrival < fastestArrivalTime)) {
@@ -22748,7 +22847,7 @@ class Result {
22748
22847
  let round = fastestLegNumber;
22749
22848
  let previousVehicleEdge;
22750
22849
  while (round >= 0) {
22751
- const edge = (_a = this.routingState.graph[round]) === null || _a === void 0 ? void 0 : _a[currentStop];
22850
+ const edge = (_a = __classPrivateFieldGet(this, _Result_routingState, "f").graph[round]) === null || _a === void 0 ? void 0 : _a[currentStop];
22752
22851
  if (!edge) {
22753
22852
  if (round === 0)
22754
22853
  break;
@@ -22910,34 +23009,14 @@ class Result {
22910
23009
  * than this result's destination set.
22911
23010
  *
22912
23011
  * @param stop The target stop for which to return the arrival time.
22913
- * @param maxTransfers The optional maximum number of transfers allowed.
23012
+ * @param maxTransfers Optional transfer limit within retained data.
22914
23013
  * @returns The arrival time if the target stop is reachable, otherwise undefined.
22915
23014
  */
22916
23015
  arrivalAt(stop, maxTransfers) {
22917
- var _a, _b;
22918
23016
  const equivalentStops = this.stopsIndex.equivalentStops(stop);
22919
23017
  let earliestArrival = undefined;
22920
23018
  for (const equivalentStop of equivalentStops) {
22921
- let arrivalTime;
22922
- if (maxTransfers === undefined ||
22923
- ((_a = this.routingState.getArrival(equivalentStop.id)) === null || _a === void 0 ? void 0 : _a.legNumber) ===
22924
- maxTransfers + 1) {
22925
- arrivalTime = this.routingState.getArrival(equivalentStop.id);
22926
- }
22927
- else {
22928
- // We have no guarantee that the stop was visited in the last round,
22929
- // so we need to check all rounds if it's not found in the last one.
22930
- for (let i = maxTransfers + 1; i >= 0; i--) {
22931
- const arrivalEdge = (_b = this.routingState.graph[i]) === null || _b === void 0 ? void 0 : _b[equivalentStop.id];
22932
- if (arrivalEdge !== undefined) {
22933
- arrivalTime = {
22934
- arrival: arrivalEdge.arrival,
22935
- legNumber: i,
22936
- };
22937
- break;
22938
- }
22939
- }
22940
- }
23019
+ const arrivalTime = this.concreteArrivalAt(equivalentStop.id, maxTransfers);
22941
23020
  if (arrivalTime !== undefined) {
22942
23021
  if (earliestArrival === undefined ||
22943
23022
  arrivalTime.arrival < earliestArrival.arrival) {
@@ -23083,8 +23162,8 @@ class RoutingState {
23083
23162
  */
23084
23163
  this.maxArrivalTime = UNREACHED_TIME;
23085
23164
  /**
23086
- * Every stop that has received an arrival improvement during the current run,
23087
- * in the order the improvements occurred. Used by {@link resetFor} to clear
23165
+ * Every stop reached during the current run, recorded once in first-reached
23166
+ * order. Used by {@link resetFor} to clear
23088
23167
  * only the touched entries instead of scanning the entire array.
23089
23168
  */
23090
23169
  this.reachedStops = [];
@@ -23176,7 +23255,9 @@ class RoutingState {
23176
23255
  * @param leg The round number (number of transit legs taken so far).
23177
23256
  */
23178
23257
  updateArrival(stop, time, leg) {
23179
- this.reachedStops.push(stop);
23258
+ if (this.earliestArrivalTimes[stop] === UNREACHED_TIME) {
23259
+ this.reachedStops.push(stop);
23260
+ }
23180
23261
  this.earliestArrivalTimes[stop] = time;
23181
23262
  this.earliestArrivalLegs[stop] = leg;
23182
23263
  if (this.destinationSet.has(stop) && time < this._destinationBest) {
@@ -23314,6 +23395,13 @@ class RoutingState {
23314
23395
  return arr;
23315
23396
  });
23316
23397
  state.graph.splice(0, state.graph.length, ...denseRounds);
23398
+ state.reachedStops.length = 0;
23399
+ const touched = new Set(arrivals.map(([stop]) => stop));
23400
+ for (const round of graph) {
23401
+ for (const [stop] of round)
23402
+ touched.add(stop);
23403
+ }
23404
+ state.reachedStops.push(...touched);
23317
23405
  return state;
23318
23406
  }
23319
23407
  }
@@ -23339,7 +23427,7 @@ class PlainRouter {
23339
23427
  .map((destination) => destination.id);
23340
23428
  const routingState = new RoutingState(query.departureTime, destinations, accessLegs, this.timetable.nbStops(), query.options.maxTransfers + 1, query.options.maxDuration);
23341
23429
  this.raptor.run(query.options, routingState);
23342
- return new Result(new Set(destinations), routingState, this.stopsIndex, this.timetable);
23430
+ return new Result(routingState, this.stopsIndex, this.timetable);
23343
23431
  }
23344
23432
  }
23345
23433
 
@@ -23358,53 +23446,50 @@ class PlainRouter {
23358
23446
  * strictly earlier *and* arrives strictly earlier than the previous one,
23359
23447
  * forming the classic staircase Pareto frontier.
23360
23448
  *
23361
- * **Full-network mode** (empty `destinations`): when no destinations are
23449
+ * **Full-network mode** (no query destinations): when no destinations are
23362
23450
  * supplied to the range query every departure slot in the window becomes its
23363
23451
  * own run, because destination-based Pareto pruning cannot be applied.
23364
- * In this mode the destination-specific helpers ({@link getRoutes},
23452
+ * In this mode the destination-specific helpers ({@link routes},
23365
23453
  * {@link bestRoute}, {@link latestDepartureRoute}, {@link fastestRoute})
23366
- * return empty results; use {@link allEarliestArrivals},
23367
- * {@link allShortestDurations}, {@link earliestArrivalAt}, or
23454
+ * return empty results; use {@link arrivals},
23455
+ * {@link shortestDurations}, {@link arrivalAt}, or
23368
23456
  * {@link shortestDurationTo} instead.
23369
23457
  *
23370
23458
  * Destination handling is delegated to {@link Result}, which expands
23371
23459
  * equivalent stops when reconstructing routes or looking up arrivals.
23372
23460
  */
23373
23461
  class RangeResult {
23374
- constructor(runs, destinations) {
23462
+ constructor(runs) {
23375
23463
  this._runs = runs;
23376
- this._destinations = destinations;
23377
- }
23378
- /** The resolved destination stop IDs for this result. */
23379
- get destinations() {
23380
- return this._destinations;
23381
23464
  }
23382
23465
  normalizeTargets(to) {
23466
+ var _a;
23383
23467
  if (to instanceof Set)
23384
23468
  return new Set(to);
23385
23469
  if (to !== undefined)
23386
23470
  return new Set([to]);
23387
- return new Set(this._destinations);
23471
+ return new Set((_a = this._runs[0]) === null || _a === void 0 ? void 0 : _a.result[resultDestinations]());
23388
23472
  }
23389
23473
  /**
23390
- * Returns all non-dominated routes to this result's default destination set,
23474
+ * Lazily yields all non-dominated routes to this result's default destination set,
23391
23475
  * ordered from the earliest departure to the latest departure.
23392
23476
  *
23393
- * Each route in the list departs strictly earlier *and* arrives strictly
23394
- * earlier than its predecessor.
23477
+ * Each route in the list departs strictly later *and* arrives strictly
23478
+ * later than its predecessor.
23395
23479
  *
23396
- * Returns an empty array when no destinations were provided (full-network
23397
- * mode). Use {@link allEarliestArrivals} or {@link allShortestDurations}
23480
+ * Yields nothing when no destinations were provided (full-network
23481
+ * mode). Use {@link arrivals} or {@link shortestDurations}
23398
23482
  * to query individual stops in that case.
23399
23483
  */
23400
- getRoutes() {
23401
- const routes = [];
23402
- for (const { result } of this._runs) {
23403
- const route = result.bestRoute();
23484
+ *routes() {
23485
+ for (let index = this._runs.length - 1; index >= 0; index--) {
23486
+ const run = this._runs[index];
23487
+ if (run === undefined)
23488
+ continue;
23489
+ const route = run.result.bestRoute();
23404
23490
  if (route !== undefined)
23405
- routes.push(route);
23491
+ yield route;
23406
23492
  }
23407
- return routes.reverse();
23408
23493
  }
23409
23494
  /**
23410
23495
  * The route that arrives **earliest** at the given stop(s) across all
@@ -23419,16 +23504,17 @@ class RangeResult {
23419
23504
  * (no destinations), otherwise `undefined` is returned.
23420
23505
  *
23421
23506
  * @param to Optional destination stop ID or set of stop IDs.
23507
+ * @param maxTransfers Optional transfer limit within retained data.
23422
23508
  * @returns The reconstructed {@link Route} with the earliest arrival,
23423
23509
  * or `undefined` if the target is unreachable in every run.
23424
23510
  */
23425
- bestRoute(to) {
23511
+ bestRoute(to, maxTransfers) {
23426
23512
  const targetStops = this.normalizeTargets(to);
23427
23513
  let bestRun;
23428
23514
  let bestArrival;
23429
23515
  for (const run of this._runs) {
23430
23516
  for (const stopId of targetStops) {
23431
- const arrival = run.result.arrivalAt(stopId);
23517
+ const arrival = run.result.arrivalAt(stopId, maxTransfers);
23432
23518
  if (arrival === undefined)
23433
23519
  continue;
23434
23520
  if (bestArrival === undefined || arrival.arrival < bestArrival) {
@@ -23437,7 +23523,7 @@ class RangeResult {
23437
23523
  }
23438
23524
  }
23439
23525
  }
23440
- return bestRun === null || bestRun === void 0 ? void 0 : bestRun.result.bestRoute(targetStops);
23526
+ return bestRun === null || bestRun === void 0 ? void 0 : bestRun.result.bestRoute(targetStops, maxTransfers);
23441
23527
  }
23442
23528
  /**
23443
23529
  * The route with the **latest possible departure** from the origin among all
@@ -23453,13 +23539,14 @@ class RangeResult {
23453
23539
  * (no destinations), otherwise `undefined` is returned.
23454
23540
  *
23455
23541
  * @param to Optional destination stop ID or set of stop IDs.
23542
+ * @param maxTransfers Optional transfer limit within retained data.
23456
23543
  * @returns The reconstructed {@link Route} with the latest departure,
23457
23544
  * or `undefined` if the target is unreachable in every run.
23458
23545
  */
23459
- latestDepartureRoute(to) {
23546
+ latestDepartureRoute(to, maxTransfers) {
23460
23547
  const targetStops = this.normalizeTargets(to);
23461
23548
  for (const { result } of this._runs) {
23462
- const route = result.bestRoute(targetStops);
23549
+ const route = result.bestRoute(targetStops, maxTransfers);
23463
23550
  if (route !== undefined)
23464
23551
  return route;
23465
23552
  }
@@ -23479,16 +23566,17 @@ class RangeResult {
23479
23566
  * (no destinations), otherwise `undefined` is returned.
23480
23567
  *
23481
23568
  * @param to Optional destination stop ID or set of stop IDs.
23569
+ * @param maxTransfers Optional transfer limit within retained data.
23482
23570
  * @returns The reconstructed fastest {@link Route}, or `undefined` if the
23483
23571
  * target is unreachable in every run.
23484
23572
  */
23485
- fastestRoute(to) {
23573
+ fastestRoute(to, maxTransfers) {
23486
23574
  const targetStops = this.normalizeTargets(to);
23487
23575
  let fastestRun;
23488
23576
  let shortestDuration = Infinity;
23489
23577
  for (const run of this._runs) {
23490
23578
  for (const stopId of targetStops) {
23491
- const arrival = run.result.arrivalAt(stopId);
23579
+ const arrival = run.result.arrivalAt(stopId, maxTransfers);
23492
23580
  if (arrival === undefined)
23493
23581
  continue;
23494
23582
  const duration = arrival.arrival - run.departureTime;
@@ -23501,7 +23589,7 @@ class RangeResult {
23501
23589
  }
23502
23590
  }
23503
23591
  }
23504
- return fastestRun === null || fastestRun === void 0 ? void 0 : fastestRun.result.bestRoute(targetStops);
23592
+ return fastestRun === null || fastestRun === void 0 ? void 0 : fastestRun.result.bestRoute(targetStops, maxTransfers);
23505
23593
  }
23506
23594
  /** Number of Pareto-optimal journeys found. */
23507
23595
  get size() {
@@ -23517,9 +23605,9 @@ class RangeResult {
23517
23605
  * Equivalent stops are handled by {@link Result.arrivalAt}.
23518
23606
  *
23519
23607
  * @param stop The target stop ID.
23520
- * @param maxTransfers Optional upper bound on the number of transfers.
23608
+ * @param maxTransfers Optional transfer limit within retained data.
23521
23609
  */
23522
- earliestArrivalAt(stop, maxTransfers) {
23610
+ arrivalAt(stop, maxTransfers) {
23523
23611
  let best;
23524
23612
  for (const { result } of this._runs) {
23525
23613
  const arrival = result.arrivalAt(stop, maxTransfers);
@@ -23546,7 +23634,7 @@ class RangeResult {
23546
23634
  * Returns `undefined` if `stop` is unreachable in every run.
23547
23635
  *
23548
23636
  * @param stop The target stop ID.
23549
- * @param maxTransfers Optional upper bound on the number of transfers.
23637
+ * @param maxTransfers Optional transfer limit within retained data.
23550
23638
  */
23551
23639
  shortestDurationTo(stop, maxTransfers) {
23552
23640
  let shortest;
@@ -23563,12 +23651,15 @@ class RangeResult {
23563
23651
  }
23564
23652
  /**
23565
23653
  * Shortest travel duration to **every reachable stop** across all
23566
- * Pareto-optimal runs, as a single `Map<StopId, DurationArrival>`.
23654
+ * Pareto-optimal runs, yielding the stop ID and arrival with duration.
23655
+ * All runs are aggregated before the first value is yielded. Ties retain
23656
+ * the first run's arrival and leg count.
23657
+ * @param maxTransfers Optional transfer limit within retained data.
23567
23658
  */
23568
- allShortestDurations() {
23659
+ *shortestDurations(maxTransfers) {
23569
23660
  const durations = new Map();
23570
23661
  for (const { departureTime, result } of this._runs) {
23571
- for (const { stop, arrival, legNumber, } of result.routingState.arrivals()) {
23662
+ for (const { stop, arrival, legNumber } of result.arrivals(maxTransfers)) {
23572
23663
  const duration = arrival - departureTime;
23573
23664
  const existing = durations.get(stop);
23574
23665
  if (existing === undefined || duration < existing.duration) {
@@ -23576,23 +23667,30 @@ class RangeResult {
23576
23667
  }
23577
23668
  }
23578
23669
  }
23579
- return durations;
23670
+ for (const [stop, arrival] of durations) {
23671
+ yield Object.assign({ stop }, arrival);
23672
+ }
23580
23673
  }
23581
23674
  /**
23582
23675
  * Earliest achievable arrival at **every reachable stop** across all
23583
- * Pareto-optimal runs, as a single `Map<StopId, Arrival>`.
23676
+ * Pareto-optimal runs, yielding the stop ID and arrival.
23677
+ * All runs are aggregated before the first value is yielded. Ties retain
23678
+ * the first run's arrival and leg count.
23679
+ * @param maxTransfers Optional transfer limit within retained data.
23584
23680
  */
23585
- allEarliestArrivals() {
23681
+ *arrivals(maxTransfers) {
23586
23682
  const arrivals = new Map();
23587
23683
  for (const { result } of this._runs) {
23588
- for (const { stop, arrival, legNumber, } of result.routingState.arrivals()) {
23684
+ for (const { stop, arrival, legNumber } of result.arrivals(maxTransfers)) {
23589
23685
  const existing = arrivals.get(stop);
23590
23686
  if (existing === undefined || arrival < existing.arrival) {
23591
23687
  arrivals.set(stop, { arrival, legNumber });
23592
23688
  }
23593
23689
  }
23594
23690
  }
23595
- return arrivals;
23691
+ for (const [stop, arrival] of arrivals) {
23692
+ yield Object.assign({ stop }, arrival);
23693
+ }
23596
23694
  }
23597
23695
  /**
23598
23696
  * Iterates over all Pareto-optimal `(departureTime, result)` pairs,
@@ -23744,7 +23842,7 @@ class RangeRouter {
23744
23842
  const accessLegs = this.accessFinder.collectAccessPaths(query.from, query.options.minTransferTime);
23745
23843
  const departureSlots = this.accessFinder.collectDepartureTimes(accessLegs, earliest, latest);
23746
23844
  if (departureSlots.length === 0) {
23747
- return new RangeResult([], new Set(destinations));
23845
+ return new RangeResult([]);
23748
23846
  }
23749
23847
  const maxRounds = query.options.maxTransfers + 1;
23750
23848
  const rangeState = new RangeRaptorState(maxRounds, this.timetable.nbStops(), latest);
@@ -23803,12 +23901,12 @@ class RangeRouter {
23803
23901
  if (isParetoOptimal) {
23804
23902
  paretoRuns.push({
23805
23903
  departureTime: depTime,
23806
- result: new Result(new Set(destinations), routingState, this.stopsIndex, this.timetable),
23904
+ result: new Result(routingState, this.stopsIndex, this.timetable),
23807
23905
  });
23808
23906
  routingState = null;
23809
23907
  }
23810
23908
  }
23811
- return new RangeResult(paretoRuns, new Set(destinations));
23909
+ return new RangeResult(paretoRuns);
23812
23910
  }
23813
23911
  }
23814
23912
 
@@ -24090,6 +24188,50 @@ class Router {
24090
24188
  }
24091
24189
  }
24092
24190
 
24191
+ /** Observed deltas, not peak memory or total allocations; GC can make them negative. */
24192
+ const measurePerformance = (operation, iterations) => {
24193
+ var _a;
24194
+ let totalTime = 0;
24195
+ let totalHeap = 0;
24196
+ let totalArrayBuffers = 0;
24197
+ for (let i = 0; i < iterations; i++) {
24198
+ (_a = global.gc) === null || _a === void 0 ? void 0 : _a.call(global);
24199
+ const before = process.memoryUsage();
24200
+ const start = performance$1.now();
24201
+ operation();
24202
+ const end = performance$1.now();
24203
+ const after = process.memoryUsage();
24204
+ totalTime += (end - start) * 1000;
24205
+ totalHeap += after.heapUsed - before.heapUsed;
24206
+ totalArrayBuffers += after.arrayBuffers - before.arrayBuffers;
24207
+ }
24208
+ return {
24209
+ meanTimeUs: totalTime / iterations,
24210
+ meanHeapMiB: totalHeap / iterations / (1024 * 1024),
24211
+ meanArrayBuffersMiB: totalArrayBuffers / iterations / (1024 * 1024),
24212
+ };
24213
+ };
24214
+ /** Measure retained storage after collection, keeping only the returned value alive. */
24215
+ const measureRetainedMemory = (operation) => {
24216
+ const gc = global.gc;
24217
+ gc === null || gc === void 0 ? void 0 : gc();
24218
+ const before = gc ? process.memoryUsage() : undefined;
24219
+ const start = performance$1.now();
24220
+ const value = operation();
24221
+ const loadTimeMs = performance$1.now() - start;
24222
+ if (!gc || !before)
24223
+ return { value, loadTimeMs };
24224
+ // A second collection lets backing storage released by finalization settle.
24225
+ gc();
24226
+ gc();
24227
+ const after = process.memoryUsage();
24228
+ return {
24229
+ value,
24230
+ loadTimeMs,
24231
+ retainedHeapMiB: (after.heapUsed - before.heapUsed) / (1024 * 1024),
24232
+ retainedArrayBuffersMiB: (after.arrayBuffers - before.arrayBuffers) / (1024 * 1024),
24233
+ };
24234
+ };
24093
24235
  const renderTable = (columns, rows, footerRow) => {
24094
24236
  const bar = (l, m, r) => l + columns.map((c) => '─'.repeat(c.width + 2)).join(m) + r;
24095
24237
  const renderRow = (cells) => '│' +
@@ -24217,32 +24359,12 @@ const loadRangeQueriesFromJson = (filePath, stopsIndex) => {
24217
24359
  * yield a more stable mean at the cost of longer wall-clock time.
24218
24360
  * @param stopsIndex - Used to resolve stop names for result labels.
24219
24361
  * @returns An array of {@link PerformanceResult} objects, one per query, each
24220
- * containing the mean wall-clock time (µs) and mean heap delta (MB).
24362
+ * containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
24221
24363
  */
24222
24364
  const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
24223
24365
  const results = [];
24224
24366
  for (const task of tasks) {
24225
- let totalTime = 0;
24226
- let totalMemory = 0;
24227
- for (let i = 0; i < iterations; i++) {
24228
- if (global.gc) {
24229
- global.gc();
24230
- }
24231
- const startMemory = process.memoryUsage().heapUsed;
24232
- const startTime = performance$1.now();
24233
- router.route(task);
24234
- const endTime = performance$1.now();
24235
- const endMemory = process.memoryUsage().heapUsed;
24236
- totalTime += (endTime - startTime) * 1000;
24237
- if (endMemory >= startMemory) {
24238
- totalMemory += endMemory - startMemory;
24239
- }
24240
- }
24241
- results.push({
24242
- label: buildQueryLabel(task, stopsIndex),
24243
- meanTimeUs: totalTime / iterations,
24244
- meanMemoryMb: totalMemory / iterations / (1024 * 1024),
24245
- });
24367
+ results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.route(task), iterations)));
24246
24368
  }
24247
24369
  return results;
24248
24370
  };
@@ -24257,34 +24379,14 @@ const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
24257
24379
  * @param iterations - Number of times `bestRoute` is called per query.
24258
24380
  * @param stopsIndex - Used to resolve stop names for result labels.
24259
24381
  * @returns An array of {@link PerformanceResult} objects, one per query, each
24260
- * containing the mean wall-clock time (µs) and mean heap delta (MB) for the
24382
+ * containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
24261
24383
  * `bestRoute` call alone.
24262
24384
  */
24263
24385
  const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
24264
24386
  const results = [];
24265
24387
  for (const task of tasks) {
24266
24388
  const result = router.route(task);
24267
- let totalTime = 0;
24268
- let totalMemory = 0;
24269
- for (let i = 0; i < iterations; i++) {
24270
- if (global.gc) {
24271
- global.gc();
24272
- }
24273
- const startMemory = process.memoryUsage().heapUsed;
24274
- const startTime = performance$1.now();
24275
- result.bestRoute();
24276
- const endTime = performance$1.now();
24277
- const endMemory = process.memoryUsage().heapUsed;
24278
- totalTime += (endTime - startTime) * 1000;
24279
- if (endMemory >= startMemory) {
24280
- totalMemory += endMemory - startMemory;
24281
- }
24282
- }
24283
- results.push({
24284
- label: buildQueryLabel(task, stopsIndex),
24285
- meanTimeUs: totalTime / iterations,
24286
- meanMemoryMb: totalMemory / iterations / (1024 * 1024),
24287
- });
24389
+ results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => result.bestRoute(), iterations)));
24288
24390
  }
24289
24391
  return results;
24290
24392
  };
@@ -24297,78 +24399,37 @@ const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
24297
24399
  * @param iterations - Number of times each query is repeated.
24298
24400
  * @param stopsIndex - Used to resolve stop names for result labels.
24299
24401
  * @returns An array of {@link PerformanceResult} objects, one per query, each
24300
- * containing the mean wall-clock time (µs) and mean heap delta (MB).
24402
+ * containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
24301
24403
  */
24302
24404
  const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
24303
24405
  const results = [];
24304
24406
  for (const task of tasks) {
24305
- let totalTime = 0;
24306
- let totalMemory = 0;
24307
- for (let i = 0; i < iterations; i++) {
24308
- if (global.gc) {
24309
- global.gc();
24310
- }
24311
- const startMemory = process.memoryUsage().heapUsed;
24312
- const startTime = performance$1.now();
24313
- router.rangeRoute(task);
24314
- const endTime = performance$1.now();
24315
- const endMemory = process.memoryUsage().heapUsed;
24316
- totalTime += (endTime - startTime) * 1000;
24317
- if (endMemory >= startMemory) {
24318
- totalMemory += endMemory - startMemory;
24319
- }
24320
- }
24321
- results.push({
24322
- label: buildQueryLabel(task, stopsIndex),
24323
- meanTimeUs: totalTime / iterations,
24324
- meanMemoryMb: totalMemory / iterations / (1024 * 1024),
24325
- });
24407
+ results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.rangeRoute(task), iterations)));
24326
24408
  }
24327
24409
  return results;
24328
24410
  };
24329
24411
  /**
24330
- * Benchmarks {@link RangeResult.getRoutes} — the full Pareto-frontier
24412
+ * Benchmarks {@link RangeResult.routes} — the full Pareto-frontier
24331
24413
  * reconstruction phase — independently of the range routing phase.
24332
24414
  *
24333
24415
  * @param router - The router instance used to produce the range results that
24334
- * are then fed into `getRoutes`.
24416
+ * are then fed into `routes`.
24335
24417
  * @param tasks - The list of range queries to benchmark. One
24336
24418
  * {@link PerformanceResult} is produced per query.
24337
- * @param iterations - Number of times `getRoutes` is called per query.
24419
+ * @param iterations - Number of times `routes` is fully consumed per query.
24338
24420
  * @param stopsIndex - Used to resolve stop names for result labels.
24339
24421
  * @returns An array of {@link PerformanceResult} objects, one per query, each
24340
- * containing the mean wall-clock time (µs) and mean heap delta (MB) for the
24341
- * `getRoutes` call alone.
24422
+ * containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
24423
+ * full `routes` iteration alone.
24342
24424
  */
24343
24425
  const testRangeResultPerformance = (router, tasks, iterations, stopsIndex) => {
24344
24426
  const results = [];
24345
24427
  for (const task of tasks) {
24346
24428
  const rangeResult = router.rangeRoute(task);
24347
- let totalTime = 0;
24348
- let totalMemory = 0;
24349
- for (let i = 0; i < iterations; i++) {
24350
- if (global.gc) {
24351
- global.gc();
24352
- }
24353
- const startMemory = process.memoryUsage().heapUsed;
24354
- const startTime = performance$1.now();
24355
- rangeResult.getRoutes();
24356
- const endTime = performance$1.now();
24357
- const endMemory = process.memoryUsage().heapUsed;
24358
- totalTime += (endTime - startTime) * 1000;
24359
- if (endMemory >= startMemory) {
24360
- totalMemory += endMemory - startMemory;
24361
- }
24362
- }
24363
- results.push({
24364
- label: buildQueryLabel(task, stopsIndex),
24365
- meanTimeUs: totalTime / iterations,
24366
- meanMemoryMb: totalMemory / iterations / (1024 * 1024),
24367
- });
24429
+ results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => [...rangeResult.routes()], iterations)));
24368
24430
  }
24369
24431
  return results;
24370
24432
  };
24371
- // ─── Output ───────────────────────────────────────────────────────────────────
24372
24433
  /**
24373
24434
  * Prints a table summary of performance results to stdout.
24374
24435
  *
@@ -24388,12 +24449,16 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
24388
24449
  const fmtTime = (n) => Math.round(n).toLocaleString('en-US');
24389
24450
  const fmtMem = (n) => n.toFixed(2);
24390
24451
  const meanTime = results.reduce((s, r) => s + r.meanTimeUs, 0) / results.length;
24391
- const meanMem = results.reduce((s, r) => s + r.meanMemoryMb, 0) / results.length;
24452
+ const meanMem = results.reduce((s, r) => s + r.meanHeapMiB, 0) / results.length;
24453
+ const meanBuffers = results.reduce((s, r) => s + r.meanArrayBuffersMiB, 0) / results.length;
24392
24454
  const queryHeader = 'Query';
24393
24455
  const timeHeader = 'Time (µs)';
24394
- const memHeader = 'Mem (MB)';
24456
+ const memHeader = 'Heap Δ (MiB)';
24457
+ const buffersHeader = 'ArrayBuffers Δ (MiB)';
24395
24458
  const timeVals = results.map((r) => fmtTime(r.meanTimeUs));
24396
- const memVals = results.map((r) => fmtMem(r.meanMemoryMb));
24459
+ const memVals = results.map((r) => fmtMem(r.meanHeapMiB));
24460
+ const bufferVals = results.map((r) => fmtMem(r.meanArrayBuffersMiB));
24461
+ const meanBuffersStr = fmtMem(meanBuffers);
24397
24462
  const meanTimeStr = fmtTime(meanTime);
24398
24463
  const meanMemStr = fmtMem(meanMem);
24399
24464
  const queryWidth = Math.max(queryHeader.length, 'mean'.length, ...results.map((r) => r.label.length));
@@ -24403,17 +24468,26 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
24403
24468
  { header: queryHeader, width: queryWidth, align: 'left' },
24404
24469
  { header: timeHeader, width: timeWidth, align: 'right' },
24405
24470
  { header: memHeader, width: memWidth, align: 'right' },
24471
+ {
24472
+ header: buffersHeader,
24473
+ width: Math.max(buffersHeader.length, meanBuffersStr.length, ...bufferVals.map((v) => v.length)),
24474
+ align: 'right',
24475
+ },
24406
24476
  ];
24407
24477
  const rows = results.map((r, i) => {
24408
- var _a, _b;
24478
+ var _a, _b, _c;
24409
24479
  return [
24410
24480
  r.label,
24411
24481
  (_a = timeVals[i]) !== null && _a !== void 0 ? _a : '',
24412
24482
  (_b = memVals[i]) !== null && _b !== void 0 ? _b : '',
24483
+ (_c = bufferVals[i]) !== null && _c !== void 0 ? _c : '',
24413
24484
  ];
24414
24485
  });
24415
- const footer = ['mean', meanTimeStr, meanMemStr];
24486
+ const footer = ['mean', meanTimeStr, meanMemStr, meanBuffersStr];
24416
24487
  console.log(renderTable(columns, rows, footer));
24488
+ if (!global.gc) {
24489
+ console.log('Explicit GC unavailable; use node --expose-gc for more consistent samples.');
24490
+ }
24417
24491
  };
24418
24492
 
24419
24493
  /**
@@ -24553,7 +24627,7 @@ const startRepl = (stopsPath, timetablePath) => {
24553
24627
  console.log(`Found ${result.size} Pareto-optimal journey${result.size === 1 ? '' : 's'} ` +
24554
24628
  `from ${fromStop.name} to ${toStop.name} ` +
24555
24629
  `(window ${atTime}–${beforeTime}):`);
24556
- const routes = result.getRoutes();
24630
+ const routes = [...result.routes()];
24557
24631
  routes.forEach((route, index) => {
24558
24632
  const journeyNumber = index + 1;
24559
24633
  console.log(`\nJourney ${journeyNumber}:`);
@@ -24954,7 +25028,16 @@ program
24954
25028
  .option('-i, --iterations <number>', 'Number of iterations for performance tests', '20')
24955
25029
  .action((routesPath, options) => {
24956
25030
  const stopsIndex = StopsIndex.fromData(fs$1.readFileSync(options.stopsPath));
24957
- const timetable = Timetable.fromData(fs$1.readFileSync(options.timetablePath));
25031
+ const loading = measureRetainedMemory(() => Timetable.fromData(fs$1.readFileSync(options.timetablePath)));
25032
+ const timetable = loading.value;
25033
+ console.log(`Timetable load (read + decode): ${loading.loadTimeMs.toFixed(2)} ms`);
25034
+ if (loading.retainedHeapMiB !== undefined &&
25035
+ loading.retainedArrayBuffersMiB !== undefined) {
25036
+ console.log(`Timetable retained after GC: heap ${loading.retainedHeapMiB.toFixed(2)} MiB; ArrayBuffers ${loading.retainedArrayBuffersMiB.toFixed(2)} MiB`);
25037
+ }
25038
+ else {
25039
+ console.log('Retained memory skipped: explicit GC unavailable; use node --expose-gc.');
25040
+ }
24958
25041
  const router = new Router(timetable, stopsIndex);
24959
25042
  const queries = loadQueriesFromJson(routesPath, stopsIndex);
24960
25043
  const iterations = parseInt(options.iterations, 10);
@@ -24966,7 +25049,7 @@ program
24966
25049
  const rangeRouterResults = testRangeRouterPerformance(router, rangeQueries, iterations, stopsIndex);
24967
25050
  prettyPrintPerformanceResults(rangeRouterResults, 'Range queries — router.rangeRoute()');
24968
25051
  const rangeResultResults = testRangeResultPerformance(router, rangeQueries, iterations, stopsIndex);
24969
- prettyPrintPerformanceResults(rangeResultResults, 'Range queries — rangeResult.getRoutes() (reconstruction only)');
25052
+ prettyPrintPerformanceResults(rangeResultResults, 'Range queries — rangeResult.routes() (reconstruction only)');
24970
25053
  });
24971
25054
  program.parse(process.argv);
24972
25055
  //# sourceMappingURL=cli.mjs.map