@parcel/graph 3.0.4-nightly.3069 → 3.0.4-nightly.3071

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/lib/Graph.js CHANGED
@@ -257,6 +257,51 @@ class Graph {
257
257
  this._visited = visited;
258
258
  return null;
259
259
  }
260
+
261
+ // A post-order implementation of dfsFast
262
+ postOrderDfsFast(visit, startNodeId) {
263
+ let traversalStartNode = (0, _nullthrows().default)(startNodeId !== null && startNodeId !== void 0 ? startNodeId : this.rootNodeId, 'A start node is required to traverse');
264
+ this._assertHasNodeId(traversalStartNode);
265
+ let visited;
266
+ if (!this._visited || this._visited.capacity < this.nodes.length) {
267
+ this._visited = new _BitSet.BitSet(this.nodes.length);
268
+ visited = this._visited;
269
+ } else {
270
+ visited = this._visited;
271
+ visited.clear();
272
+ }
273
+ this._visited = null;
274
+ let stopped = false;
275
+ let actions = {
276
+ stop() {
277
+ stopped = true;
278
+ },
279
+ skipChildren() {
280
+ throw new Error('Calling skipChildren inside a post-order traversal is not allowed');
281
+ }
282
+ };
283
+ let queue = [traversalStartNode];
284
+ while (queue.length !== 0) {
285
+ let nodeId = queue[queue.length - 1];
286
+ if (!visited.has(nodeId)) {
287
+ visited.add(nodeId);
288
+ this.adjacencyList.forEachNodeIdConnectedFromReverse(nodeId, child => {
289
+ if (!visited.has(child)) {
290
+ queue.push(child);
291
+ }
292
+ return false;
293
+ });
294
+ } else {
295
+ queue.pop();
296
+ visit(nodeId, null, actions);
297
+ if (stopped) {
298
+ this._visited = visited;
299
+ return;
300
+ }
301
+ }
302
+ }
303
+ this._visited = visited;
304
+ }
260
305
  dfs({
261
306
  visit,
262
307
  startNodeId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/graph",
3
- "version": "3.0.4-nightly.3069+65f8e21ad",
3
+ "version": "3.0.4-nightly.3071+273f94c8e",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -22,5 +22,5 @@
22
22
  "dependencies": {
23
23
  "nullthrows": "^1.1.1"
24
24
  },
25
- "gitHead": "65f8e21ad8a7c8c0770bd8c008e17ab702c1a0ab"
25
+ "gitHead": "273f94c8e6e478d328e329bd9787789469463522"
26
26
  }
package/src/Graph.js CHANGED
@@ -388,6 +388,67 @@ export default class Graph<TNode, TEdgeType: number = 1> {
388
388
  return null;
389
389
  }
390
390
 
391
+ // A post-order implementation of dfsFast
392
+ postOrderDfsFast(
393
+ visit: GraphTraversalCallback<NodeId, TraversalActions>,
394
+ startNodeId: ?NodeId,
395
+ ): void {
396
+ let traversalStartNode = nullthrows(
397
+ startNodeId ?? this.rootNodeId,
398
+ 'A start node is required to traverse',
399
+ );
400
+ this._assertHasNodeId(traversalStartNode);
401
+
402
+ let visited;
403
+ if (!this._visited || this._visited.capacity < this.nodes.length) {
404
+ this._visited = new BitSet(this.nodes.length);
405
+ visited = this._visited;
406
+ } else {
407
+ visited = this._visited;
408
+ visited.clear();
409
+ }
410
+ this._visited = null;
411
+
412
+ let stopped = false;
413
+ let actions: TraversalActions = {
414
+ stop() {
415
+ stopped = true;
416
+ },
417
+ skipChildren() {
418
+ throw new Error(
419
+ 'Calling skipChildren inside a post-order traversal is not allowed',
420
+ );
421
+ },
422
+ };
423
+
424
+ let queue = [traversalStartNode];
425
+ while (queue.length !== 0) {
426
+ let nodeId = queue[queue.length - 1];
427
+
428
+ if (!visited.has(nodeId)) {
429
+ visited.add(nodeId);
430
+
431
+ this.adjacencyList.forEachNodeIdConnectedFromReverse(nodeId, child => {
432
+ if (!visited.has(child)) {
433
+ queue.push(child);
434
+ }
435
+ return false;
436
+ });
437
+ } else {
438
+ queue.pop();
439
+ visit(nodeId, null, actions);
440
+
441
+ if (stopped) {
442
+ this._visited = visited;
443
+ return;
444
+ }
445
+ }
446
+ }
447
+
448
+ this._visited = visited;
449
+ return;
450
+ }
451
+
391
452
  dfs<TContext>({
392
453
  visit,
393
454
  startNodeId,