-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfhyper.js
More file actions
81 lines (76 loc) 路 1.66 KB
/
Copy pathfhyper.js
File metadata and controls
81 lines (76 loc) 路 1.66 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
/* Graph, Directed, Hypergraph, F-edges */
const genConnector = (gState, nState, eState) =>
function perTarget(nn, headlabel) {
if (nn === undefined) {
nn = genNode(gState)();
}
const nnState = nn.state;
const nnFrom = nnState.from;
eState.targets.push({
node: nnState,
index: nnFrom.length,
headlabel: headlabel
});
nnFrom.push(eState);
return perTarget;
};
const genEdge = (gState, nState) =>
(label, taillabel) => {
if (label === undefined) {
label = {};
}
const eState = {
source: {
node: nState,
index: nState.to.length
},
targets: [],
label: label,
taillabel: taillabel,
root: gState
};
nState.to.push(eState);
gState.edges.push(eState);
const res = genConnector(gState, nState, eState);
res.state = eState;
return res;
};
const genNode = gState =>
function(label) {
const nState = {
from: [],
to: [],
label: label,
root: gState
};
gState.nodes.push(nState);
const res = genEdge(gState, nState);
res.state = nState;
const alen = arguments.length;
if (alen > 1) {
for (let i = 1; i < alen; i++) {
const arg = arguments[i];
if (Array.isArray(arg)) {
arg.map(function(subArg) {
subArg(res);
});
} else {
arg(res);
}
}
}
return res;
};
module.exports = function(label) {
const gState = {
nodes: [],
edges: [],
label: label
};
const res = genNode(gState);
res.nodes = gState.nodes;
res.edges = gState.edges;
res.label = gState.label;
return res;
};