@parcel/graph 2.5.1-nightly.2700 → 2.5.1-nightly.2708

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.
@@ -214,7 +214,7 @@ class AdjacencyList {
214
214
 
215
215
 
216
216
  addEdge(from, to, type = 1) {
217
- (0, _assert().default)(type > 0, `Unsupported edge type ${0}`);
217
+ (0, _assert().default)(type > 0, `Unsupported edge type ${type}`);
218
218
  let hash = this.#edges.hash(from, to, type);
219
219
  let edge = this.#edges.addressOf(hash, from, to, type); // The edge is already in the graph; do nothing.
220
220
 
@@ -378,6 +378,7 @@ class AdjacencyList {
378
378
  let matches = node => type === _Graph.ALL_EDGE_TYPES || (Array.isArray(type) ? type.includes(this.#nodes.typeOf(node)) : type === this.#nodes.typeOf(node));
379
379
 
380
380
  let nodes = [];
381
+ let seen = new Set();
381
382
  let node = this.#nodes.head(from);
382
383
 
383
384
  while (node !== null) {
@@ -385,7 +386,13 @@ class AdjacencyList {
385
386
  let edge = this.#nodes.firstOut(node);
386
387
 
387
388
  while (edge !== null) {
388
- nodes.push(this.#edges.to(edge));
389
+ let to = this.#edges.to(edge);
390
+
391
+ if (!seen.has(to)) {
392
+ nodes.push(to);
393
+ seen.add(to);
394
+ }
395
+
389
396
  edge = this.#edges.nextOut(edge);
390
397
  }
391
398
  }
@@ -404,6 +411,7 @@ class AdjacencyList {
404
411
  let matches = node => type === _Graph.ALL_EDGE_TYPES || (Array.isArray(type) ? type.includes(this.#nodes.typeOf(node)) : type === this.#nodes.typeOf(node));
405
412
 
406
413
  let nodes = [];
414
+ let seen = new Set();
407
415
  let node = this.#nodes.head(to);
408
416
 
409
417
  while (node !== null) {
@@ -411,7 +419,13 @@ class AdjacencyList {
411
419
  let edge = this.#nodes.firstIn(node);
412
420
 
413
421
  while (edge !== null) {
414
- nodes.push(this.#edges.from(edge));
422
+ let from = this.#edges.from(edge);
423
+
424
+ if (!seen.has(from)) {
425
+ nodes.push(from);
426
+ seen.add(from);
427
+ }
428
+
415
429
  edge = this.#edges.nextIn(edge);
416
430
  }
417
431
  }
@@ -539,7 +553,7 @@ class SharedTypeMap {
539
553
 
540
554
  get bufferSize() {
541
555
  return `${(this.data.byteLength / 1024 / 1024).toLocaleString(undefined, {
542
- minmumFractionDigits: 2,
556
+ minimumFractionDigits: 2,
543
557
  maximumFractionDigits: 2
544
558
  })} mb`;
545
559
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/graph",
3
- "version": "2.5.1-nightly.2700+c576758fb",
3
+ "version": "2.5.1-nightly.2708+504e54651",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -20,8 +20,8 @@
20
20
  "node": ">= 12.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/utils": "2.0.0-nightly.1077+c576758fb",
23
+ "@parcel/utils": "2.0.0-nightly.1085+504e54651",
24
24
  "nullthrows": "^1.1.1"
25
25
  },
26
- "gitHead": "c576758fb98fcc2a12a9c49328261219826a9655"
26
+ "gitHead": "504e54651a06993707d230941d46c702be60edc4"
27
27
  }
@@ -246,7 +246,7 @@ export default class AdjacencyList<TEdgeType: number = 1> {
246
246
  to: NodeId,
247
247
  type: TEdgeType | NullEdgeType = 1,
248
248
  ): boolean {
249
- assert(type > 0, `Unsupported edge type ${0}`);
249
+ assert(type > 0, `Unsupported edge type ${type}`);
250
250
 
251
251
  let hash = this.#edges.hash(from, to, type);
252
252
  let edge = this.#edges.addressOf(hash, from, to, type);
@@ -439,14 +439,18 @@ export default class AdjacencyList<TEdgeType: number = 1> {
439
439
  (Array.isArray(type)
440
440
  ? type.includes(this.#nodes.typeOf(node))
441
441
  : type === this.#nodes.typeOf(node));
442
-
443
442
  let nodes = [];
443
+ let seen = new Set<NodeId>();
444
444
  let node = this.#nodes.head(from);
445
445
  while (node !== null) {
446
446
  if (matches(node)) {
447
447
  let edge = this.#nodes.firstOut(node);
448
448
  while (edge !== null) {
449
- nodes.push(this.#edges.to(edge));
449
+ let to = this.#edges.to(edge);
450
+ if (!seen.has(to)) {
451
+ nodes.push(to);
452
+ seen.add(to);
453
+ }
450
454
  edge = this.#edges.nextOut(edge);
451
455
  }
452
456
  }
@@ -473,12 +477,17 @@ export default class AdjacencyList<TEdgeType: number = 1> {
473
477
  : type === this.#nodes.typeOf(node));
474
478
 
475
479
  let nodes = [];
480
+ let seen = new Set<NodeId>();
476
481
  let node = this.#nodes.head(to);
477
482
  while (node !== null) {
478
483
  if (matches(node)) {
479
484
  let edge = this.#nodes.firstIn(node);
480
485
  while (edge !== null) {
481
- nodes.push(this.#edges.from(edge));
486
+ let from = this.#edges.from(edge);
487
+ if (!seen.has(from)) {
488
+ nodes.push(from);
489
+ seen.add(from);
490
+ }
482
491
  edge = this.#edges.nextIn(edge);
483
492
  }
484
493
  }
@@ -600,7 +609,7 @@ export class SharedTypeMap<TItemType, THash, TAddress: number>
600
609
 
601
610
  get bufferSize(): string {
602
611
  return `${(this.data.byteLength / 1024 / 1024).toLocaleString(undefined, {
603
- minmumFractionDigits: 2,
612
+ minimumFractionDigits: 2,
604
613
  maximumFractionDigits: 2,
605
614
  })} mb`;
606
615
  }
@@ -57,6 +57,18 @@ describe('AdjacencyList', () => {
57
57
  assert.deepEqual(graph.getNodeIdsConnectedTo(node1), [0, 2, 4, 5, 6]);
58
58
  });
59
59
 
60
+ it('getNodeIdsConnectedTo and getNodeIdsConnectedFrom should remove duplicate values', () => {
61
+ let graph = new AdjacencyList();
62
+ let a = graph.addNode();
63
+ let b = graph.addNode();
64
+ let c = graph.addNode();
65
+ graph.addEdge(a, b);
66
+ graph.addEdge(a, c);
67
+ graph.addEdge(a, b, 2);
68
+ assert.deepEqual(graph.getNodeIdsConnectedFrom(a, -1), [b, c]);
69
+ assert.deepEqual(graph.getNodeIdsConnectedTo(b, -1), [a]);
70
+ });
71
+
60
72
  it('removeEdge should remove an edge of a specific type from the graph', () => {
61
73
  let graph = new AdjacencyList();
62
74
  let a = graph.addNode();