@hpcc-js/util 2.45.0 → 2.46.1

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.
Files changed (79) hide show
  1. package/LICENSE +43 -43
  2. package/dist/index.js +2290 -2289
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/lib-es6/__package__.js +3 -3
  7. package/lib-es6/array.js +84 -84
  8. package/lib-es6/array.js.map +1 -1
  9. package/lib-es6/cache.js +60 -60
  10. package/lib-es6/debounce.js +85 -85
  11. package/lib-es6/dictionary.js +61 -61
  12. package/lib-es6/dispatch.js +101 -101
  13. package/lib-es6/esp.js +32 -32
  14. package/lib-es6/graph.js +348 -348
  15. package/lib-es6/graph.js.map +1 -1
  16. package/lib-es6/graph2.js +603 -603
  17. package/lib-es6/graph2.js.map +1 -1
  18. package/lib-es6/hashSum.js +49 -49
  19. package/lib-es6/immutable.js +54 -54
  20. package/lib-es6/index.js +21 -21
  21. package/lib-es6/logging.js +177 -177
  22. package/lib-es6/logging.js.map +1 -1
  23. package/lib-es6/math.js +90 -90
  24. package/lib-es6/object.js +121 -121
  25. package/lib-es6/object.js.map +1 -1
  26. package/lib-es6/observer.js +79 -79
  27. package/lib-es6/platform.js +17 -17
  28. package/lib-es6/saxParser.js +125 -125
  29. package/lib-es6/stack.js +41 -41
  30. package/lib-es6/stateful.js +170 -170
  31. package/lib-es6/string.js +22 -22
  32. package/lib-es6/url.js +32 -32
  33. package/lib-es6/url.js.map +1 -1
  34. package/package.json +6 -21
  35. package/src/__package__.ts +2 -2
  36. package/src/array.ts +98 -98
  37. package/src/cache.ts +65 -65
  38. package/src/debounce.ts +88 -88
  39. package/src/dictionary.ts +69 -69
  40. package/src/dispatch.ts +119 -119
  41. package/src/esp.ts +32 -32
  42. package/src/graph.ts +353 -353
  43. package/src/graph2.ts +661 -661
  44. package/src/hashSum.ts +55 -55
  45. package/src/immutable.ts +57 -57
  46. package/src/index.ts +21 -21
  47. package/src/logging.ts +211 -211
  48. package/src/math.ts +92 -92
  49. package/src/object.ts +117 -117
  50. package/src/observer.ts +91 -91
  51. package/src/platform.ts +20 -20
  52. package/src/saxParser.ts +135 -135
  53. package/src/stack.ts +41 -41
  54. package/src/stateful.ts +178 -178
  55. package/src/string.ts +21 -21
  56. package/src/url.ts +27 -27
  57. package/types/__package__.d.ts +3 -3
  58. package/types/array.d.ts +13 -13
  59. package/types/cache.d.ts +20 -20
  60. package/types/debounce.d.ts +12 -12
  61. package/types/dictionary.d.ts +20 -20
  62. package/types/dispatch.d.ts +26 -26
  63. package/types/esp.d.ts +1 -1
  64. package/types/graph.d.ts +73 -73
  65. package/types/graph2.d.ts +111 -111
  66. package/types/hashSum.d.ts +1 -1
  67. package/types/immutable.d.ts +2 -2
  68. package/types/index.d.ts +21 -21
  69. package/types/logging.d.ts +57 -57
  70. package/types/math.d.ts +70 -70
  71. package/types/object.d.ts +48 -48
  72. package/types/observer.d.ts +18 -18
  73. package/types/platform.d.ts +5 -5
  74. package/types/saxParser.d.ts +28 -28
  75. package/types/stack.d.ts +28 -28
  76. package/types/stateful.d.ts +33 -33
  77. package/types/string.d.ts +2 -2
  78. package/types/url.d.ts +2 -2
  79. package/types-3.4/__package__.d.ts +2 -2
package/lib-es6/graph.js CHANGED
@@ -1,349 +1,349 @@
1
- import { __extends, __spreadArray } from "tslib";
2
- var GraphItem = /** @class */ (function () {
3
- function GraphItem(graph, parent) {
4
- this.props = {};
5
- this._graph = graph;
6
- this.parent = parent;
7
- }
8
- return GraphItem;
9
- }());
10
- export { GraphItem };
11
- var Subgraph = /** @class */ (function (_super) {
12
- __extends(Subgraph, _super);
13
- function Subgraph(graph, parent, _) {
14
- var _this = _super.call(this, graph, parent) || this;
15
- _this.subgraphs = [];
16
- _this.vertices = [];
17
- _this.edges = [];
18
- if (parent) { // Only needed for dummy root
19
- parent._addSubgraph(_this);
20
- }
21
- _this._ = _;
22
- return _this;
23
- }
24
- Subgraph.prototype.remove = function (full) {
25
- if (full === void 0) { full = true; }
26
- this._graph.removeSubgraph(this, full);
27
- };
28
- Subgraph.prototype.createSubgraph = function (_) {
29
- return this._graph.createSubgraph(this, _);
30
- };
31
- Subgraph.prototype._addSubgraph = function (subgraph) {
32
- if (this.subgraphs.indexOf(subgraph) >= 0) {
33
- throw new Error("Subgraph already exists");
34
- }
35
- this.subgraphs.push(subgraph);
36
- };
37
- Subgraph.prototype._removeSubgraph = function (subgraph) {
38
- var idx = this.subgraphs.indexOf(subgraph);
39
- if (idx < 0) {
40
- throw new Error("Subgraph does not exist");
41
- }
42
- this.subgraphs.splice(idx, 1);
43
- };
44
- Subgraph.prototype.removeAllSubgraphs = function () {
45
- for (var i = this.subgraphs.length - 1; i >= 0; --i) {
46
- this._graph.removeSubgraph(this.subgraphs[i], true);
47
- }
48
- };
49
- Subgraph.prototype.createVertex = function (_) {
50
- return this._graph.createVertex(this, _);
51
- };
52
- Subgraph.prototype._addVertex = function (vertex) {
53
- if (this.vertices.indexOf(vertex) >= 0) {
54
- throw new Error("Vertex already exists");
55
- }
56
- this.vertices.push(vertex);
57
- };
58
- Subgraph.prototype._removeVertex = function (vertex) {
59
- var idx = this.vertices.indexOf(vertex);
60
- if (idx < 0) {
61
- throw new Error("Vertex does not exist");
62
- }
63
- this.vertices.splice(idx, 1);
64
- };
65
- Subgraph.prototype.removeAllVertices = function () {
66
- for (var i = this.vertices.length - 1; i >= 0; --i) {
67
- this._graph.removeVertex(this.vertices[i], true);
68
- }
69
- };
70
- Subgraph.prototype.createEdge = function (source, target, _) {
71
- return this._graph.createEdge(this, source, target, _);
72
- };
73
- Subgraph.prototype._addEdge = function (edge) {
74
- if (this.edges.indexOf(edge) >= 0) {
75
- throw new Error("Edge already exists");
76
- }
77
- this.edges.push(edge);
78
- };
79
- Subgraph.prototype._removeEdge = function (edge) {
80
- var idx = this.edges.indexOf(edge);
81
- if (idx < 0) {
82
- throw new Error("Edge does not exist");
83
- }
84
- this.edges.splice(idx, 1);
85
- };
86
- Subgraph.prototype._add = function (item) {
87
- if (item instanceof Subgraph) {
88
- this._addSubgraph(item);
89
- }
90
- else if (item instanceof Vertex) {
91
- this._addVertex(item);
92
- }
93
- else {
94
- this._addEdge(item);
95
- }
96
- };
97
- return Subgraph;
98
- }(GraphItem));
99
- export { Subgraph };
100
- var Vertex = /** @class */ (function (_super) {
101
- __extends(Vertex, _super);
102
- function Vertex(graph, parent, _) {
103
- var _this = _super.call(this, graph, parent) || this;
104
- _this.inEdges = [];
105
- _this.outEdges = [];
106
- parent._addVertex(_this);
107
- _this._ = _;
108
- return _this;
109
- }
110
- Object.defineProperty(Vertex.prototype, "edges", {
111
- get: function () {
112
- return __spreadArray(__spreadArray([], this.inEdges), this.outEdges);
113
- },
114
- enumerable: false,
115
- configurable: true
116
- });
117
- Vertex.prototype.remove = function (full, _) {
118
- if (full === void 0) { full = true; }
119
- return this._graph.removeVertex(this, full, _);
120
- };
121
- Vertex.prototype.addInEdge = function (edge) {
122
- this.inEdges.push(edge);
123
- };
124
- Vertex.prototype.removeInEdge = function (edge) {
125
- var idx = this.inEdges.indexOf(edge);
126
- if (idx < 0) {
127
- throw new Error("In edge does not exist");
128
- }
129
- this.inEdges.splice(idx, 1);
130
- };
131
- Vertex.prototype.addOutEdge = function (edge) {
132
- this.outEdges.push(edge);
133
- };
134
- Vertex.prototype.removeOutEdge = function (edge) {
135
- var idx = this.outEdges.indexOf(edge);
136
- if (idx < 0) {
137
- throw new Error("Out edge does not exist");
138
- }
139
- this.outEdges.splice(idx, 1);
140
- };
141
- return Vertex;
142
- }(GraphItem));
143
- export { Vertex };
144
- var Edge = /** @class */ (function (_super) {
145
- __extends(Edge, _super);
146
- function Edge(graph, parent, source, target, _) {
147
- var _this = _super.call(this, graph, parent) || this;
148
- if (!source) {
149
- throw new Error("Missing source vertex");
150
- }
151
- if (!target) {
152
- throw new Error("Missing target vertex");
153
- }
154
- parent._addEdge(_this);
155
- _this.source = source;
156
- _this.source.addOutEdge(_this);
157
- _this.target = target;
158
- _this.target.addInEdge(_this);
159
- _this._ = _;
160
- return _this;
161
- }
162
- Edge.prototype.remove = function () {
163
- this._graph.removeEdge(this);
164
- };
165
- return Edge;
166
- }(GraphItem));
167
- export { Edge };
168
- var Graph = /** @class */ (function () {
169
- function Graph(idOf, _) {
170
- if (idOf === void 0) { idOf = function (item) { return "" + item._; }; }
171
- this._allSubgraphs = [];
172
- this._allSubgraphsMap = {};
173
- this._allVertices = [];
174
- this._allVerticesMap = {};
175
- this._allEdges = [];
176
- this._allEdgesMap = {};
177
- this.root = new Subgraph(this, null, _);
178
- this.idOf = idOf;
179
- }
180
- Graph.prototype.createSubgraph = function (parent, _) {
181
- var retVal = new Subgraph(this, parent || this.root, _);
182
- this._allSubgraphs.push(retVal);
183
- this._allSubgraphsMap[this.idOf(retVal)] = retVal;
184
- return retVal;
185
- };
186
- Graph.prototype.removeSubgraph = function (subgraph, full) {
187
- var _this = this;
188
- if (full === void 0) { full = true; }
189
- var idx = this._allSubgraphs.indexOf(subgraph);
190
- if (idx < 0) {
191
- throw new Error("Subgraph does not exist");
192
- }
193
- this._allSubgraphs.splice(idx, 1);
194
- delete this._allSubgraphsMap[this.idOf(subgraph)];
195
- if (subgraph.parent) {
196
- subgraph.parent._removeSubgraph(subgraph);
197
- }
198
- subgraph.edges.forEach(function (edge) { return full ? _this.removeEdge(edge) : subgraph.parent._addEdge(edge); });
199
- subgraph.vertices.forEach(function (vertex) { return full ? _this.removeVertex(vertex, full) : subgraph.parent._addVertex(vertex); });
200
- subgraph.subgraphs.forEach(function (childSubgraph) { return full ? _this.removeSubgraph(childSubgraph, full) : subgraph.parent._addSubgraph(childSubgraph); });
201
- };
202
- Object.defineProperty(Graph.prototype, "subgraphs", {
203
- get: function () {
204
- return this._allSubgraphs;
205
- },
206
- enumerable: false,
207
- configurable: true
208
- });
209
- Graph.prototype.subgraph = function (id) {
210
- return this._allSubgraphsMap[id];
211
- };
212
- Graph.prototype.createVertex = function (parent, _) {
213
- var retVal = new Vertex(this, parent, _);
214
- this._allVertices.push(retVal);
215
- this._allVerticesMap[this.idOf(retVal)] = retVal;
216
- return retVal;
217
- };
218
- Graph.prototype.removeVertex = function (vertex, full, _) {
219
- var _this = this;
220
- if (full === void 0) { full = true; }
221
- var idx = this._allVertices.indexOf(vertex);
222
- if (idx < 0) {
223
- throw new Error("Vertex does not exist");
224
- }
225
- this._allVertices.splice(idx, 1);
226
- delete this._allVerticesMap[this.idOf(vertex)];
227
- if (vertex.parent) {
228
- vertex.parent._removeVertex(vertex);
229
- }
230
- if (!full) {
231
- vertex.inEdges.forEach(function (inEdge) {
232
- vertex.outEdges.forEach(function (outEdge) {
233
- _this.createEdge(_this.root, inEdge.source, outEdge.target, _ ? _(inEdge.source._, outEdge.target._) : undefined);
234
- });
235
- });
236
- }
237
- vertex.inEdges.forEach(function (edge) { return _this.removeEdge(edge); });
238
- vertex.outEdges.forEach(function (edge) { return _this.removeEdge(edge); });
239
- };
240
- Object.defineProperty(Graph.prototype, "vertices", {
241
- get: function () {
242
- return this._allVertices;
243
- },
244
- enumerable: false,
245
- configurable: true
246
- });
247
- Graph.prototype.vertex = function (id) {
248
- return this._allVerticesMap[id];
249
- };
250
- Graph.prototype.createEdge = function (parent, source, target, _) {
251
- var retVal = new Edge(this, parent, source, target, _);
252
- this._allEdges.push(retVal);
253
- this._allEdgesMap[this.idOf(retVal)] = retVal;
254
- return retVal;
255
- };
256
- Graph.prototype.removeEdge = function (edge) {
257
- var idx = this._allEdges.indexOf(edge);
258
- if (idx < 0) {
259
- throw new Error("Edge does not exist");
260
- }
261
- this._allEdges.splice(idx, 1);
262
- delete this._allEdgesMap[this.idOf(edge)];
263
- if (edge.parent) {
264
- edge.parent._removeEdge(edge);
265
- }
266
- edge.source.removeOutEdge(edge);
267
- edge.target.removeInEdge(edge);
268
- };
269
- Object.defineProperty(Graph.prototype, "edges", {
270
- get: function () {
271
- return this._allEdges;
272
- },
273
- enumerable: false,
274
- configurable: true
275
- });
276
- Graph.prototype.edge = function (id) {
277
- return this._allEdgesMap[id];
278
- };
279
- Graph.prototype._walk = function (parent, visitor) {
280
- for (var _i = 0, _a = parent.subgraphs; _i < _a.length; _i++) {
281
- var subgraph = _a[_i];
282
- switch (visitor(subgraph)) {
283
- case "abort":
284
- return true;
285
- case "stepover":
286
- break;
287
- default:
288
- if (this._walk(subgraph, visitor))
289
- return true;
290
- }
291
- }
292
- for (var _b = 0, _c = parent.vertices; _b < _c.length; _b++) {
293
- var vertex = _c[_b];
294
- if (visitor(vertex) === "abort")
295
- return true;
296
- }
297
- };
298
- Graph.prototype.walk = function (visitor) {
299
- this._walk(this.root, visitor);
300
- for (var _i = 0, _a = this._allEdges; _i < _a.length; _i++) {
301
- var edge = _a[_i];
302
- if (visitor(edge) === "abort")
303
- return true;
304
- }
305
- };
306
- Graph.prototype.clone = function () {
307
- var ctor = this.constructor;
308
- var retVal = new ctor(this.idOf, this.root._);
309
- var map = ObjMap();
310
- map.put(this.root, retVal.root);
311
- this.walk(function (item) {
312
- var parent = map.get(item.parent);
313
- if (item instanceof Subgraph) {
314
- map.put(item, parent.createSubgraph(item._));
315
- }
316
- else if (item instanceof Vertex) {
317
- map.put(item, parent.createVertex(item._));
318
- }
319
- else if (item instanceof Edge) {
320
- var source = map.get(item.source);
321
- var target = map.get(item.target);
322
- parent.createEdge(source, target, item._);
323
- }
324
- });
325
- return retVal;
326
- };
327
- return Graph;
328
- }());
329
- export { Graph };
330
- function ObjMap() {
331
- var keys = [];
332
- var values = [];
333
- return {
334
- put: function (key, value) {
335
- var index = keys.indexOf(key);
336
- if (index === -1) {
337
- keys.push(key);
338
- values.push(value);
339
- }
340
- else {
341
- values[index] = value;
342
- }
343
- },
344
- get: function (key) {
345
- return values[keys.indexOf(key)];
346
- }
347
- };
348
- }
1
+ import { __extends, __spreadArray } from "tslib";
2
+ var GraphItem = /** @class */ (function () {
3
+ function GraphItem(graph, parent) {
4
+ this.props = {};
5
+ this._graph = graph;
6
+ this.parent = parent;
7
+ }
8
+ return GraphItem;
9
+ }());
10
+ export { GraphItem };
11
+ var Subgraph = /** @class */ (function (_super) {
12
+ __extends(Subgraph, _super);
13
+ function Subgraph(graph, parent, _) {
14
+ var _this = _super.call(this, graph, parent) || this;
15
+ _this.subgraphs = [];
16
+ _this.vertices = [];
17
+ _this.edges = [];
18
+ if (parent) { // Only needed for dummy root
19
+ parent._addSubgraph(_this);
20
+ }
21
+ _this._ = _;
22
+ return _this;
23
+ }
24
+ Subgraph.prototype.remove = function (full) {
25
+ if (full === void 0) { full = true; }
26
+ this._graph.removeSubgraph(this, full);
27
+ };
28
+ Subgraph.prototype.createSubgraph = function (_) {
29
+ return this._graph.createSubgraph(this, _);
30
+ };
31
+ Subgraph.prototype._addSubgraph = function (subgraph) {
32
+ if (this.subgraphs.indexOf(subgraph) >= 0) {
33
+ throw new Error("Subgraph already exists");
34
+ }
35
+ this.subgraphs.push(subgraph);
36
+ };
37
+ Subgraph.prototype._removeSubgraph = function (subgraph) {
38
+ var idx = this.subgraphs.indexOf(subgraph);
39
+ if (idx < 0) {
40
+ throw new Error("Subgraph does not exist");
41
+ }
42
+ this.subgraphs.splice(idx, 1);
43
+ };
44
+ Subgraph.prototype.removeAllSubgraphs = function () {
45
+ for (var i = this.subgraphs.length - 1; i >= 0; --i) {
46
+ this._graph.removeSubgraph(this.subgraphs[i], true);
47
+ }
48
+ };
49
+ Subgraph.prototype.createVertex = function (_) {
50
+ return this._graph.createVertex(this, _);
51
+ };
52
+ Subgraph.prototype._addVertex = function (vertex) {
53
+ if (this.vertices.indexOf(vertex) >= 0) {
54
+ throw new Error("Vertex already exists");
55
+ }
56
+ this.vertices.push(vertex);
57
+ };
58
+ Subgraph.prototype._removeVertex = function (vertex) {
59
+ var idx = this.vertices.indexOf(vertex);
60
+ if (idx < 0) {
61
+ throw new Error("Vertex does not exist");
62
+ }
63
+ this.vertices.splice(idx, 1);
64
+ };
65
+ Subgraph.prototype.removeAllVertices = function () {
66
+ for (var i = this.vertices.length - 1; i >= 0; --i) {
67
+ this._graph.removeVertex(this.vertices[i], true);
68
+ }
69
+ };
70
+ Subgraph.prototype.createEdge = function (source, target, _) {
71
+ return this._graph.createEdge(this, source, target, _);
72
+ };
73
+ Subgraph.prototype._addEdge = function (edge) {
74
+ if (this.edges.indexOf(edge) >= 0) {
75
+ throw new Error("Edge already exists");
76
+ }
77
+ this.edges.push(edge);
78
+ };
79
+ Subgraph.prototype._removeEdge = function (edge) {
80
+ var idx = this.edges.indexOf(edge);
81
+ if (idx < 0) {
82
+ throw new Error("Edge does not exist");
83
+ }
84
+ this.edges.splice(idx, 1);
85
+ };
86
+ Subgraph.prototype._add = function (item) {
87
+ if (item instanceof Subgraph) {
88
+ this._addSubgraph(item);
89
+ }
90
+ else if (item instanceof Vertex) {
91
+ this._addVertex(item);
92
+ }
93
+ else {
94
+ this._addEdge(item);
95
+ }
96
+ };
97
+ return Subgraph;
98
+ }(GraphItem));
99
+ export { Subgraph };
100
+ var Vertex = /** @class */ (function (_super) {
101
+ __extends(Vertex, _super);
102
+ function Vertex(graph, parent, _) {
103
+ var _this = _super.call(this, graph, parent) || this;
104
+ _this.inEdges = [];
105
+ _this.outEdges = [];
106
+ parent._addVertex(_this);
107
+ _this._ = _;
108
+ return _this;
109
+ }
110
+ Object.defineProperty(Vertex.prototype, "edges", {
111
+ get: function () {
112
+ return __spreadArray(__spreadArray([], this.inEdges, true), this.outEdges, true);
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ Vertex.prototype.remove = function (full, _) {
118
+ if (full === void 0) { full = true; }
119
+ return this._graph.removeVertex(this, full, _);
120
+ };
121
+ Vertex.prototype.addInEdge = function (edge) {
122
+ this.inEdges.push(edge);
123
+ };
124
+ Vertex.prototype.removeInEdge = function (edge) {
125
+ var idx = this.inEdges.indexOf(edge);
126
+ if (idx < 0) {
127
+ throw new Error("In edge does not exist");
128
+ }
129
+ this.inEdges.splice(idx, 1);
130
+ };
131
+ Vertex.prototype.addOutEdge = function (edge) {
132
+ this.outEdges.push(edge);
133
+ };
134
+ Vertex.prototype.removeOutEdge = function (edge) {
135
+ var idx = this.outEdges.indexOf(edge);
136
+ if (idx < 0) {
137
+ throw new Error("Out edge does not exist");
138
+ }
139
+ this.outEdges.splice(idx, 1);
140
+ };
141
+ return Vertex;
142
+ }(GraphItem));
143
+ export { Vertex };
144
+ var Edge = /** @class */ (function (_super) {
145
+ __extends(Edge, _super);
146
+ function Edge(graph, parent, source, target, _) {
147
+ var _this = _super.call(this, graph, parent) || this;
148
+ if (!source) {
149
+ throw new Error("Missing source vertex");
150
+ }
151
+ if (!target) {
152
+ throw new Error("Missing target vertex");
153
+ }
154
+ parent._addEdge(_this);
155
+ _this.source = source;
156
+ _this.source.addOutEdge(_this);
157
+ _this.target = target;
158
+ _this.target.addInEdge(_this);
159
+ _this._ = _;
160
+ return _this;
161
+ }
162
+ Edge.prototype.remove = function () {
163
+ this._graph.removeEdge(this);
164
+ };
165
+ return Edge;
166
+ }(GraphItem));
167
+ export { Edge };
168
+ var Graph = /** @class */ (function () {
169
+ function Graph(idOf, _) {
170
+ if (idOf === void 0) { idOf = function (item) { return "" + item._; }; }
171
+ this._allSubgraphs = [];
172
+ this._allSubgraphsMap = {};
173
+ this._allVertices = [];
174
+ this._allVerticesMap = {};
175
+ this._allEdges = [];
176
+ this._allEdgesMap = {};
177
+ this.root = new Subgraph(this, null, _);
178
+ this.idOf = idOf;
179
+ }
180
+ Graph.prototype.createSubgraph = function (parent, _) {
181
+ var retVal = new Subgraph(this, parent || this.root, _);
182
+ this._allSubgraphs.push(retVal);
183
+ this._allSubgraphsMap[this.idOf(retVal)] = retVal;
184
+ return retVal;
185
+ };
186
+ Graph.prototype.removeSubgraph = function (subgraph, full) {
187
+ var _this = this;
188
+ if (full === void 0) { full = true; }
189
+ var idx = this._allSubgraphs.indexOf(subgraph);
190
+ if (idx < 0) {
191
+ throw new Error("Subgraph does not exist");
192
+ }
193
+ this._allSubgraphs.splice(idx, 1);
194
+ delete this._allSubgraphsMap[this.idOf(subgraph)];
195
+ if (subgraph.parent) {
196
+ subgraph.parent._removeSubgraph(subgraph);
197
+ }
198
+ subgraph.edges.forEach(function (edge) { return full ? _this.removeEdge(edge) : subgraph.parent._addEdge(edge); });
199
+ subgraph.vertices.forEach(function (vertex) { return full ? _this.removeVertex(vertex, full) : subgraph.parent._addVertex(vertex); });
200
+ subgraph.subgraphs.forEach(function (childSubgraph) { return full ? _this.removeSubgraph(childSubgraph, full) : subgraph.parent._addSubgraph(childSubgraph); });
201
+ };
202
+ Object.defineProperty(Graph.prototype, "subgraphs", {
203
+ get: function () {
204
+ return this._allSubgraphs;
205
+ },
206
+ enumerable: false,
207
+ configurable: true
208
+ });
209
+ Graph.prototype.subgraph = function (id) {
210
+ return this._allSubgraphsMap[id];
211
+ };
212
+ Graph.prototype.createVertex = function (parent, _) {
213
+ var retVal = new Vertex(this, parent, _);
214
+ this._allVertices.push(retVal);
215
+ this._allVerticesMap[this.idOf(retVal)] = retVal;
216
+ return retVal;
217
+ };
218
+ Graph.prototype.removeVertex = function (vertex, full, _) {
219
+ var _this = this;
220
+ if (full === void 0) { full = true; }
221
+ var idx = this._allVertices.indexOf(vertex);
222
+ if (idx < 0) {
223
+ throw new Error("Vertex does not exist");
224
+ }
225
+ this._allVertices.splice(idx, 1);
226
+ delete this._allVerticesMap[this.idOf(vertex)];
227
+ if (vertex.parent) {
228
+ vertex.parent._removeVertex(vertex);
229
+ }
230
+ if (!full) {
231
+ vertex.inEdges.forEach(function (inEdge) {
232
+ vertex.outEdges.forEach(function (outEdge) {
233
+ _this.createEdge(_this.root, inEdge.source, outEdge.target, _ ? _(inEdge.source._, outEdge.target._) : undefined);
234
+ });
235
+ });
236
+ }
237
+ vertex.inEdges.forEach(function (edge) { return _this.removeEdge(edge); });
238
+ vertex.outEdges.forEach(function (edge) { return _this.removeEdge(edge); });
239
+ };
240
+ Object.defineProperty(Graph.prototype, "vertices", {
241
+ get: function () {
242
+ return this._allVertices;
243
+ },
244
+ enumerable: false,
245
+ configurable: true
246
+ });
247
+ Graph.prototype.vertex = function (id) {
248
+ return this._allVerticesMap[id];
249
+ };
250
+ Graph.prototype.createEdge = function (parent, source, target, _) {
251
+ var retVal = new Edge(this, parent, source, target, _);
252
+ this._allEdges.push(retVal);
253
+ this._allEdgesMap[this.idOf(retVal)] = retVal;
254
+ return retVal;
255
+ };
256
+ Graph.prototype.removeEdge = function (edge) {
257
+ var idx = this._allEdges.indexOf(edge);
258
+ if (idx < 0) {
259
+ throw new Error("Edge does not exist");
260
+ }
261
+ this._allEdges.splice(idx, 1);
262
+ delete this._allEdgesMap[this.idOf(edge)];
263
+ if (edge.parent) {
264
+ edge.parent._removeEdge(edge);
265
+ }
266
+ edge.source.removeOutEdge(edge);
267
+ edge.target.removeInEdge(edge);
268
+ };
269
+ Object.defineProperty(Graph.prototype, "edges", {
270
+ get: function () {
271
+ return this._allEdges;
272
+ },
273
+ enumerable: false,
274
+ configurable: true
275
+ });
276
+ Graph.prototype.edge = function (id) {
277
+ return this._allEdgesMap[id];
278
+ };
279
+ Graph.prototype._walk = function (parent, visitor) {
280
+ for (var _i = 0, _a = parent.subgraphs; _i < _a.length; _i++) {
281
+ var subgraph = _a[_i];
282
+ switch (visitor(subgraph)) {
283
+ case "abort":
284
+ return true;
285
+ case "stepover":
286
+ break;
287
+ default:
288
+ if (this._walk(subgraph, visitor))
289
+ return true;
290
+ }
291
+ }
292
+ for (var _b = 0, _c = parent.vertices; _b < _c.length; _b++) {
293
+ var vertex = _c[_b];
294
+ if (visitor(vertex) === "abort")
295
+ return true;
296
+ }
297
+ };
298
+ Graph.prototype.walk = function (visitor) {
299
+ this._walk(this.root, visitor);
300
+ for (var _i = 0, _a = this._allEdges; _i < _a.length; _i++) {
301
+ var edge = _a[_i];
302
+ if (visitor(edge) === "abort")
303
+ return true;
304
+ }
305
+ };
306
+ Graph.prototype.clone = function () {
307
+ var ctor = this.constructor;
308
+ var retVal = new ctor(this.idOf, this.root._);
309
+ var map = ObjMap();
310
+ map.put(this.root, retVal.root);
311
+ this.walk(function (item) {
312
+ var parent = map.get(item.parent);
313
+ if (item instanceof Subgraph) {
314
+ map.put(item, parent.createSubgraph(item._));
315
+ }
316
+ else if (item instanceof Vertex) {
317
+ map.put(item, parent.createVertex(item._));
318
+ }
319
+ else if (item instanceof Edge) {
320
+ var source = map.get(item.source);
321
+ var target = map.get(item.target);
322
+ parent.createEdge(source, target, item._);
323
+ }
324
+ });
325
+ return retVal;
326
+ };
327
+ return Graph;
328
+ }());
329
+ export { Graph };
330
+ function ObjMap() {
331
+ var keys = [];
332
+ var values = [];
333
+ return {
334
+ put: function (key, value) {
335
+ var index = keys.indexOf(key);
336
+ if (index === -1) {
337
+ keys.push(key);
338
+ values.push(value);
339
+ }
340
+ else {
341
+ values[index] = value;
342
+ }
343
+ },
344
+ get: function (key) {
345
+ return values[keys.indexOf(key)];
346
+ }
347
+ };
348
+ }
349
349
  //# sourceMappingURL=graph.js.map