minotor 11.1.0 → 11.1.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.
@@ -12897,6 +12897,45 @@ class Route {
12897
12897
  }
12898
12898
  return arrival;
12899
12899
  }
12900
+ /**
12901
+ * Computes the per-trip base offset used by the hot-path scanning methods.
12902
+ *
12903
+ * Cache the result once when boarding a new trip and pass it to
12904
+ * {@link arrivalAtOffset} and {@link dropOffTypeAtOffset} throughout the
12905
+ * scanning loop to avoid recomputing `tripIndex × nbStops` on every stop.
12906
+ *
12907
+ * @param tripIndex - The index of the trip.
12908
+ * @returns `tripIndex × nbStops`.
12909
+ */
12910
+ tripStopOffset(tripIndex) {
12911
+ return tripIndex * this.nbStops;
12912
+ }
12913
+ /**
12914
+ * Hot-path variant of {@link arrivalAt} that accepts a precomputed base offset.
12915
+ *
12916
+ * @param stopIndex - The index of the stop in the route.
12917
+ * @param offset - Precomputed value from {@link tripStopOffset}.
12918
+ * @returns The arrival time at the specified stop.
12919
+ */
12920
+ arrivalAtOffset(stopIndex, offset) {
12921
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12922
+ return this.stopTimes[(offset + stopIndex) * 2];
12923
+ }
12924
+ /**
12925
+ * Hot-path variant of {@link dropOffTypeAt} that accepts a precomputed base offset.
12926
+ *
12927
+ * @param stopIndex - The index of the stop in the route.
12928
+ * @param offset - Precomputed value from {@link tripStopOffset}.
12929
+ * @returns The drop-off type at the specified stop.
12930
+ */
12931
+ dropOffTypeAtOffset(stopIndex, offset) {
12932
+ const globalIndex = offset + stopIndex;
12933
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12934
+ const byte = this.pickupDropOffTypes[globalIndex >> 1];
12935
+ // Bit layout per byte (two pairs): [pickup_1(2)][dropOff_1(2)][pickup_0(2)][dropOff_0(2)]
12936
+ // First pair → drop-off in lower 2 bits; second pair → drop-off in bits 4-5.
12937
+ return (globalIndex & 1 ? (byte >> 4) & 0x03 : byte & 0x03);
12938
+ }
12900
12939
  /**
12901
12940
  * Retrieves the departure time at a specific stop for a given trip.
12902
12941
  *
@@ -13396,6 +13435,12 @@ class Timetable {
13396
13435
  isActive(stopId) {
13397
13436
  return this.activeStops.has(stopId);
13398
13437
  }
13438
+ /**
13439
+ * Returns the total number of stops in the timetable.
13440
+ */
13441
+ nbStops() {
13442
+ return this.stopsAdjacency.length;
13443
+ }
13399
13444
  /**
13400
13445
  * Retrieves the route associated with the given route ID.
13401
13446
  *
@@ -13482,21 +13527,26 @@ class Timetable {
13482
13527
  */
13483
13528
  findReachableRoutes(fromStops, transportModes = ALL_TRANSPORT_MODES) {
13484
13529
  const reachableRoutes = new Map();
13485
- const fromStopsArray = Array.from(fromStops);
13486
- for (let i = 0; i < fromStopsArray.length; i++) {
13487
- const originStop = fromStopsArray[i];
13488
- const validRoutes = this.routesPassingThrough(originStop).filter((route) => {
13489
- const serviceRoute = this.getServiceRouteInfo(route);
13490
- return transportModes.has(serviceRoute.type);
13491
- });
13492
- for (let j = 0; j < validRoutes.length; j++) {
13493
- const route = validRoutes[j];
13494
- const originStopIndices = route.stopRouteIndices(originStop);
13495
- const originStopIndex = originStopIndices[0];
13530
+ // Skip the per-route mode check entirely when all modes are allowed,
13531
+ // which is the common case.
13532
+ const filterByMode = transportModes !== ALL_TRANSPORT_MODES;
13533
+ for (const originStop of fromStops) {
13534
+ const stopData = this.stopsAdjacency[originStop];
13535
+ if (!stopData)
13536
+ continue;
13537
+ for (let i = 0; i < stopData.routes.length; i++) {
13538
+ const route = this.routesAdjacency[stopData.routes[i]];
13539
+ if (!route)
13540
+ continue;
13541
+ if (filterByMode) {
13542
+ const serviceRoute = this.serviceRoutes[route.serviceRoute()];
13543
+ if (!serviceRoute || !transportModes.has(serviceRoute.type))
13544
+ continue;
13545
+ }
13546
+ const originStopIndex = route.stopRouteIndices(originStop)[0];
13496
13547
  const existingHopOnStopIndex = reachableRoutes.get(route);
13497
13548
  if (existingHopOnStopIndex !== undefined) {
13498
13549
  if (originStopIndex < existingHopOnStopIndex) {
13499
- // if the current stop is before the existing hop on stop, replace it
13500
13550
  reachableRoutes.set(route, originStopIndex);
13501
13551
  }
13502
13552
  }
@@ -13521,9 +13571,15 @@ class Timetable {
13521
13571
  if (!guaranteedTransfers) {
13522
13572
  return false;
13523
13573
  }
13524
- return guaranteedTransfers.some((transfer) => transfer.stopIndex === toTripStop.stopIndex &&
13525
- transfer.routeId === toTripStop.routeId &&
13526
- transfer.tripIndex === toTripStop.tripIndex);
13574
+ for (let i = 0; i < guaranteedTransfers.length; i++) {
13575
+ const transfer = guaranteedTransfers[i];
13576
+ if (transfer.stopIndex === toTripStop.stopIndex &&
13577
+ transfer.routeId === toTripStop.routeId &&
13578
+ transfer.tripIndex === toTripStop.tripIndex) {
13579
+ return true;
13580
+ }
13581
+ }
13582
+ return false;
13527
13583
  }
13528
13584
  /**
13529
13585
  * Retrieves all guaranteed trip transfer options available at the specified stop for a given trip.