@rsconcept/domain 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/analyzer-DlSq3Y3r.d.ts +39 -0
- package/dist/arguments-extractor-1acwjQNc.d.ts +38 -0
- package/dist/ast-C8sIpKdL.d.ts +51 -0
- package/dist/ast-annotations-BiMjkKvz.d.ts +16 -0
- package/dist/branded-ZlzIcxzu.d.ts +9 -0
- package/dist/calculator-C9W2jkSx.d.ts +39 -0
- package/dist/cctext/index.d.ts +2 -1
- package/dist/cctext/index.js +2 -42
- package/dist/cctext/language-api.d.ts +10 -12
- package/dist/cctext/language-api.js +157 -227
- package/dist/cctext/language-api.js.map +1 -1
- package/dist/cctext/language.d.ts +24 -22
- package/dist/cctext/language.js +43 -39
- package/dist/cctext/language.js.map +1 -1
- package/dist/error-E1LVq_3w.d.ts +87 -0
- package/dist/graph/graph.d.ts +2 -62
- package/dist/graph/graph.js +339 -382
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +2 -1
- package/dist/graph/index.js +2 -384
- package/dist/graph-DR8rL2o3.d.ts +64 -0
- package/dist/hash-Y8I4c6Al.d.ts +8 -0
- package/dist/index-BKZ67WMa.d.ts +1 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-DmtQKWjk.d.ts +1 -0
- package/dist/index-_6s0AX1B.d.ts +1 -0
- package/dist/index.d.ts +27 -28
- package/dist/index.js +23 -5851
- package/dist/lezer-tree-iS7LpLBJ.d.ts +14 -0
- package/dist/library/folder-tree.d.ts +22 -20
- package/dist/library/folder-tree.js +108 -130
- package/dist/library/folder-tree.js.map +1 -1
- package/dist/library/index.d.ts +8 -17
- package/dist/library/index.js +7 -2800
- package/dist/library/library-api.d.ts +3 -1
- package/dist/library/library-api.js +9 -8
- package/dist/library/library-api.js.map +1 -1
- package/dist/library/library.d.ts +2 -56
- package/dist/library/library.js +23 -19
- package/dist/library/library.js.map +1 -1
- package/dist/library/oss-api.d.ts +26 -37
- package/dist/library/oss-api.js +258 -1096
- package/dist/library/oss-api.js.map +1 -1
- package/dist/library/oss-layout-api.d.ts +28 -28
- package/dist/library/oss-layout-api.js +239 -316
- package/dist/library/oss-layout-api.js.map +1 -1
- package/dist/library/oss-layout.d.ts +2 -25
- package/dist/library/oss-layout.js +1 -1
- package/dist/library/oss.d.ts +87 -89
- package/dist/library/oss.js +27 -26
- package/dist/library/oss.js.map +1 -1
- package/dist/library/rsengine.d.ts +100 -106
- package/dist/library/rsengine.js +439 -2599
- package/dist/library/rsengine.js.map +1 -1
- package/dist/library/rsform-api.d.ts +11 -16
- package/dist/library/rsform-api.js +313 -825
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +159 -167
- package/dist/library/rsform.js +29 -28
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +8 -15
- package/dist/library/rsmodel-api.js +172 -813
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +27 -33
- package/dist/library/rsmodel.js +16 -23
- package/dist/library/rsmodel.js.map +1 -1
- package/dist/library/structure-planner.d.ts +20 -26
- package/dist/library/structure-planner.js +106 -474
- package/dist/library/structure-planner.js.map +1 -1
- package/dist/library-CYun28Xz.d.ts +58 -0
- package/dist/oss-layout-3glgAqfn.d.ts +27 -0
- package/dist/parser-Bwd8LxJ1.d.ts +7 -0
- package/dist/parsing/ast.d.ts +2 -49
- package/dist/parsing/ast.js +68 -76
- package/dist/parsing/ast.js.map +1 -1
- package/dist/parsing/index.d.ts +3 -3
- package/dist/parsing/index.js +3 -141
- package/dist/parsing/lezer-tree.d.ts +2 -13
- package/dist/parsing/lezer-tree.js +50 -43
- package/dist/parsing/lezer-tree.js.map +1 -1
- package/dist/rslang/api.d.ts +9 -14
- package/dist/rslang/api.js +114 -827
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +2 -18
- package/dist/rslang/ast-annotations.js +34 -45
- package/dist/rslang/ast-annotations.js.map +1 -1
- package/dist/rslang/error.d.ts +2 -85
- package/dist/rslang/error.js +88 -150
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +2 -43
- package/dist/rslang/eval/calculator.js +81 -1636
- package/dist/rslang/eval/calculator.js.map +1 -1
- package/dist/rslang/eval/evaluation-cache.d.ts +22 -26
- package/dist/rslang/eval/evaluation-cache.js +168 -287
- package/dist/rslang/eval/evaluation-cache.js.map +1 -1
- package/dist/rslang/eval/evaluator.d.ts +59 -63
- package/dist/rslang/eval/evaluator.js +602 -1509
- package/dist/rslang/eval/evaluator.js.map +1 -1
- package/dist/rslang/eval/value-api.d.ts +2 -48
- package/dist/rslang/eval/value-api.js +2 -490
- package/dist/rslang/eval/value.d.ts +2 -36
- package/dist/rslang/eval/value.js +2 -118
- package/dist/rslang/index.d.ts +14 -17
- package/dist/rslang/index.js +12 -4314
- package/dist/rslang/labels.d.ts +6 -6
- package/dist/rslang/labels.js +139 -305
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/expression-generator.d.ts +5 -5
- package/dist/rslang/parser/expression-generator.js +248 -446
- package/dist/rslang/parser/expression-generator.js.map +1 -1
- package/dist/rslang/parser/normalize.d.ts +4 -8
- package/dist/rslang/parser/normalize.js +286 -481
- package/dist/rslang/parser/normalize.js.map +1 -1
- package/dist/rslang/parser/parser.d.ts +2 -5
- package/dist/rslang/parser/parser.js +30 -21
- package/dist/rslang/parser/parser.js.map +1 -1
- package/dist/rslang/parser/parser.terms.d.ts +43 -41
- package/dist/rslang/parser/parser.terms.js +44 -83
- package/dist/rslang/parser/parser.terms.js.map +1 -1
- package/dist/rslang/parser/syntax-errors.d.ts +5 -8
- package/dist/rslang/parser/syntax-errors.js +113 -382
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/parser/token.d.ts +2 -79
- package/dist/rslang/parser/token.js +81 -93
- package/dist/rslang/parser/token.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +2 -39
- package/dist/rslang/semantic/analyzer.js +186 -2600
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/arguments-extractor.d.ts +2 -42
- package/dist/rslang/semantic/arguments-extractor.js +202 -361
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +64 -68
- package/dist/rslang/semantic/type-auditor.js +594 -1564
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +4 -7
- package/dist/rslang/semantic/typification-api.js +162 -303
- package/dist/rslang/semantic/typification-api.js.map +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +2 -12
- package/dist/rslang/semantic/typification-parser.js +165 -219
- package/dist/rslang/semantic/typification-parser.js.map +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -119
- package/dist/rslang/semantic/typification.js +66 -52
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +32 -38
- package/dist/rslang/semantic/value-auditor.js +206 -518
- package/dist/rslang/semantic/value-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-class.d.ts +2 -10
- package/dist/rslang/semantic/value-class.js +8 -7
- package/dist/rslang/semantic/value-class.js.map +1 -1
- package/dist/rslang/typification-graph.d.ts +2 -33
- package/dist/rslang/typification-graph.js +94 -306
- package/dist/rslang/typification-graph.js.map +1 -1
- package/dist/shared/branded.d.ts +2 -7
- package/dist/shared/branded.js +1 -1
- package/dist/shared/hash.d.ts +2 -6
- package/dist/shared/hash.js +13 -13
- package/dist/shared/hash.js.map +1 -1
- package/dist/shared/index.d.ts +3 -2
- package/dist/shared/index.js +2 -18
- package/dist/token-DeXAmzwr.d.ts +81 -0
- package/dist/typification-Dk-fisgO.d.ts +120 -0
- package/dist/typification-graph-6HcZ-rKH.d.ts +30 -0
- package/dist/typification-parser-BBVx1RxP.d.ts +13 -0
- package/dist/value-B8UtCqaK.js +366 -0
- package/dist/value-B8UtCqaK.js.map +1 -0
- package/dist/value-CTjX6825.d.ts +33 -0
- package/dist/value-api-Bw-SgaYY.d.ts +49 -0
- package/dist/value-class-CNI-lqXJ.d.ts +12 -0
- package/package.json +8 -8
- package/src/library/oss-api.test.ts +76 -0
- package/src/library/oss-api.ts +4 -1
- package/src/library/rsform-api.test.ts +24 -0
- package/src/library/rsform-api.ts +12 -4
- package/dist/cctext/index.js.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/library/index.js.map +0 -1
- package/dist/library/oss-layout.js.map +0 -1
- package/dist/parsing/index.js.map +0 -1
- package/dist/rslang/eval/value-api.js.map +0 -1
- package/dist/rslang/eval/value.js.map +0 -1
- package/dist/rslang/index.js.map +0 -1
- package/dist/shared/branded.js.map +0 -1
- package/dist/shared/index.js.map +0 -1
package/dist/graph/graph.js
CHANGED
|
@@ -1,385 +1,342 @@
|
|
|
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
|
-
|
|
1
|
+
//#region src/graph/graph.ts
|
|
2
|
+
/**
|
|
3
|
+
* Module: Custom graph data structure.
|
|
4
|
+
*/
|
|
5
|
+
/** Represents single node of a {@link Graph}, as implemented by storing outgoing and incoming connections. */
|
|
6
|
+
var GraphNode = class GraphNode {
|
|
7
|
+
/** Unique identifier of the node. */
|
|
8
|
+
id;
|
|
9
|
+
/** List of outgoing nodes. */
|
|
10
|
+
outputs;
|
|
11
|
+
/** List of incoming nodes. */
|
|
12
|
+
inputs;
|
|
13
|
+
constructor(id) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.outputs = [];
|
|
16
|
+
this.inputs = [];
|
|
17
|
+
}
|
|
18
|
+
clone() {
|
|
19
|
+
const result = new GraphNode(this.id);
|
|
20
|
+
result.outputs = [...this.outputs];
|
|
21
|
+
result.inputs = [...this.inputs];
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
addOutput(node) {
|
|
25
|
+
this.outputs.push(node);
|
|
26
|
+
}
|
|
27
|
+
addInput(node) {
|
|
28
|
+
this.inputs.push(node);
|
|
29
|
+
}
|
|
30
|
+
removeInput(target) {
|
|
31
|
+
const index = this.inputs.findIndex((node) => node === target);
|
|
32
|
+
return index > -1 ? this.inputs.splice(index, 1)[0] : null;
|
|
33
|
+
}
|
|
34
|
+
removeOutput(target) {
|
|
35
|
+
const index = this.outputs.findIndex((node) => node === target);
|
|
36
|
+
return index > -1 ? this.outputs.splice(index, 1)[0] : null;
|
|
37
|
+
}
|
|
34
38
|
};
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
findCycle() {
|
|
335
|
-
const visited = /* @__PURE__ */ new Set();
|
|
336
|
-
const nodeStack = /* @__PURE__ */ new Set();
|
|
337
|
-
const parents = /* @__PURE__ */ new Map();
|
|
338
|
-
for (const nodeId of this.nodes.keys()) {
|
|
339
|
-
if (visited.has(nodeId)) {
|
|
340
|
-
continue;
|
|
341
|
-
}
|
|
342
|
-
const callStack = [];
|
|
343
|
-
callStack.push({ nodeId, parentId: null });
|
|
344
|
-
while (callStack.length > 0) {
|
|
345
|
-
const { nodeId: nodeId2, parentId } = callStack[callStack.length - 1];
|
|
346
|
-
if (visited.has(nodeId2)) {
|
|
347
|
-
nodeStack.delete(nodeId2);
|
|
348
|
-
callStack.pop();
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
visited.add(nodeId2);
|
|
352
|
-
nodeStack.add(nodeId2);
|
|
353
|
-
if (parentId !== null) {
|
|
354
|
-
parents.set(nodeId2, parentId);
|
|
355
|
-
}
|
|
356
|
-
const currentNode = this.nodes.get(nodeId2);
|
|
357
|
-
for (const child of currentNode.outputs) {
|
|
358
|
-
if (!visited.has(child)) {
|
|
359
|
-
callStack.push({ nodeId: child, parentId: nodeId2 });
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
if (!nodeStack.has(child)) {
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
365
|
-
const cycle = [];
|
|
366
|
-
let current = nodeId2;
|
|
367
|
-
cycle.push(child);
|
|
368
|
-
while (current !== child) {
|
|
369
|
-
cycle.push(current);
|
|
370
|
-
current = parents.get(current);
|
|
371
|
-
}
|
|
372
|
-
cycle.push(child);
|
|
373
|
-
cycle.reverse();
|
|
374
|
-
return cycle;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
export {
|
|
382
|
-
Graph,
|
|
383
|
-
GraphNode
|
|
39
|
+
/**
|
|
40
|
+
* Represents a Graph.
|
|
41
|
+
*
|
|
42
|
+
* This class is optimized for TermGraph use case and not supposed to be used as generic graph implementation.
|
|
43
|
+
*/
|
|
44
|
+
var Graph = class Graph {
|
|
45
|
+
/** Map of nodes. */
|
|
46
|
+
nodes = /* @__PURE__ */ new Map();
|
|
47
|
+
constructor(arr) {
|
|
48
|
+
if (!arr) return;
|
|
49
|
+
arr.forEach((edge) => {
|
|
50
|
+
if (edge.length === 1) this.addNode(edge[0]);
|
|
51
|
+
else this.addEdge(edge[0], edge[1]);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
clone() {
|
|
55
|
+
const result = new Graph();
|
|
56
|
+
this.nodes.forEach((node) => result.nodes.set(node.id, node.clone()));
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
at(target) {
|
|
60
|
+
return this.nodes.get(target);
|
|
61
|
+
}
|
|
62
|
+
addNode(target) {
|
|
63
|
+
let node = this.nodes.get(target);
|
|
64
|
+
if (!node) {
|
|
65
|
+
node = new GraphNode(target);
|
|
66
|
+
this.nodes.set(target, node);
|
|
67
|
+
}
|
|
68
|
+
return node;
|
|
69
|
+
}
|
|
70
|
+
hasNode(target) {
|
|
71
|
+
return !!this.nodes.get(target);
|
|
72
|
+
}
|
|
73
|
+
removeNode(target) {
|
|
74
|
+
this.nodes.forEach((node) => {
|
|
75
|
+
node.removeInput(target);
|
|
76
|
+
node.removeOutput(target);
|
|
77
|
+
});
|
|
78
|
+
this.nodes.delete(target);
|
|
79
|
+
}
|
|
80
|
+
foldNode(target) {
|
|
81
|
+
const nodeToRemove = this.nodes.get(target);
|
|
82
|
+
if (!nodeToRemove) return;
|
|
83
|
+
nodeToRemove.inputs.forEach((input) => {
|
|
84
|
+
nodeToRemove.outputs.forEach((output) => {
|
|
85
|
+
this.addEdge(input, output);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
this.removeNode(target);
|
|
89
|
+
}
|
|
90
|
+
removeIsolated() {
|
|
91
|
+
const result = [];
|
|
92
|
+
this.nodes.forEach((node) => {
|
|
93
|
+
if (node.outputs.length === 0 && node.inputs.length === 0) {
|
|
94
|
+
result.push(node);
|
|
95
|
+
this.nodes.delete(node.id);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
addEdge(source, destination) {
|
|
101
|
+
if (this.hasEdge(source, destination)) return;
|
|
102
|
+
const sourceNode = this.addNode(source);
|
|
103
|
+
const destinationNode = this.addNode(destination);
|
|
104
|
+
sourceNode.addOutput(destinationNode.id);
|
|
105
|
+
destinationNode.addInput(sourceNode.id);
|
|
106
|
+
}
|
|
107
|
+
removeEdge(source, destination) {
|
|
108
|
+
const sourceNode = this.nodes.get(source);
|
|
109
|
+
const destinationNode = this.nodes.get(destination);
|
|
110
|
+
if (sourceNode && destinationNode) {
|
|
111
|
+
sourceNode.removeOutput(destination);
|
|
112
|
+
destinationNode.removeInput(source);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
hasEdge(source, destination) {
|
|
116
|
+
const sourceNode = this.nodes.get(source);
|
|
117
|
+
if (!sourceNode) return false;
|
|
118
|
+
return !!sourceNode.outputs.find((id) => id === destination);
|
|
119
|
+
}
|
|
120
|
+
isReachable(source, destination) {
|
|
121
|
+
return this.expandAllOutputs([source]).includes(destination);
|
|
122
|
+
}
|
|
123
|
+
rootNodes() {
|
|
124
|
+
return [...this.nodes.keys()].filter((id) => !this.nodes.get(id)?.inputs.length);
|
|
125
|
+
}
|
|
126
|
+
expandOutputs(origin) {
|
|
127
|
+
const result = [];
|
|
128
|
+
origin.forEach((id) => {
|
|
129
|
+
const node = this.nodes.get(id);
|
|
130
|
+
if (node) node.outputs.forEach((child) => {
|
|
131
|
+
if (!origin.includes(child) && !result.includes(child)) result.push(child);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
expandInputs(origin) {
|
|
137
|
+
const result = [];
|
|
138
|
+
origin.forEach((id) => {
|
|
139
|
+
const node = this.nodes.get(id);
|
|
140
|
+
if (node) node.inputs.forEach((child) => {
|
|
141
|
+
if (!origin.includes(child) && !result.includes(child)) result.push(child);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
expandAllOutputs(origin) {
|
|
147
|
+
const result = this.expandOutputs(origin);
|
|
148
|
+
if (result.length === 0) return [];
|
|
149
|
+
const marked = /* @__PURE__ */ new Map();
|
|
150
|
+
origin.forEach((id) => marked.set(id, true));
|
|
151
|
+
let position = 0;
|
|
152
|
+
while (position < result.length) {
|
|
153
|
+
const node = this.nodes.get(result[position]);
|
|
154
|
+
if (node && !marked.get(node.id)) {
|
|
155
|
+
marked.set(node.id, true);
|
|
156
|
+
node.outputs.forEach((child) => {
|
|
157
|
+
if (!marked.get(child) && !result.find((id) => id === child)) result.push(child);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
position += 1;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
expandAllInputs(origin) {
|
|
165
|
+
const result = this.expandInputs(origin);
|
|
166
|
+
if (result.length === 0) return [];
|
|
167
|
+
const marked = /* @__PURE__ */ new Map();
|
|
168
|
+
origin.forEach((id) => marked.set(id, true));
|
|
169
|
+
let position = 0;
|
|
170
|
+
while (position < result.length) {
|
|
171
|
+
const node = this.nodes.get(result[position]);
|
|
172
|
+
if (node && !marked.get(node.id)) {
|
|
173
|
+
marked.set(node.id, true);
|
|
174
|
+
node.inputs.forEach((child) => {
|
|
175
|
+
if (!marked.get(child) && !result.find((id) => id === child)) result.push(child);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
position += 1;
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
maximizePart(origin) {
|
|
183
|
+
const outputs = this.expandAllOutputs(origin);
|
|
184
|
+
const result = [...origin];
|
|
185
|
+
this.topologicalOrder().filter((id) => outputs.includes(id)).forEach((id) => {
|
|
186
|
+
if (this.nodes.get(id)?.inputs.every((parent) => result.includes(parent))) result.push(id);
|
|
187
|
+
});
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
topologicalOrder() {
|
|
191
|
+
const result = [];
|
|
192
|
+
const marked = /* @__PURE__ */ new Set();
|
|
193
|
+
const nodeStack = [];
|
|
194
|
+
this.nodes.forEach((node) => {
|
|
195
|
+
if (marked.has(node.id)) return;
|
|
196
|
+
nodeStack.push(node.id);
|
|
197
|
+
while (nodeStack.length > 0) {
|
|
198
|
+
const item = nodeStack[nodeStack.length - 1];
|
|
199
|
+
if (marked.has(item)) {
|
|
200
|
+
if (!result.find((id) => id === item)) result.push(item);
|
|
201
|
+
nodeStack.pop();
|
|
202
|
+
} else {
|
|
203
|
+
marked.add(item);
|
|
204
|
+
const itemNode = this.nodes.get(item);
|
|
205
|
+
if (itemNode && itemNode.outputs.length > 0) itemNode.outputs.forEach((child) => {
|
|
206
|
+
if (!marked.has(child)) nodeStack.push(child);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return result.reverse();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Stably reorders the given node ids so that, for this DAG, no node appears before a transitive
|
|
215
|
+
* successor (edges: source → dependent; {@link GraphNode.outputs} lists dependents).
|
|
216
|
+
*/
|
|
217
|
+
sortStable(target) {
|
|
218
|
+
if (target.length <= 1) return [...target];
|
|
219
|
+
const reachable = this.buildTransitiveClosureForSort();
|
|
220
|
+
const testSet = /* @__PURE__ */ new Set();
|
|
221
|
+
const result = [];
|
|
222
|
+
for (const nodeId of [...target].reverse()) {
|
|
223
|
+
const nodeReachable = reachable.get(nodeId) ?? /* @__PURE__ */ new Set();
|
|
224
|
+
const needMove = testSet.has(nodeId);
|
|
225
|
+
for (const childId of nodeReachable) testSet.add(childId);
|
|
226
|
+
if (!needMove) {
|
|
227
|
+
result.push(nodeId);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
let inserted = false;
|
|
231
|
+
for (let index = 0; index < result.length; index++) {
|
|
232
|
+
const parent = result[index];
|
|
233
|
+
const parentReachable = reachable.get(parent) ?? /* @__PURE__ */ new Set();
|
|
234
|
+
if (nodeReachable.has(parent)) {
|
|
235
|
+
if (parentReachable.has(nodeId)) result.push(nodeId);
|
|
236
|
+
else result.splice(index, 0, nodeId);
|
|
237
|
+
inserted = true;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!inserted) result.push(nodeId);
|
|
242
|
+
}
|
|
243
|
+
result.reverse();
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
buildTransitiveClosureForSort() {
|
|
247
|
+
const closure = /* @__PURE__ */ new Map();
|
|
248
|
+
for (const node of this.nodes.values()) closure.set(node.id, new Set(node.outputs));
|
|
249
|
+
const order = this.topologicalOrder();
|
|
250
|
+
for (const nodeId of [...order].reverse()) {
|
|
251
|
+
const node = this.at(nodeId);
|
|
252
|
+
if (!node) continue;
|
|
253
|
+
const nodeClosure = closure.get(nodeId) ?? /* @__PURE__ */ new Set();
|
|
254
|
+
for (const parentId of node.inputs) {
|
|
255
|
+
const parentClosure = closure.get(parentId) ?? /* @__PURE__ */ new Set();
|
|
256
|
+
for (const childId of nodeClosure) parentClosure.add(childId);
|
|
257
|
+
closure.set(parentId, parentClosure);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return closure;
|
|
261
|
+
}
|
|
262
|
+
transitiveReduction() {
|
|
263
|
+
const order = this.topologicalOrder();
|
|
264
|
+
const marked = /* @__PURE__ */ new Map();
|
|
265
|
+
order.forEach((nodeID) => {
|
|
266
|
+
if (marked.get(nodeID)) return;
|
|
267
|
+
const stack = [];
|
|
268
|
+
stack.push({
|
|
269
|
+
id: nodeID,
|
|
270
|
+
parents: []
|
|
271
|
+
});
|
|
272
|
+
while (stack.length > 0) {
|
|
273
|
+
const item = stack.splice(0, 1)[0];
|
|
274
|
+
const node = this.nodes.get(item.id);
|
|
275
|
+
if (node) node.outputs.forEach((child) => {
|
|
276
|
+
item.parents.forEach((parent) => this.removeEdge(parent, child));
|
|
277
|
+
stack.push({
|
|
278
|
+
id: child,
|
|
279
|
+
parents: [item.id, ...item.parents]
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
marked.set(item.id, true);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Finds a cycle in the graph.
|
|
288
|
+
*
|
|
289
|
+
* @returns {NodeID[] | null} The cycle if found, otherwise `null`.
|
|
290
|
+
* Uses non-recursive DFS.
|
|
291
|
+
*/
|
|
292
|
+
findCycle() {
|
|
293
|
+
const visited = /* @__PURE__ */ new Set();
|
|
294
|
+
const nodeStack = /* @__PURE__ */ new Set();
|
|
295
|
+
const parents = /* @__PURE__ */ new Map();
|
|
296
|
+
for (const nodeId of this.nodes.keys()) {
|
|
297
|
+
if (visited.has(nodeId)) continue;
|
|
298
|
+
const callStack = [];
|
|
299
|
+
callStack.push({
|
|
300
|
+
nodeId,
|
|
301
|
+
parentId: null
|
|
302
|
+
});
|
|
303
|
+
while (callStack.length > 0) {
|
|
304
|
+
const { nodeId, parentId } = callStack[callStack.length - 1];
|
|
305
|
+
if (visited.has(nodeId)) {
|
|
306
|
+
nodeStack.delete(nodeId);
|
|
307
|
+
callStack.pop();
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
visited.add(nodeId);
|
|
311
|
+
nodeStack.add(nodeId);
|
|
312
|
+
if (parentId !== null) parents.set(nodeId, parentId);
|
|
313
|
+
const currentNode = this.nodes.get(nodeId);
|
|
314
|
+
for (const child of currentNode.outputs) {
|
|
315
|
+
if (!visited.has(child)) {
|
|
316
|
+
callStack.push({
|
|
317
|
+
nodeId: child,
|
|
318
|
+
parentId: nodeId
|
|
319
|
+
});
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (!nodeStack.has(child)) continue;
|
|
323
|
+
const cycle = [];
|
|
324
|
+
let current = nodeId;
|
|
325
|
+
cycle.push(child);
|
|
326
|
+
while (current !== child) {
|
|
327
|
+
cycle.push(current);
|
|
328
|
+
current = parents.get(current);
|
|
329
|
+
}
|
|
330
|
+
cycle.push(child);
|
|
331
|
+
cycle.reverse();
|
|
332
|
+
return cycle;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
384
338
|
};
|
|
339
|
+
//#endregion
|
|
340
|
+
export { Graph, GraphNode };
|
|
341
|
+
|
|
385
342
|
//# sourceMappingURL=graph.js.map
|