@@ -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}
0 commit comments