@@ -103,9 +103,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
103
103
// mate[v] is the remote endpoint of its matched edge, or -1 if it is single
104
104
// (i.e. endpoint[mate[v]] is v's partner vertex).
105
105
// Initially all vertices are single; updated during augmentation.
106
- i = nvertex ;
107
- const mate = new Array ( i ) ;
108
- while ( i -- ) mate [ i ] = - 1 ;
106
+ const mate = new Array ( nvertex ) . fill ( - 1 ) ;
109
107
110
108
// If b is a top-level blossom,
111
109
// label[b] is 0 if b is unlabeled (free);
@@ -116,19 +114,15 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
116
114
// If v is a vertex inside a T-blossom,
117
115
// label[v] is 2 iff v is reachable from an S-vertex outside the blossom.
118
116
// Labels are assigned during a stage and reset after each augmentation.
119
- i = 2 * nvertex ;
120
- const label = new Array ( i ) ;
121
- while ( i -- ) label [ i ] = 0 ;
117
+ const label = new Array ( 2 * nvertex ) . fill ( 0 ) ;
122
118
123
119
// If b is a labeled top-level blossom,
124
120
// labelend[b] is the remote endpoint of the edge through which b obtained
125
121
// its label, or -1 if b's base vertex is single.
126
122
// If v is a vertex inside a T-blossom and label[v] === 2,
127
123
// labelend[v] is the remote endpoint of the edge through which v is
128
124
// reachable from outside the blossom.
129
- i = 2 * nvertex ;
130
- const labelend = new Array ( i ) ;
131
- while ( i -- ) labelend [ i ] = - 1 ;
125
+ const labelend = new Array ( 2 * nvertex ) . fill ( - 1 ) ;
132
126
133
127
// If v is a vertex,
134
128
// inblossom[v] is the top-level blossom to which v belongs.
@@ -142,16 +136,12 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
142
136
// If b is a sub-blossom,
143
137
// blossomparent[b] is its immediate parent (sub-)blossom.
144
138
// If b is a top-level blossom, blossomparent[b] is -1.
145
- i = 2 * nvertex ;
146
- const blossomparent = new Array ( i ) ;
147
- while ( i -- ) blossomparent [ i ] = - 1 ;
139
+ const blossomparent = new Array ( 2 * nvertex ) . fill ( - 1 ) ;
148
140
149
141
// If b is a non-trivial (sub-)blossom,
150
142
// blossomchilds[b] is an ordered list of its sub-blossoms, starting with
151
143
// the base and going round the blossom.
152
- i = 2 * nvertex ;
153
- const blossomchilds = new Array ( i ) ;
154
- while ( i -- ) blossomchilds [ i ] = null ;
144
+ const blossomchilds = new Array ( 2 * nvertex ) . fill ( null ) ;
155
145
156
146
// If b is a (sub-)blossom,
157
147
// blossombase[b] is its base VERTEX (i.e. recursive sub-blossom).
@@ -164,9 +154,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
164
154
// blossomendps[b] is a list of endpoints on its connecting edges,
165
155
// such that blossomendps[b][i] is the local endpoint of blossomchilds[b][i]
166
156
// on the edge that connects it to blossomchilds[b][wrap(i+1)].
167
- i = 2 * nvertex ;
168
- const blossomendps = new Array ( i ) ;
169
- while ( i -- ) blossomendps [ i ] = null ;
157
+ const blossomendps = new Array ( 2 * nvertex ) . fill ( null ) ;
170
158
171
159
// If v is a free vertex (or an unreached vertex inside a T-blossom),
172
160
// bestedge[v] is the edge to an S-vertex with least slack,
@@ -175,17 +163,13 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
175
163
// bestedge[b] is the least-slack edge to a different S-blossom,
176
164
// or -1 if there is no such edge.
177
165
// This is used for efficient computation of delta2 and delta3.
178
- i = 2 * nvertex ;
179
- const bestedge = new Array ( i ) ;
180
- while ( i -- ) bestedge [ i ] = - 1 ;
166
+ const bestedge = new Array ( 2 * nvertex ) . fill ( - 1 ) ;
181
167
182
168
// If b is a non-trivial top-level S-blossom,
183
169
// blossombestedges[b] is a list of least-slack edges to neighbouring
184
170
// S-blossoms, or null if no such list has been computed yet.
185
171
// This is used for efficient computation of delta3.
186
- i = 2 * nvertex ;
187
- const blossombestedges = new Array ( i ) ;
188
- while ( i -- ) blossombestedges [ i ] = null ;
172
+ const blossombestedges = new Array ( 2 * nvertex ) . fill ( null ) ;
189
173
190
174
// List of currently unused blossom numbers.
191
175
i = nvertex ;
@@ -207,9 +191,7 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
207
191
// If allowedge[k] is true, edge k has zero slack in the optimization
208
192
// problem; if allowedge[k] is false, the edge's slack may or may not
209
193
// be zero.
210
- i = nedge ;
211
- const allowedge = new Array ( i ) ;
212
- while ( i -- ) allowedge [ i ] = false ;
194
+ const allowedge = new Array ( nedge ) . fill ( false ) ;
213
195
214
196
// Queue of newly discovered S-vertices.
215
197
let queue = [ ] ;
@@ -774,19 +756,15 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
774
756
console . debug ( 'DEBUG: STAGE ' + t ) ;
775
757
776
758
// Remove labels from top-level blossoms/vertices.
777
- i = 2 * nvertex ;
778
- while ( i -- ) label [ i ] = 0 ;
759
+ label . fill ( 0 ) ;
779
760
780
761
// Forget all about least-slack edges.
781
- i = 2 * nvertex ;
782
- while ( i -- ) bestedge [ i ] = - 1 ;
783
- i = nvertex ;
784
- while ( i -- ) blossombestedges [ nvertex + i ] = null ;
762
+ bestedge . fill ( - 1 ) ;
763
+ blossombestedges . fill ( null , nvertex , 2 * nvertex ) ;
785
764
786
765
// Loss of labeling means that we can not be sure that currently
787
766
// allowable edges remain allowable througout this stage.
788
- i = nedge ;
789
- while ( i -- ) allowedge [ i ] = false ;
767
+ allowedge . fill ( false ) ;
790
768
791
769
// Make queue empty.
792
770
queue = [ ] ;
0 commit comments