Skip to content

Commit 4039edf

Browse files
committed
fix: consume row pairs when the prefilter does not match.
1 parent abcbf43 commit 4039edf

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

typescript/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "covertable",
3-
"version": "2.5.1",
3+
"version": "2.5.2",
44
"description": "A flexible pairwise tool written in TypeScript",
55
"homepage": "https://docs.walkframe.com/covertable",
66
"repository": {

typescript/src/controller.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ export class Controller<T extends FactorsType> {
131131
this.row.consumed.set(pairKey, pair);
132132
}
133133
}
134+
public consumeRow(row: Row) {
135+
for (let pair of combinations([...row.values()], this.pairwiseCount)) {
136+
this.consume(pair);
137+
}
138+
}
134139

135140
public getCandidate(pair: PairType) {
136141
return getCandidate(pair, this.parents);
@@ -156,6 +161,7 @@ export class Controller<T extends FactorsType> {
156161
try {
157162
const ok = this.options.preFilter(proxy);
158163
if (!ok) {
164+
this.consumeRow(nxt);
159165
return null;
160166
}
161167
} catch (e) {
@@ -206,7 +212,8 @@ export class Controller<T extends FactorsType> {
206212
}
207213

208214
private discard() {
209-
this.rejected.add(this.row.getPairKey());
215+
const pairKey = this.row.getPairKey();
216+
this.rejected.add(pairKey);
210217
this.row = new Row([]);
211218
}
212219

@@ -268,7 +275,7 @@ export class Controller<T extends FactorsType> {
268275
}
269276
const proxy = this.toProxy(this.row);
270277
try {
271-
return this.options.preFilter ? this.options.preFilter(proxy) : true;
278+
return this.options.preFilter?.(proxy) ?? true;
272279
} catch (e) {
273280
if (e instanceof NotReady) {
274281
return false;
@@ -284,7 +291,7 @@ export class Controller<T extends FactorsType> {
284291
return 1 - this.incomplete.size / this.numAllChunks;
285292
}
286293

287-
public *makeAsync<T extends FactorsType>(): Generator<SuggestRowType<T>, void, unknown> {
294+
public *makeAsync<T extends FactorsType>() {
288295
const {criterion = greedy, postFilter} = this.options;
289296
do {
290297
for (let pair of criterion(this)) {
@@ -309,5 +316,6 @@ export class Controller<T extends FactorsType> {
309316
throw e;
310317
}
311318
} while (this.incomplete.size);
319+
this.incomplete.clear();
312320
}
313321
}

typescript/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Controller } from "./controller";
1212
const makeAsync = function* <T extends FactorsType>(
1313
factors: T,
1414
options: OptionsType<T> = {}
15-
): Generator<SuggestRowType<T>, void, unknown> {
15+
) {
1616
const ctrl = new Controller(factors, options);
1717
yield* ctrl.makeAsync();
1818
};

0 commit comments

Comments
 (0)