Skip to content

Commit 7c96844

Browse files
♻️ refactor(blossom): Reduce use of counter variables.
1 parent def1ee5 commit 7c96844

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/core/blossom/blossom.js

+4-17
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
269269
// variable to zero; relabel its T-vertices to S and add them to the queue.
270270
const addBlossom = function (base, k) {
271271
let i;
272-
let j;
273-
let nblist;
274-
let nblists;
275272
let v = edges[k][0];
276273
let w = edges[k][1];
277274
const bb = inblossom[base];
@@ -359,33 +356,23 @@ export default function blossom(CHECK_OPTIMUM, CHECK_DELTA) {
359356

360357
const length_ = path.length;
361358
for (let z = 0; z < length_; ++z) {
359+
let nblists;
362360
bv = path[z];
363-
364361
if (blossombestedges[bv] === null) {
365362
// This subblossom does not have a list of least-slack edges;
366363
// get the information from the vertices.
367364
nblists = [];
368365
for (const v of blossomLeaves(nvertex, blossomchilds, bv)) {
369-
j = neighbend[v].length;
370-
const temporary_ = new Array(j);
371-
while (j--) {
372-
const p = neighbend[v][j];
373-
temporary_[j] = Math.floor(p / 2);
374-
}
375-
366+
const temporary_ = neighbend[v].map((p) => Math.floor(p / 2));
376367
nblists.push(temporary_);
377368
}
378369
} else {
379370
// Walk this subblossom's least-slack edges.
380371
nblists = [blossombestedges[bv]];
381372
}
382373

383-
for (let x = 0, m = nblists.length; x < m; ++x) {
384-
nblist = nblists[x];
385-
386-
for (let y = 0, n = nblist.length; y < n; ++y) {
387-
const k = nblist[y];
388-
374+
for (const nblist of nblists) {
375+
for (const k of nblist) {
389376
let i = edges[k][0];
390377
let j = edges[k][1];
391378

0 commit comments

Comments
 (0)