diff --git a/doc/scripts/header.js b/doc/scripts/header.js index d31b912..f8d1e33 100644 --- a/doc/scripts/header.js +++ b/doc/scripts/header.js @@ -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'); }); - }); diff --git a/src/adt/Forest.js b/src/adt/Forest.js index f74576a..3276751 100644 --- a/src/adt/Forest.js +++ b/src/adt/Forest.js @@ -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); +}; diff --git a/src/adt/ForestAmortizedHalving.js b/src/adt/ForestAmortizedHalving.js index 82abcf2..e9722d5 100644 --- a/src/adt/ForestAmortizedHalving.js +++ b/src/adt/ForestAmortizedHalving.js @@ -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); diff --git a/src/adt/ForestAmortizedRecursive.js b/src/adt/ForestAmortizedRecursive.js index 1ef0086..1fc176a 100644 --- a/src/adt/ForestAmortizedRecursive.js +++ b/src/adt/ForestAmortizedRecursive.js @@ -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); diff --git a/src/adt/ForestAmortizedSplitting.js b/src/adt/ForestAmortizedSplitting.js index 51f0d63..1970bc9 100644 --- a/src/adt/ForestAmortizedSplitting.js +++ b/src/adt/ForestAmortizedSplitting.js @@ -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); diff --git a/src/adt/ForestAmortizedTwoPasses.js b/src/adt/ForestAmortizedTwoPasses.js index 18bf314..a984ada 100644 --- a/src/adt/ForestAmortizedTwoPasses.js +++ b/src/adt/ForestAmortizedTwoPasses.js @@ -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); diff --git a/src/adt/LinkedList.js b/src/adt/LinkedList.js index a8bf6a6..2a20f88 100644 --- a/src/adt/LinkedList.js +++ b/src/adt/LinkedList.js @@ -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); +}; diff --git a/src/adt/LinkedListWithHead.js b/src/adt/LinkedListWithHead.js index 64b5230..af5defc 100644 --- a/src/adt/LinkedListWithHead.js +++ b/src/adt/LinkedListWithHead.js @@ -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); +}; diff --git a/src/adt/LinkedListWithHeadAndLength.js b/src/adt/LinkedListWithHeadAndLength.js index a0e4ecd..f5e5926 100644 --- a/src/adt/LinkedListWithHeadAndLength.js +++ b/src/adt/LinkedListWithHeadAndLength.js @@ -1,42 +1,34 @@ -import { selfs , nulls , ones } from '../fundamentals/index.js' ; +import {identity, nulls, ones} from '../fundamentals/index.js'; -export function union ( back , next , length , a , b ) { - - if ( length[a] < length[b] ) { - let c = a ; - a = b ; - b = c ; +export const union = (back, next, length, a, b) => { + if (length[a] < length[b]) { + const c = a; + a = b; + b = c; } - next[back[a]] = b ; - back[a] = back[b] ; - - for ( let c = next[a] ; c !== b ; c = next[c] ) back[c] = back[b] ; + next[back[a]] = b; + back[a] = back[b]; - length[a] += length[b] ; + for (let c = next[a]; c !== b; c = next[c]) back[c] = back[b]; - return a ; + length[a] += length[b]; -} + return a; +}; -export const find = ( back , node ) => back[node] ; +export const find = (back, node) => back[node]; -export function Universe ( n , List = Array ) { - this.back = selfs( n , List ) ; - this.next = nulls( n , List ) ; - this._length = ones( n , List ) ; +export function Universe(n, List = Array) { + this.back = identity(n, List); + this.next = nulls(n, List); + this._length = ones(n, List); } -Universe.prototype.union = function ( a , b ) { - return union( this.back , this.next , this._length , a , b ) ; -} ; - -Universe.prototype.find = function ( node ) { - return find( this.back , node ) ; -} ; +Universe.prototype.union = function (a, b) { + return union(this.back, this.next, this._length, a, b); +}; -export default { - Universe , - union , - find , -} ; +Universe.prototype.find = function (node) { + return find(this.back, node); +}; diff --git a/src/adt/index.js b/src/adt/index.js index 28ae976..43ebe90 100644 --- a/src/adt/index.js +++ b/src/adt/index.js @@ -1,30 +1,8 @@ -import Forest from './Forest.js' ; -import ForestAmortizedHalving from './ForestAmortizedHalving.js' ; -import ForestAmortizedRecursive from './ForestAmortizedRecursive.js' ; -import ForestAmortizedSplitting from './ForestAmortizedSplitting.js' ; -import ForestAmortizedTwoPasses from './ForestAmortizedTwoPasses.js' ; -import LinkedList from './LinkedList.js' ; -import LinkedListWithHead from './LinkedListWithHead.js' ; -import LinkedListWithHeadAndLength from './LinkedListWithHeadAndLength.js' ; - -export default { - Forest , - ForestAmortizedHalving , - ForestAmortizedRecursive , - ForestAmortizedSplitting , - ForestAmortizedTwoPasses , - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , -} ; - -export { - Forest , - ForestAmortizedHalving , - ForestAmortizedRecursive , - ForestAmortizedSplitting , - ForestAmortizedTwoPasses , - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , -} ; +export * as Forest from './Forest.js'; +export * as ForestAmortizedRecursive from './ForestAmortizedRecursive.js'; +export * as ForestAmortizedHalving from './ForestAmortizedHalving.js'; +export * as ForestAmortizedTwoPasses from './ForestAmortizedTwoPasses.js'; +export * as ForestAmortizedSplitting from './ForestAmortizedSplitting.js'; +export * as LinkedList from './LinkedList.js'; +export * as LinkedListWithHeadAndLength from './LinkedListWithHeadAndLength.js'; +export * as LinkedListWithHead from './LinkedListWithHead.js'; diff --git a/src/fundamentals/_RankedTreeUniverse.js b/src/fundamentals/_RankedTreeUniverse.js index cdc3f37..b0b3d4a 100644 --- a/src/fundamentals/_RankedTreeUniverse.js +++ b/src/fundamentals/_RankedTreeUniverse.js @@ -1,21 +1,19 @@ -import selfs from './selfs.js' ; -import zeros from './zeros.js' ; +import identity from './identity.js'; +import zeros from './zeros.js'; -export default function _RankedTreeUniverse ( union , find ) { +export default function _RankedTreeUniverse(union, find) { + const Universe = function (n, List = Array) { + this.p = identity(n, List); + this.r = zeros(n, List); + }; - const Universe = function ( n , List = Array ) { - this.p = selfs( n , List ) ; - this.r = zeros( n , List ) ; - } ; + Universe.prototype.union = function (a, b) { + return union(this.p, this.r, a, b); + }; - Universe.prototype.union = function ( a , b ) { - return union( this.p , this.r , a , b ) ; - } ; - - Universe.prototype.find = function ( x ) { - return find( this.p , x ) ; - } ; - - return Universe ; + Universe.prototype.find = function (x) { + return find(this.p, x); + }; + return Universe; } diff --git a/src/fundamentals/identity.js b/src/fundamentals/identity.js new file mode 100644 index 0000000..754bc34 --- /dev/null +++ b/src/fundamentals/identity.js @@ -0,0 +1,7 @@ +export default function identity(n, List = Array) { + const a = new List(n); + + for (let i = 0; i < n; ++i) a[i] = i; + + return a; +} diff --git a/src/fundamentals/index.js b/src/fundamentals/index.js index 69c60bc..1559bf2 100644 --- a/src/fundamentals/index.js +++ b/src/fundamentals/index.js @@ -1,24 +1,6 @@ -import _RankedTreeUniverse from './_RankedTreeUniverse.js' ; -import nulls from './nulls.js' ; -import ones from './ones.js' ; -import rankedtreeunion from './rankedtreeunion.js' ; -import selfs from './selfs.js' ; -import zeros from './zeros.js' ; - -export default { - _RankedTreeUniverse , - nulls , - ones , - rankedtreeunion , - selfs , - zeros , -} ; - -export { - _RankedTreeUniverse , - nulls , - ones , - rankedtreeunion , - selfs , - zeros , -} ; +export {default as _RankedTreeUniverse} from './_RankedTreeUniverse.js'; +export {default as ones} from './ones.js'; +export {default as nulls} from './nulls.js'; +export {default as identity} from './identity.js'; +export {default as rankedtreeunion} from './rankedtreeunion.js'; +export {default as zeros} from './zeros.js'; diff --git a/src/fundamentals/nulls.js b/src/fundamentals/nulls.js index f80ae3e..5ab6eff 100644 --- a/src/fundamentals/nulls.js +++ b/src/fundamentals/nulls.js @@ -1,9 +1,7 @@ -export default function nulls ( n , List = Array ) { +export default function nulls(n, List = Array) { + const a = new List(n); - const a = new List( n ) ; - - for ( let i = 0 ; i < n ; ++i ) a[i] = -1 ; - - return a ; + for (let i = 0; i < n; ++i) a[i] = -1; + return a; } diff --git a/src/fundamentals/ones.js b/src/fundamentals/ones.js index 7f055e9..1ac4087 100644 --- a/src/fundamentals/ones.js +++ b/src/fundamentals/ones.js @@ -1,9 +1,7 @@ -export default function ones ( n , List = Array ) { +export default function ones(n, List = Array) { + const a = new List(n); - const a = new List( n ) ; - - for ( let i = 0 ; i < n ; ++i ) a[i] = 1 ; - - return a ; + for (let i = 0; i < n; ++i) a[i] = 1; + return a; } diff --git a/src/fundamentals/rankedtreeunion.js b/src/fundamentals/rankedtreeunion.js index c7f8afa..2296f15 100644 --- a/src/fundamentals/rankedtreeunion.js +++ b/src/fundamentals/rankedtreeunion.js @@ -1,19 +1,15 @@ -export default function rankedtreeunion ( p , r , a , b ) { - - if ( r[a] < r[b] ) { - p[a] = b ; - return b ; - } - - else if ( r[a] > r[b] ) { - p[b] = a ; - return a ; +export default function rankedtreeunion(p, r, a, b) { + if (r[a] < r[b]) { + p[a] = b; + return b; } - else { - p[b] = a ; - ++r[a] ; - return a ; + if (r[a] > r[b]) { + p[b] = a; + return a; } + p[b] = a; + ++r[a]; + return a; } diff --git a/src/fundamentals/selfs.js b/src/fundamentals/selfs.js deleted file mode 100644 index 43a2c27..0000000 --- a/src/fundamentals/selfs.js +++ /dev/null @@ -1,9 +0,0 @@ -export default function selfs ( n , List = Array ) { - - const a = new List( n ) ; - - for ( let i = 0 ; i < n ; ++i ) a[i] = i ; - - return a ; - -} diff --git a/src/fundamentals/zeros.js b/src/fundamentals/zeros.js index df16ad4..7ea0053 100644 --- a/src/fundamentals/zeros.js +++ b/src/fundamentals/zeros.js @@ -1,9 +1,7 @@ -export default function zeros ( n , List = Array ) { +export default function zeros(n, List = Array) { + const a = new List(n); - const a = new List( n ) ; - - for ( let i = 0 ; i < n ; ++i ) a[i] = 0 ; - - return a ; + for (let i = 0; i < n; ++i) a[i] = 0; + return a; } diff --git a/src/index.js b/src/index.js index 49b5cee..d2e94e5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,32 +1,10 @@ -import { - Forest , - ForestAmortizedHalving , - ForestAmortizedRecursive , - ForestAmortizedSplitting , - ForestAmortizedTwoPasses , - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , -} from './adt/index.js' ; - -export default { - Forest , - ForestAmortizedHalving , - ForestAmortizedRecursive , - ForestAmortizedSplitting , - ForestAmortizedTwoPasses , - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , -} ; - export { - Forest , - ForestAmortizedHalving , - ForestAmortizedRecursive , - ForestAmortizedSplitting , - ForestAmortizedTwoPasses , - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , -} ; + Forest, + ForestAmortizedRecursive, + ForestAmortizedHalving, + ForestAmortizedTwoPasses, + ForestAmortizedSplitting, + LinkedList, + LinkedListWithHeadAndLength, + LinkedListWithHead, +} from './adt/index.js'; diff --git a/test/src/disjointset.js b/test/src/disjointset.js index 9a098c5..7833a2c 100644 --- a/test/src/disjointset.js +++ b/test/src/disjointset.js @@ -1,131 +1,343 @@ -import test from 'ava' ; +import test from 'ava'; import { - LinkedList , - LinkedListWithHead , - LinkedListWithHeadAndLength , - Forest , - ForestAmortizedRecursive , - ForestAmortizedTwoPasses , - ForestAmortizedSplitting , - ForestAmortizedHalving , -} from '../../src/index.js' ; + LinkedList, + LinkedListWithHead, + LinkedListWithHeadAndLength, + Forest, + ForestAmortizedRecursive, + ForestAmortizedTwoPasses, + ForestAmortizedSplitting, + ForestAmortizedHalving, +} from '../../src/index.js'; -function macro ( t , Universe ) { +function macro(t, Universe) { + /* eslint-disable no-multi-assign */ + let a; + let b; + let c; + let d; + let e; + let A; + let B; + let C; + let D; + let E; + let U; - let a , b , c , d , e , A , B , C , D , E , U ; + // eslint-disable-next-line unicorn/no-array-callback-reference + const l = (x, y) => t.true(U.find(x) === U.find(y)); - const l = ( x , y ) => t.true( U.find( x ) === U.find( y ) ) ; - - const o = ( x , y ) => t.true( U.find( x ) !== U.find( y ) ) ; + // eslint-disable-next-line unicorn/no-array-callback-reference + const o = (x, y) => t.true(U.find(x) !== U.find(y)); // 1st scenario - U = new Universe( 5 ) ; + U = new Universe(5); - A = a = 0 ; - B = b = 1 ; - C = c = 2 ; - D = d = 3 ; - E = e = 4 ; + A = a = 0; + B = b = 1; + C = c = 2; + D = d = 3; + E = e = 4; - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; o( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; o( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; o( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - o( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; + l(a, a); + o(b, a); + o(c, a); + o(d, a); + o(e, a); + o(a, b); + l(b, b); + o(c, b); + o(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + o(b, d); + o(c, d); + l(d, d); + o(e, d); + o(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); - A = U.union( A , E ) ; + A = U.union(A, E); - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; o( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; o( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; + l(a, a); + o(b, a); + o(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + o(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + o(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); - B = U.union( D , B ) ; + B = U.union(D, B); - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; l( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; l( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; + l(a, a); + o(b, a); + o(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + l(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + l(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); - A = U.union( C , A ) ; + A = U.union(C, A); - l( a , a ) ; o( b , a ) ; l( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; l( d , b ) ; o( e , b ) ; - l( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; l( e , c ) ; - o( a , d ) ; l( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; l( c , e ) ; o( d , e ) ; l( e , e ) ; + l(a, a); + o(b, a); + l(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + l(d, b); + o(e, b); + l(a, c); + o(b, c); + l(c, c); + o(d, c); + l(e, c); + o(a, d); + l(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + l(c, e); + o(d, e); + l(e, e); - A = U.union( B , A ) ; + A = U.union(B, A); - l( a , a ) ; l( b , a ) ; l( c , a ) ; l( d , a ) ; l( e , a ) ; - l( a , b ) ; l( b , b ) ; l( c , b ) ; l( d , b ) ; l( e , b ) ; - l( a , c ) ; l( b , c ) ; l( c , c ) ; l( d , c ) ; l( e , c ) ; - l( a , d ) ; l( b , d ) ; l( c , d ) ; l( d , d ) ; l( e , d ) ; - l( a , e ) ; l( b , e ) ; l( c , e ) ; l( d , e ) ; l( e , e ) ; + l(a, a); + l(b, a); + l(c, a); + l(d, a); + l(e, a); + l(a, b); + l(b, b); + l(c, b); + l(d, b); + l(e, b); + l(a, c); + l(b, c); + l(c, c); + l(d, c); + l(e, c); + l(a, d); + l(b, d); + l(c, d); + l(d, d); + l(e, d); + l(a, e); + l(b, e); + l(c, e); + l(d, e); + l(e, e); // 2nd scenario - U = new Universe( 5 ) ; - - A = a = 0 ; - B = b = 1 ; - C = c = 2 ; - D = d = 3 ; - E = e = 4 ; - - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; o( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; o( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; o( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - o( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; - - A = U.union( A , E ) ; - - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; o( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; o( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; - - B = U.union( D , B ) ; - - l( a , a ) ; o( b , a ) ; o( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; l( d , b ) ; o( e , b ) ; - o( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; o( e , c ) ; - o( a , d ) ; l( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; o( c , e ) ; o( d , e ) ; l( e , e ) ; - - A = U.union( A , C ) ; - - l( a , a ) ; o( b , a ) ; l( c , a ) ; o( d , a ) ; l( e , a ) ; - o( a , b ) ; l( b , b ) ; o( c , b ) ; l( d , b ) ; o( e , b ) ; - l( a , c ) ; o( b , c ) ; l( c , c ) ; o( d , c ) ; l( e , c ) ; - o( a , d ) ; l( b , d ) ; o( c , d ) ; l( d , d ) ; o( e , d ) ; - l( a , e ) ; o( b , e ) ; l( c , e ) ; o( d , e ) ; l( e , e ) ; - - A = U.union( B , A ) ; - - l( a , a ) ; l( b , a ) ; l( c , a ) ; l( d , a ) ; l( e , a ) ; - l( a , b ) ; l( b , b ) ; l( c , b ) ; l( d , b ) ; l( e , b ) ; - l( a , c ) ; l( b , c ) ; l( c , c ) ; l( d , c ) ; l( e , c ) ; - l( a , d ) ; l( b , d ) ; l( c , d ) ; l( d , d ) ; l( e , d ) ; - l( a , e ) ; l( b , e ) ; l( c , e ) ; l( d , e ) ; l( e , e ) ; - -} ; - -for ( const [ name , Set ] of [ - [ "LinkedList" , LinkedList ] , - [ "LinkedListWithHead" , LinkedListWithHead ] , - [ "LinkedListWithHeadAndLength" , LinkedListWithHeadAndLength ] , - [ "Forest" , Forest ] , - [ "ForestAmortizedRecursive" , ForestAmortizedRecursive ] , - [ "ForestAmortizedTwoPasses" , ForestAmortizedTwoPasses ] , - [ "ForestAmortizedSplitting" , ForestAmortizedSplitting ] , - [ "ForestAmortizedHalving" , ForestAmortizedHalving ] , -] ) { - - test( name , macro , Set.Universe ) ; + U = new Universe(5); + + A = a = 0; + B = b = 1; + C = c = 2; + D = d = 3; + E = e = 4; + + l(a, a); + o(b, a); + o(c, a); + o(d, a); + o(e, a); + o(a, b); + l(b, b); + o(c, b); + o(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + o(b, d); + o(c, d); + l(d, d); + o(e, d); + o(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); + + A = U.union(A, E); + + l(a, a); + o(b, a); + o(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + o(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + o(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); + + B = U.union(D, B); + + l(a, a); + o(b, a); + o(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + l(d, b); + o(e, b); + o(a, c); + o(b, c); + l(c, c); + o(d, c); + o(e, c); + o(a, d); + l(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + o(c, e); + o(d, e); + l(e, e); + + A = U.union(A, C); + + l(a, a); + o(b, a); + l(c, a); + o(d, a); + l(e, a); + o(a, b); + l(b, b); + o(c, b); + l(d, b); + o(e, b); + l(a, c); + o(b, c); + l(c, c); + o(d, c); + l(e, c); + o(a, d); + l(b, d); + o(c, d); + l(d, d); + o(e, d); + l(a, e); + o(b, e); + l(c, e); + o(d, e); + l(e, e); + + // eslint-disable-next-line no-unused-vars + A = U.union(B, A); + + l(a, a); + l(b, a); + l(c, a); + l(d, a); + l(e, a); + l(a, b); + l(b, b); + l(c, b); + l(d, b); + l(e, b); + l(a, c); + l(b, c); + l(c, c); + l(d, c); + l(e, c); + l(a, d); + l(b, d); + l(c, d); + l(d, d); + l(e, d); + l(a, e); + l(b, e); + l(c, e); + l(d, e); + l(e, e); + + /* eslint-enable no-multi-assign */ +} +for (const [name, DisjointSet] of [ + ['LinkedList', LinkedList], + ['LinkedListWithHead', LinkedListWithHead], + ['LinkedListWithHeadAndLength', LinkedListWithHeadAndLength], + ['Forest', Forest], + ['ForestAmortizedRecursive', ForestAmortizedRecursive], + ['ForestAmortizedTwoPasses', ForestAmortizedTwoPasses], + ['ForestAmortizedSplitting', ForestAmortizedSplitting], + ['ForestAmortizedHalving', ForestAmortizedHalving], +]) { + test(name, macro, DisjointSet.Universe); }