@@ -7,6 +7,7 @@ import checkDelta3 from './checkDelta3';
77import statistics from './statistics' ;
88import endpoints from './endpoints' ;
99import neighbours from './neighbours' ;
10+ import blossomLeaves from './blossomLeaves' ;
1011
1112// Adapted from http://jorisvr.nl/maximummatching.html
1213// All credit for the implementation goes to Joris van Rantwijk [http://jorisvr.nl].
@@ -193,23 +194,6 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
193194 return dualvar [ i ] + dualvar [ j ] - 2 * wt ;
194195 } ;
195196
196- // Generate the leaf vertices of a blossom.
197- const blossomLeaves = function ( b , fn ) {
198- if ( b < nvertex ) {
199- if ( fn ( b ) ) return true ;
200- } else {
201- let i ;
202- let t ;
203- const length_ = blossomchilds [ b ] . length ;
204- for ( i = 0 ; i < length_ ; ++ i ) {
205- t = blossomchilds [ b ] [ i ] ;
206- if ( t < nvertex ) {
207- if ( fn ( t ) ) return true ;
208- } else if ( blossomLeaves ( t , fn ) ) return true ;
209- }
210- }
211- } ;
212-
213197 // Assign label t to the top-level blossom containing vertex w
214198 // and record the fact that w was reached through the edge with
215199 // remote endpoint p.
@@ -225,7 +209,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
225209 bestedge [ b ] = - 1 ;
226210 if ( t === 1 ) {
227211 // B became an S-vertex/blossom; add it(s vertices) to the queue.
228- blossomLeaves ( b , function ( v ) {
212+ blossomLeaves ( nvertex , blossomchilds , b , function ( v ) {
229213 queue . push ( v ) ;
230214 } ) ;
231215 console . debug ( 'DEBUG: PUSH ' + queue ) ;
@@ -379,7 +363,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
379363 // Set dual variable to zero.
380364 dualvar [ b ] = 0 ;
381365 // Relabel vertices.
382- blossomLeaves ( b , function ( v ) {
366+ blossomLeaves ( nvertex , blossomchilds , b , function ( v ) {
383367 if ( label [ inblossom [ v ] ] === 2 ) {
384368 // This T-vertex now turns into an S-vertex because it becomes
385369 // part of an S-blossom; add it to the queue.
@@ -403,7 +387,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
403387 // This subblossom does not have a list of least-slack edges;
404388 // get the information from the vertices.
405389 nblists = [ ] ;
406- blossomLeaves ( bv , function ( v ) {
390+ blossomLeaves ( nvertex , blossomchilds , bv , function ( v ) {
407391 j = neighbend [ v ] . length ;
408392 temporary_ = new Array ( j ) ;
409393 while ( j -- ) {
@@ -499,7 +483,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
499483 // Recursively expand this sub-blossom.
500484 expandBlossom ( s , endstage ) ;
501485 } else {
502- blossomLeaves ( s , function ( v ) {
486+ blossomLeaves ( nvertex , blossomchilds , s , function ( v ) {
503487 inblossom [ v ] = s ;
504488 } ) ;
505489 }
@@ -569,7 +553,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
569553 continue ;
570554 }
571555
572- blossomLeaves ( bv , function ( v ) {
556+ blossomLeaves ( nvertex , blossomchilds , bv , function ( v ) {
573557 if ( label [ v ] !== 0 ) {
574558 // If the sub-blossom contains a reachable vertex, assign
575559 // label T to the sub-blossom.
@@ -875,7 +859,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
875859 nvertex,
876860 edges,
877861 blossomparent,
878- blossomLeaves ,
862+ blossomchilds ,
879863 neighbend,
880864 label,
881865 endpoint,
0 commit comments