Skip to content

Commit

Permalink
👕 refactor: Lint sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 10, 2022
1 parent 1447156 commit 6d0d15e
Show file tree
Hide file tree
Showing 20 changed files with 521 additions and 463 deletions.
40 changes: 18 additions & 22 deletions doc/scripts/header.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
var domReady = function(callback) {
var state = document.readyState ;
if ( state === 'interactive' || state === 'complete' ) {
callback() ;
}
else {
const domReady = function (callback) {
const state = document.readyState;
if (state === 'interactive' || state === 'complete') {
callback();
} else {
document.addEventListener('DOMContentLoaded', callback);
}
} ;

};

domReady(function(){

var projectname = document.createElement('a');
domReady(function () {
const projectname = document.createElement('a');
projectname.classList.add('project-name');
projectname.text = 'union-find/contiguous';
projectname.href = './index.html' ;
projectname.href = './index.html';

var header = document.getElementsByTagName('header')[0] ;
header.insertBefore(projectname,header.firstChild);
const header = document.querySelectorAll('header')[0];
header.insertBefore(projectname, header.firstChild);

var testlink = document.querySelector('header > a[data-ice="testLink"]') ;
testlink.href = 'https://coveralls.io/github/union-find/contiguous' ;
testlink.target = '_BLANK' ;
const testlink = document.querySelector('header > a[data-ice="testLink"]');
testlink.href = 'https://coveralls.io/github/union-find/contiguous';
testlink.target = '_BLANK';

var searchBox = document.querySelector('.search-box');
var input = document.querySelector('.search-input');
const searchBox = document.querySelector('.search-box');
const input = document.querySelector('.search-input');

// active search box when focus on searchBox.
input.addEventListener('focus', function(){
// Active search box when focus on searchBox.
input.addEventListener('focus', function () {
searchBox.classList.add('active');
});

});
44 changes: 17 additions & 27 deletions src/adt/Forest.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
import { selfs } from '../fundamentals/index.js' ;
import {identity} from '../fundamentals/index.js';

export function union ( p , a , b ) {
export const union = (p, a, b) => {
p[find(p, b)] = find(p, a);

p[ find( p , b ) ] = find( p , a ) ;
return a;
};

return a ;
export const find = (p, x) => {
while (x !== p[x]) x = p[x];

}

export function find ( p , x ) {

while ( x !== p[x] ) x = p[x] ;

return x ;
return x;
};

export function Universe(n, List = Array) {
this.p = identity(n, List);
}

export function Universe ( n , List = Array ) {
this.p = selfs( n , List ) ;
}

Universe.prototype.union = function ( a , b ) {
return union( this.p , a , b ) ;
} ;

Universe.prototype.find = function ( x ) {
return find( this.p , x ) ;
} ;
Universe.prototype.union = function (a, b) {
return union(this.p, a, b);
};

export default {
Universe ,
union ,
find ,
} ;
Universe.prototype.find = function (x) {
return find(this.p, x);
};
30 changes: 10 additions & 20 deletions src/adt/ForestAmortizedHalving.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { rankedtreeunion , _RankedTreeUniverse } from '../fundamentals/index.js' ;
import {rankedtreeunion, _RankedTreeUniverse} from '../fundamentals/index.js';

export const union = rankedtreeunion ;
export const union = rankedtreeunion;

export function find ( p , node ) {

let parent = p[node] ;

for ( ; p[parent] !== parent ; parent = p[node] ) {

p[node] = p[parent] ;
node = p[node] ;
export const find = (p, node) => {
let parent = p[node];

for (; p[parent] !== parent; parent = p[node]) {
p[node] = p[parent];
node = p[node];
}

return parent ;

}

export const Universe = _RankedTreeUniverse( union , find ) ;
return parent;
};

export default {
Universe ,
union ,
find ,
} ;
export const Universe = _RankedTreeUniverse(union, find);
22 changes: 7 additions & 15 deletions src/adt/ForestAmortizedRecursive.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { rankedtreeunion , _RankedTreeUniverse } from '../fundamentals/index.js' ;
import {rankedtreeunion, _RankedTreeUniverse} from '../fundamentals/index.js';

export const union = rankedtreeunion ;
export const union = rankedtreeunion;

export function find ( p , node ) {
export const find = (p, node) => {
if (node !== p[node]) p[node] = find(p, p[node]);

if ( node !== p[node] ) p[node] = find( p , p[node] ) ;
return p[node];
};

return p[node] ;

}

export const Universe = _RankedTreeUniverse( union , find ) ;

export default {
Universe ,
union ,
find ,
} ;
export const Universe = _RankedTreeUniverse(union, find);
30 changes: 10 additions & 20 deletions src/adt/ForestAmortizedSplitting.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import { rankedtreeunion , _RankedTreeUniverse } from '../fundamentals/index.js' ;
import {rankedtreeunion, _RankedTreeUniverse} from '../fundamentals/index.js';

export const union = rankedtreeunion ;
export const union = rankedtreeunion;

export function find ( p , node ) {

let parent = p[node] ;

for ( ; p[parent] !== parent ; parent = p[node] ) {

p[node] = p[parent] ;
node = parent ;
export const find = (p, node) => {
let parent = p[node];

for (; p[parent] !== parent; parent = p[node]) {
p[node] = p[parent];
node = parent;
}

return parent ;

}

export const Universe = _RankedTreeUniverse( union , find ) ;
return parent;
};

export default {
Universe ,
union ,
find ,
} ;
export const Universe = _RankedTreeUniverse(union, find);
34 changes: 12 additions & 22 deletions src/adt/ForestAmortizedTwoPasses.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { rankedtreeunion , _RankedTreeUniverse } from '../fundamentals/index.js' ;
import {rankedtreeunion, _RankedTreeUniverse} from '../fundamentals/index.js';

export const union = rankedtreeunion ;
export const union = rankedtreeunion;

export function find ( p , node ) {
export const find = (p, node) => {
let it = node;

let it = node ;

for ( ; it !== p[it] ; it = p[it] ) ;

while ( p[node] !== it ) {

const parent = p[node] ;
p[node] = it ;
node = parent ;
for (; it !== p[it]; it = p[it]);

while (p[node] !== it) {
const parent = p[node];
p[node] = it;
node = parent;
}

return it ;

}

export const Universe = _RankedTreeUniverse( union , find ) ;
return it;
};

export default {
Universe ,
union ,
find ,
} ;
export const Universe = _RankedTreeUniverse(union, find);
48 changes: 19 additions & 29 deletions src/adt/LinkedList.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
import { selfs , nulls } from '../fundamentals/index.js' ;
import {identity, nulls} from '../fundamentals/index.js';

export function union ( back , next , a , b ) {
export const union = (back, next, a, b) => {
next[back[a]] = b;
back[a] = back[b];
return a;
};

next[back[a]] = b ;
back[a] = back[b] ;
return a ;
export const find = (next, node) => {
while (next[node] !== -1) node = next[node];

}

export function find ( next , node ) {

while ( next[node] !== -1 ) node = next[node] ;

return node ;
return node;
};

export function Universe(n, List = Array) {
this.back = identity(n, List);
this.next = nulls(n, List);
}

export function Universe ( n , List = Array ) {
this.back = selfs( n , List ) ;
this.next = nulls( n , List ) ;
}

Universe.prototype.union = function ( a , b ) {
return union( this.back , this.next , a , b ) ;
} ;

Universe.prototype.find = function ( node ) {
return find( this.next , node ) ;
} ;
Universe.prototype.union = function (a, b) {
return union(this.back, this.next, a, b);
};

export default {
Universe ,
union ,
find ,
} ;
Universe.prototype.find = function (node) {
return find(this.next, node);
};
42 changes: 17 additions & 25 deletions src/adt/LinkedListWithHead.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { selfs , nulls } from '../fundamentals/index.js' ;
import {identity, nulls} from '../fundamentals/index.js';

export function union ( back , next , a , b ) {
export const union = (back, next, a, b) => {
next[back[a]] = b;
back[a] = back[b];

next[back[a]] = b ;
back[a] = back[b] ;
for (let c = next[a]; c !== b; c = next[c]) back[c] = back[b];

for ( let c = next[a] ; c !== b ; c = next[c] ) back[c] = back[b] ;
return a;
};

return a ;
export const find = (back, node) => back[node];

export function Universe(n, List = Array) {
this.back = identity(n, List);
this.next = nulls(n, List);
}

export const find = ( back , node ) => back[node] ;
Universe.prototype.union = function (a, b) {
return union(this.back, this.next, a, b);
};

export function Universe ( n , List = Array) {
this.back = selfs( n , List ) ;
this.next = nulls( n , List ) ;
}

Universe.prototype.union = function ( a , b ) {
return union( this.back , this.next , a , b ) ;
} ;

Universe.prototype.find = function ( node ) {
return find( this.back , node ) ;
} ;

export default {
Universe ,
union ,
find ,
} ;
Universe.prototype.find = function (node) {
return find(this.back, node);
};
Loading

0 comments on commit 6d0d15e

Please sign in to comment.