StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics
https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.0 KiB
62 lines
1.0 KiB
"use strict"; "use restrict";
|
|
|
|
module.exports = UnionFind;
|
|
|
|
function UnionFind(count) {
|
|
this.roots = new Array(count);
|
|
this.ranks = new Array(count);
|
|
|
|
for(var i=0; i<count; ++i) {
|
|
this.roots[i] = i;
|
|
this.ranks[i] = 0;
|
|
}
|
|
}
|
|
|
|
var proto = UnionFind.prototype
|
|
|
|
Object.defineProperty(proto, "length", {
|
|
"get": function() {
|
|
return this.roots.length
|
|
}
|
|
})
|
|
|
|
proto.makeSet = function() {
|
|
var n = this.roots.length;
|
|
this.roots.push(n);
|
|
this.ranks.push(0);
|
|
return n;
|
|
}
|
|
|
|
proto.find = function(x) {
|
|
var x0 = x
|
|
var roots = this.roots;
|
|
while(roots[x] !== x) {
|
|
x = roots[x]
|
|
}
|
|
while(roots[x0] !== x) {
|
|
var y = roots[x0]
|
|
roots[x0] = x
|
|
x0 = y
|
|
}
|
|
return x;
|
|
}
|
|
|
|
proto.link = function(x, y) {
|
|
var xr = this.find(x)
|
|
, yr = this.find(y);
|
|
if(xr === yr) {
|
|
return;
|
|
}
|
|
var ranks = this.ranks
|
|
, roots = this.roots
|
|
, xd = ranks[xr]
|
|
, yd = ranks[yr];
|
|
if(xd < yd) {
|
|
roots[xr] = yr;
|
|
} else if(yd < xd) {
|
|
roots[yr] = xr;
|
|
} else {
|
|
roots[yr] = xr;
|
|
++ranks[xr];
|
|
}
|
|
} |