minotor 12.0.0 → 12.0.1
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 +3 -9
- package/dist/cli/perf.d.ts +15 -5
- package/dist/cli.mjs +129 -117
- package/dist/cli.mjs.map +1 -1
- package/dist/parser.cjs.js +37 -19
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.esm.js +37 -19
- package/dist/parser.esm.js.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/routing/state.d.ts +2 -2
- package/dist/stops/stopsIndex.d.ts +1 -1
- package/dist/timetable/route.d.ts +2 -0
- package/package.json +2 -2
- package/src/cli/minotor.ts +19 -2
- package/src/cli/perf.ts +94 -107
- package/src/routing/__tests__/state.test.ts +29 -0
- package/src/routing/state.ts +11 -3
- package/src/stops/__tests__/stopFinder.test.ts +13 -0
- package/src/stops/stopsIndex.ts +13 -19
- package/src/timetable/__tests__/io.test.ts +27 -0
- package/src/timetable/__tests__/route.test.ts +30 -0
- package/src/timetable/io.ts +15 -1
- package/src/timetable/route.ts +19 -5
- package/src/timetable/timetable.ts +1 -1
package/src/timetable/route.ts
CHANGED
|
@@ -85,7 +85,7 @@ export class Route {
|
|
|
85
85
|
* ...
|
|
86
86
|
* }
|
|
87
87
|
*/
|
|
88
|
-
private readonly stopIndices: Map<StopId, StopRouteIndex[]>;
|
|
88
|
+
private readonly stopIndices: Map<StopId, StopRouteIndex | StopRouteIndex[]>;
|
|
89
89
|
/**
|
|
90
90
|
* The identifier of the route as a service shown to users.
|
|
91
91
|
*/
|
|
@@ -115,15 +115,17 @@ export class Route {
|
|
|
115
115
|
this.serviceRouteId = serviceRouteId;
|
|
116
116
|
this.nbStops = stops.length;
|
|
117
117
|
this.nbTrips = this.stopTimes.length / (this.stops.length * 2);
|
|
118
|
-
this.stopIndices = new Map<StopId, StopRouteIndex[]>();
|
|
118
|
+
this.stopIndices = new Map<StopId, StopRouteIndex | StopRouteIndex[]>();
|
|
119
119
|
for (let i = 0; i < stops.length; i++) {
|
|
120
120
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
121
121
|
const stopId = stops[i]!;
|
|
122
122
|
const existingIndices = this.stopIndices.get(stopId);
|
|
123
|
-
if (existingIndices) {
|
|
124
|
-
|
|
123
|
+
if (existingIndices === undefined) {
|
|
124
|
+
this.stopIndices.set(stopId, i);
|
|
125
|
+
} else if (typeof existingIndices === 'number') {
|
|
126
|
+
this.stopIndices.set(stopId, [existingIndices, i]);
|
|
125
127
|
} else {
|
|
126
|
-
|
|
128
|
+
existingIndices.push(i);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
}
|
|
@@ -471,9 +473,21 @@ export class Route {
|
|
|
471
473
|
if (stopIndex === undefined) {
|
|
472
474
|
return [];
|
|
473
475
|
}
|
|
476
|
+
if (typeof stopIndex === 'number') {
|
|
477
|
+
// Preserve stable, mutable array results for callers that request all indices.
|
|
478
|
+
const indices = [stopIndex];
|
|
479
|
+
this.stopIndices.set(stopId, indices);
|
|
480
|
+
return indices;
|
|
481
|
+
}
|
|
474
482
|
return stopIndex;
|
|
475
483
|
}
|
|
476
484
|
|
|
485
|
+
/** Returns the first occurrence without allocating an array. */
|
|
486
|
+
public firstStopRouteIndex(stopId: StopId): StopRouteIndex | undefined {
|
|
487
|
+
const indices = this.stopIndices.get(stopId);
|
|
488
|
+
return typeof indices === 'number' ? indices : indices?.[0];
|
|
489
|
+
}
|
|
490
|
+
|
|
477
491
|
/**
|
|
478
492
|
* Retrieves the id of a stop at a given index in a route.
|
|
479
493
|
* @param stopRouteIndex The route index of the stop.
|
|
@@ -300,7 +300,7 @@ export class Timetable {
|
|
|
300
300
|
if (!serviceRoute || !transportModes.has(serviceRoute.type)) continue;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
const originStopIndex = route.
|
|
303
|
+
const originStopIndex = route.firstStopRouteIndex(originStop)!;
|
|
304
304
|
const existingHopOnStopIndex = reachableRoutes.get(route);
|
|
305
305
|
if (existingHopOnStopIndex !== undefined) {
|
|
306
306
|
if (originStopIndex < existingHopOnStopIndex) {
|