File tree Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Expand file tree Collapse file tree 2 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import rotate from './rotate';
44import verifyOptimum from './verifyOptimum' ;
55import checkDelta2 from './checkDelta2' ;
66import checkDelta3 from './checkDelta3' ;
7+ import statistics from './statistics' ;
78
89// Adapted from http://jorisvr.nl/maximummatching.html
910// All credit for the implementation goes to Joris van Rantwijk [http://jorisvr.nl].
@@ -75,22 +76,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
7576 if ( edges . length === 0 ) return [ ] ;
7677
7778 // Count vertices + find the maximum edge weight.
78- const nedge = edges . length ;
79- let nvertex = 0 ;
80- let maxweight = 0 ;
81-
82- length = nedge ;
83- while ( length -- ) {
84- i = edges [ length ] [ 0 ] ;
85- j = edges [ length ] [ 1 ] ;
86- w = edges [ length ] [ 2 ] ;
87-
88- assert ( i >= 0 && j >= 0 && i !== j ) ;
89- if ( i >= nvertex ) nvertex = i + 1 ;
90- if ( j >= nvertex ) nvertex = j + 1 ;
91-
92- maxweight = Math . max ( maxweight , w ) ;
93- }
79+ const [ nvertex , nedge , maxweight ] = statistics ( edges ) ;
9480
9581 // If p is an edge endpoint,
9682 // endpoint[p] is the vertex to which endpoint p is attached.
Original file line number Diff line number Diff line change 1+ import assert from 'assert' ;
2+
3+ const statistics = ( edges ) => {
4+ const nedge = edges . length ;
5+ let nvertex = 0 ;
6+ let maxweight = 0 ;
7+
8+ let length = nedge ;
9+ while ( length -- ) {
10+ const i = edges [ length ] [ 0 ] ;
11+ const j = edges [ length ] [ 1 ] ;
12+ const w = edges [ length ] [ 2 ] ;
13+
14+ assert ( i >= 0 && j >= 0 && i !== j ) ;
15+ if ( i >= nvertex ) nvertex = i + 1 ;
16+ if ( j >= nvertex ) nvertex = j + 1 ;
17+
18+ maxweight = Math . max ( maxweight , w ) ;
19+ }
20+
21+ return [ nvertex , nedge , maxweight ] ;
22+ } ;
23+
24+ export default statistics ;
You can’t perform that action at this time.
0 commit comments