randomWorker = {
const blob = new Blob(
[
`
importScripts("${await FileAttachment("union-find-1.0.2.js").url()}");
onmessage = event => {
const {data: {numOps, linkProb, findProb}} = event;
const uf = new unionFind(0);
for (let j=0; j < numOps; j++) {
const rnode = () => Math.floor(uf.roots.length*Math.random());
const r = Math.random();
if (uf.roots.length > 1 && r < linkProb) {
const l1 = rnode(),
l2 = rnode();
uf.link(l1,l2);
} else if (uf.roots.length > 0 && r > findProb) {
const f = rnode();
uf.find(f);
} else {
uf.makeSet();
}
// if (j > 0 && j%1000000 === 0)
// postMessage(uf);
}
postMessage(uf);
close();
};
`
],
{ type: "text/javascript" }
);
const script = URL.createObjectURL(blob);
invalidation.then(() => URL.revokeObjectURL(script));
return script;
}