-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.js
More file actions
48 lines (46 loc) · 1.32 KB
/
worker.js
File metadata and controls
48 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
importScripts('tree.js');
self.addEventListener('message', message => {
let distribution = message.data.distribution;
let name;
let params;
if (distribution == 'geometric' || distribution == 'poisson') {
name = distribution;
}
else {
name = 'manual';
if (distribution == 'man2') {
params = [1, 2, 1];
}
if (distribution == 'man3') {
params = [8, 12, 6, 1];
}
if (distribution == 'man4') {
params = [81, 108, 54, 12, 1];
}
}
if (message.data.type == 'bigtree') {
self.postMessage({ tree: newTree((n) => (n > maxNodeCount / 3), name, params) });
}
else {
self.postMessage({ tree: newTree((n) => (true), name, params), name, params });
}
});
function newTree(p, name, params) { // predicate
// t = Tree.randomTree('manual', [8, 12, 6, 1]);
t = null;
while (t == null || !p(t.size)) {
try {
treeSize = 0;
t = Tree.randomTree(name, params);
} catch (e) {
if (e instanceof TreeError) {
console.log('too big tree - trying again');
t = null;
} else {
throw e; // re-throw the error unchanged
}
}
}
t.setMultiplicities();
return t;
}