union-find/contiguous

View on GitHub
src/fundamentals/_RankedTreeUniverse.js

Summary

Maintainability
A
0 mins
Test Coverage
import identity from './identity.js';
import zeros from './zeros.js';

export default function _RankedTreeUniverse(union, find) {
    const Universe = function (n, List = Array) {
        this.p = identity(n, List);
        this.r = zeros(n, List);
    };

    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;
}