Skip to content

Commit b8616a6

Browse files
MapFABuilder: Removed kind constructor argument
1 parent 02552b9 commit b8616a6

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

src/intersection.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export function getIntersectionIterator<L, R>(
2222
): TransitionIterator<MapFABuilderNode> {
2323
MaxCharacterError.assert(left, right, "TransitionIterable");
2424

25-
const builder = new Iter.MapFABuilder(options?.maxNodes ?? 10_000, "intersection operation");
26-
27-
return Iter.intersection(builder, left.transitionIterator(), right.transitionIterator());
25+
return Iter.intersection(
26+
new Iter.MapFABuilder(options?.maxNodes ?? 10_000),
27+
left.transitionIterator(),
28+
right.transitionIterator()
29+
);
2830
}
2931

3032
/**

src/iter/map-fa-builder.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,17 @@ import { CharSet } from "../char-set";
22
import { FABuilder } from "../fa-types";
33
import { TooManyNodesError } from "../errors";
44

5-
interface Limit {
6-
current: number;
7-
readonly maxNodes: number;
8-
readonly kind: string;
9-
}
10-
115
/**
126
* An FA builder that uses `Map` objects as nodes. Each node is the map of its outgoing transitions.
137
*/
148
export class MapFABuilder implements FABuilder<MapFABuilderNode, CharSet> {
15-
private readonly _limit: Limit | undefined;
9+
private readonly _limit: number;
10+
private _counter = 0;
1611
readonly initial: MapFABuilderNode = new Map();
1712
readonly finals = new Set<MapFABuilderNode>();
1813

19-
constructor(maxNodes: number = Infinity, kind?: string) {
20-
if (maxNodes < Infinity) {
21-
this._limit = { current: 0, maxNodes, kind: kind ?? "MapFABuilder" };
22-
}
14+
constructor(maxNodes: number = Infinity) {
15+
this._limit = maxNodes;
2316
}
2417

2518
makeFinal(state: MapFABuilderNode): void {
@@ -29,10 +22,7 @@ export class MapFABuilder implements FABuilder<MapFABuilderNode, CharSet> {
2922
return this.finals.has(state);
3023
}
3124
createNode(): MapFABuilderNode {
32-
const limit = this._limit;
33-
if (limit) {
34-
TooManyNodesError.assert(++limit.current, limit.maxNodes, limit.kind);
35-
}
25+
TooManyNodesError.assert(++this._counter, this._limit, "MapFABuilder");
3626

3727
return new Map();
3828
}

0 commit comments

Comments
 (0)