Skip to content

Commit 6524d40

Browse files
👕 refactor: Lint all JavaScript files.
1 parent 4c82729 commit 6524d40

File tree

12 files changed

+118
-128
lines changed

12 files changed

+118
-128
lines changed

doc/scripts/header.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
1-
var domReady = function(callback) {
2-
var state = document.readyState ;
3-
if ( state === 'interactive' || state === 'complete' ) {
4-
callback() ;
5-
}
6-
else {
1+
const domReady = function (callback) {
2+
const state = document.readyState;
3+
if (state === 'interactive' || state === 'complete') {
4+
callback();
5+
} else {
76
document.addEventListener('DOMContentLoaded', callback);
87
}
9-
} ;
10-
8+
};
119

12-
domReady(function(){
13-
14-
var projectname = document.createElement('a');
10+
domReady(() => {
11+
const projectname = document.createElement('a');
1512
projectname.classList.add('project-name');
1613
projectname.text = 'aureooms/js-mincut';
17-
projectname.href = './index.html' ;
14+
projectname.href = './index.html';
1815

19-
var header = document.getElementsByTagName('header')[0] ;
20-
header.insertBefore(projectname,header.firstChild);
16+
const header = document.querySelectorAll('header')[0];
17+
header.insertBefore(projectname, header.firstChild);
2118

22-
var testlink = document.querySelector('header > a[data-ice="testLink"]') ;
23-
testlink.href = 'https://coveralls.io/github/aureooms/js-mincut' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href = 'https://coveralls.io/github/aureooms/js-mincut';
21+
testlink.target = '_BLANK';
2522

26-
var searchBox = document.querySelector('.search-box');
27-
var input = document.querySelector('.search-input');
23+
const searchBox = document.querySelector('.search-box');
24+
const input = document.querySelector('.search-input');
2825

29-
// active search box when focus on searchBox.
30-
input.addEventListener('focus', function(){
26+
// Active search box when focus on searchBox.
27+
input.addEventListener('focus', () => {
3128
searchBox.classList.add('active');
3229
});
33-
3430
});

src/adj.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
21
/**
32
* Constructs the adjacency list for an undirected unweighted connected
43
* loopless multigraph G given as a list of edges.
54
*
65
* @param {Iterable} edges The edges of G.
76
* @returns {Map} The adjacency list G.
87
*/
9-
export default function adj ( edges ) {
8+
export default function adj(edges) {
109
const G = new Map();
11-
for ( const [ u , v ] of edges ) {
12-
if ( !G.has(u) ) G.set(u, []) ;
10+
for (const [u, v] of edges) {
11+
if (!G.has(u)) G.set(u, []);
1312
G.get(u).push(v);
14-
if ( !G.has(v) ) G.set(v, []) ;
13+
if (!G.has(v)) G.set(v, []);
1514
G.get(v).push(u);
1615
}
16+
1717
return G;
1818
}

src/index.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import adj from "./adj.js" ;
2-
import maxback from "./maxback/index.js" ;
3-
import mincut from "./mincut.js" ;
1+
import adj from './adj.js';
2+
import maxback from './maxback/index.js';
3+
import mincut from './mincut.js';
44

5-
export default mincut ;
5+
export default mincut;
66

7-
export {
8-
adj ,
9-
maxback ,
10-
mincut ,
11-
} ;
7+
export {adj, maxback, mincut};

src/maxback/_contract.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { head } from '@aureooms/js-itertools' ;
1+
import {head} from '@aureooms/js-itertools';
22

33
/**
44
* Given G and some ordering, computes the graph H obtained from G by
@@ -8,26 +8,24 @@ import { head } from '@aureooms/js-itertools' ;
88
* @param {Array} ordering
99
* @returns {Map}
1010
*/
11-
export default function _contract ( G, ordering ) {
12-
13-
const u = ordering[ordering.length-2];
14-
const v = ordering[ordering.length-1];
11+
export default function _contract(G, ordering) {
12+
const u = ordering[ordering.length - 2];
13+
const v = ordering[ordering.length - 1];
1514

1615
const H = new Map();
1716

18-
// replace each edge xv by the edge xu, x != u ^ x != v
19-
for ( const x of head( ordering , -2 ) ) {
17+
// Replace each edge xv by the edge xu, x != u ^ x != v
18+
for (const x of head(ordering, -2)) {
2019
const n = [];
2120
H.set(x, n);
22-
for ( const y of G.get(x) ) n.push(y === v ? u : y);
21+
for (const y of G.get(x)) n.push(y === v ? u : y);
2322
}
2423

2524
const nx = [];
26-
H.set(u,nx);
27-
// keep all edges ux with, x != v (x != u is implied because G is loopless)
28-
for ( const x of G.get(u) ) if ( x !== v ) nx.push(x);
29-
// replace each edge vx by the edge ux, x != u ^ x != v
30-
for ( const x of G.get(v) ) if ( x !== u && x !== v ) nx.push(x);
25+
H.set(u, nx);
26+
// Keep all edges ux with, x != v (x != u is implied because G is loopless)
27+
for (const x of G.get(u)) if (x !== v) nx.push(x);
28+
// Replace each edge vx by the edge ux, x != u ^ x != v
29+
for (const x of G.get(v)) if (x !== u && x !== v) nx.push(x);
3130
return H;
32-
3331
}

src/maxback/_order.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { attr , decreasing } from '@aureooms/js-compare' ;
2-
import { PairingHeap } from '@aureooms/js-pairing-heap' ;
1+
import {attr, decreasing} from '@aureooms/js-compare';
2+
import {PairingHeap} from '@aureooms/js-pairing-heap';
33

44
/**
55
* Lists the vertices of an undirected unweighted connected loopless multigraph
@@ -8,31 +8,28 @@ import { PairingHeap } from '@aureooms/js-pairing-heap' ;
88
* @param {Map} G The adjacency list of G.
99
* @returns {Iterable} The vertices of G in max-back order.
1010
*/
11-
export default function* _order ( G ) {
12-
13-
const heap = new PairingHeap( attr( decreasing , 'weight' ) );
11+
export default function* _order(G) {
12+
const heap = new PairingHeap(attr(decreasing, 'weight'));
1413
const refs = new Map();
1514

16-
for ( const v of G.keys() ) refs.set(v, heap.push({ weight : 0 , vertex : v })) ;
17-
18-
for ( const _ of G ) {
15+
for (const v of G.keys()) refs.set(v, heap.push({weight: 0, vertex: v}));
1916

20-
const max = heap.pop() ;
21-
const u = max.vertex ;
22-
yield [ u , max.weight ] ;
17+
// eslint-disable-next-line no-unused-vars
18+
for (const _ of G) {
19+
const max = heap.pop();
20+
const u = max.vertex;
21+
yield [u, max.weight];
2322
refs.delete(u);
2423

25-
// update keys
26-
for ( const v of G.get(u) ) {
24+
// Update keys
25+
for (const v of G.get(u)) {
2726
if (!refs.has(v)) continue;
2827
const ref = refs.get(v);
29-
// max heap so decrease-weight is used for +
28+
// Max heap so decrease-weight is used for +
3029
heap.decreasekey(ref, {
31-
weight : ref.value.weight + 1 ,
32-
vertex : ref.value.vertex
33-
} );
30+
weight: ref.value.weight + 1,
31+
vertex: ref.value.vertex,
32+
});
3433
}
35-
3634
}
37-
3835
}

src/maxback/_smallcuts.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { list , map , head , filter , chain } from '@aureooms/js-itertools' ;
1+
import {list, map} from '@aureooms/js-itertools';
22

3-
import _order from "./_order.js" ;
4-
import _contract from "./_contract.js" ;
3+
import _order from './_order.js';
4+
import _contract from './_contract.js';
55

66
/**
77
* Yields the small cuts of undirected unweighted connected loopless multigraph G.
@@ -10,24 +10,20 @@ import _contract from "./_contract.js" ;
1010
* @param {Map} G The adjacency list of G.
1111
* @returns {Iterable} The small cuts of G.
1212
*/
13-
export default function* _smallcuts ( G ) {
14-
13+
export default function* _smallcuts(G) {
1514
let H = G;
1615
const id = new Map();
17-
for ( const v of G.keys()) id.set(v,[v]);
18-
19-
while ( H.size >= 2 ) {
16+
for (const v of G.keys()) id.set(v, [v]);
2017

21-
const ordering = list(_order(H)); // compute the max-back order
22-
const [ x ] = ordering[ordering.length-2];
23-
const [ y , cutsize ] = ordering[ordering.length-1];
18+
while (H.size >= 2) {
19+
const ordering = list(_order(H)); // Compute the max-back order
20+
const [x] = ordering[ordering.length - 2];
21+
const [y, cutsize] = ordering[ordering.length - 1];
2422

25-
yield [ new Set(id.get(y)) , cutsize ] ; // yield a small cut with its size
23+
yield [new Set(id.get(y)), cutsize]; // Yield a small cut with its size
2624

27-
id.set(x, id.get(x).concat(id.get(y))); // associate the last vertex with the penultimate one
28-
29-
H = _contract(H, list(map(([u,_]) => u , ordering))); // contract all edges between those two vertices
25+
id.set(x, id.get(x).concat(id.get(y))); // Associate the last vertex with the penultimate one
3026

27+
H = _contract(H, list(map(([u, _]) => u, ordering))); // Contract all edges between those two vertices
3128
}
32-
3329
}

src/maxback/index.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import _contract from "./_contract.js" ;
2-
import _order from "./_order.js" ;
3-
import _smallcuts from "./_smallcuts.js" ;
4-
import maxback from "./maxback.js" ;
5-
import mb from "./mb.js" ;
1+
import _contract from './_contract.js';
2+
import _order from './_order.js';
3+
import _smallcuts from './_smallcuts.js';
4+
import maxback from './maxback.js';
5+
import mb from './mb.js';
66

7-
export default maxback ;
7+
export default maxback;
88

9-
export {
10-
_contract ,
11-
_order ,
12-
_smallcuts ,
13-
maxback ,
14-
mb ,
15-
} ;
9+
export {_contract, _order, _smallcuts, maxback, mb};

src/maxback/maxback.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import adj from "../adj.js";
2-
import mb from "./mb.js";
3-
import outgoingedges from "../outgoingedges.js";
1+
import adj from '../adj.js';
2+
import mb from './mb.js';
3+
import outgoingedges from '../outgoingedges.js';
44

55
/**
66
* Convenience wrapper around Nagamochi-Ibaraki poly-time algorithm.
77
*
88
* @param {Iterable} edges List of edges of an undirected unweighted connected loopless multigraph G.
99
* @returns {Iterable} An iterable over the edges of a minimum cut of G.
1010
*/
11-
export default function maxback ( edges ) {
12-
const G = adj( edges ) ;
13-
const [ U ] = mb( G ) ;
14-
return outgoingedges( G , U ) ;
11+
export default function maxback(edges) {
12+
const G = adj(edges);
13+
const [U] = mb(G);
14+
return outgoingedges(G, U);
1515
}

src/maxback/mb.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { min } from '@aureooms/js-itertools' ;
2-
import { attr , increasing } from '@aureooms/js-compare' ;
1+
import {min} from '@aureooms/js-itertools';
2+
import {attr, increasing} from '@aureooms/js-compare';
33

4-
import _smallcuts from "./_smallcuts.js" ;
4+
import _smallcuts from './_smallcuts.js';
55

66
/**
77
* Nagamochi-Ibaraki poly-time algorithm.
88
*
99
* @param {Map} G The adjacency list of an undirected unweighted connected loopless multigraph G.
1010
* @returns {Array} A pair <code>[U,cutsize]</code> reprensenting a minimum cut of G.
1111
*/
12-
export default function mb ( G ) {
13-
return min( attr( increasing , 1 ) , _smallcuts(G) , undefined ) ;
12+
export default function mb(G) {
13+
return min(attr(increasing, 1), _smallcuts(G), undefined);
1414
}

src/mincut.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import maxback from "./maxback/index.js" ;
1+
import maxback from './maxback/index.js';
22

33
/**
44
* Default to the maxback algorithm.
55
*/
6-
export default maxback ;
6+
export default maxback;

src/outgoingedges.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* @param {Set} U The subset of edges.
88
* @returns {Iterable} The edges of G going from U to V(G) \ U.
99
*/
10-
export default function* outgoingedges ( G , U ) {
11-
for ( const u of U ) {
12-
for ( const v of G.get(u) ) {
13-
if ( !U.has(v) ) yield [ u , v ] ;
10+
export default function* outgoingedges(G, U) {
11+
for (const u of U) {
12+
for (const v of G.get(u)) {
13+
if (!U.has(v)) yield [u, v];
1414
}
1515
}
1616
}

test/src/mincut.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1-
import test from 'ava' ;
2-
import { list , map , sorted } from '@aureooms/js-itertools' ;
3-
import { increasing , fixedlexicographical } from '@aureooms/js-compare' ;
4-
import mincut from "../../src/index.js" ;
1+
import test from 'ava';
2+
import {map, sorted} from '@aureooms/js-itertools';
3+
import {increasing, fixedlexicographical} from '@aureooms/js-compare';
4+
import mincut from '../../src/index.js';
55

6-
function order ( edge ) {
7-
return sorted( increasing , edge ) ;
6+
function order(edge) {
7+
return sorted(increasing, edge);
88
}
99

10-
function sort ( edges ) {
11-
return sorted( fixedlexicographical( increasing , 2 ) , map( order , edges ) ) ;
10+
function sort(edges) {
11+
return sorted(fixedlexicographical(increasing, 2), map(order, edges));
1212
}
1313

14-
function macro ( t , edges , expected ) {
14+
function macro(t, edges, expected) {
1515
const cut = mincut(edges);
1616
t.deepEqual(sort(cut), sort(expected));
1717
}
1818

19-
macro.title = title => title ;
19+
macro.title = (title) => title;
2020

2121
// 0--1
22-
test( 'single' , macro , [[0,1]] , [[0,1]] ) ;
22+
test('single', macro, [[0, 1]], [[0, 1]]);
2323

2424
// 5 2
2525
// |\ /|
2626
// | 0--1 |
2727
// |/ \|
2828
// 4 3
29-
test( 'butterfly' , macro , [[0,1],[1,2],[1,3],[2,3],[0,4],[0,5],[4,5]] , [[0,1]] ) ;
29+
test(
30+
'butterfly',
31+
macro,
32+
[
33+
[0, 1],
34+
[1, 2],
35+
[1, 3],
36+
[2, 3],
37+
[0, 4],
38+
[0, 5],
39+
[4, 5],
40+
],
41+
[[0, 1]],
42+
);

0 commit comments

Comments
 (0)