@atlaspack/graph 3.2.1-dev.3565 → 3.2.1-dev.3566
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/AdjacencyList.js +10 -7
- package/lib/Graph.js +2 -2
- package/package.json +3 -3
- package/src/AdjacencyList.js +16 -7
- package/src/Graph.js +6 -2
- package/test/AdjacencyList.test.js +39 -0
package/lib/AdjacencyList.js
CHANGED
|
@@ -467,16 +467,19 @@ class AdjacencyList {
|
|
|
467
467
|
node = this.#nodes.next(node);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
|
-
forEachNodeIdConnectedTo(to, fn) {
|
|
470
|
+
forEachNodeIdConnectedTo(to, fn, type = 1) {
|
|
471
|
+
const matches = node => type === _Graph.ALL_EDGE_TYPES || type === this.#nodes.typeOf(node);
|
|
471
472
|
let node = this.#nodes.head(to);
|
|
472
473
|
while (node !== null) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
474
|
+
if (matches(node)) {
|
|
475
|
+
let edge = this.#nodes.firstIn(node);
|
|
476
|
+
while (edge !== null) {
|
|
477
|
+
let from = this.#edges.from(edge);
|
|
478
|
+
if (fn(from)) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
edge = this.#edges.nextIn(edge);
|
|
478
482
|
}
|
|
479
|
-
edge = this.#edges.nextIn(edge);
|
|
480
483
|
}
|
|
481
484
|
node = this.#nodes.next(node);
|
|
482
485
|
}
|
package/lib/Graph.js
CHANGED
|
@@ -85,9 +85,9 @@ class Graph {
|
|
|
85
85
|
hasEdge(from, to, type = 1) {
|
|
86
86
|
return this.adjacencyList.hasEdge(from, to, type);
|
|
87
87
|
}
|
|
88
|
-
forEachNodeIdConnectedTo(to, fn) {
|
|
88
|
+
forEachNodeIdConnectedTo(to, fn, type = ALL_EDGE_TYPES) {
|
|
89
89
|
this._assertHasNodeId(to);
|
|
90
|
-
this.adjacencyList.forEachNodeIdConnectedTo(to, fn);
|
|
90
|
+
this.adjacencyList.forEachNodeIdConnectedTo(to, fn, type);
|
|
91
91
|
}
|
|
92
92
|
forEachNodeIdConnectedFrom(from, fn, type = ALL_EDGE_TYPES) {
|
|
93
93
|
this._assertHasNodeId(from);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/graph",
|
|
3
|
-
"version": "3.2.1-dev.
|
|
3
|
+
"version": "3.2.1-dev.3566+facdfb05f",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/feature-flags": "2.12.1-dev.
|
|
19
|
+
"@atlaspack/feature-flags": "2.12.1-dev.3566+facdfb05f",
|
|
20
20
|
"nullthrows": "^1.1.1"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "facdfb05f693e50037a82a4afa101adf093fd8c9"
|
|
23
23
|
}
|
package/src/AdjacencyList.js
CHANGED
|
@@ -619,16 +619,25 @@ export default class AdjacencyList<TEdgeType: number = 1> {
|
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
-
forEachNodeIdConnectedTo(
|
|
622
|
+
forEachNodeIdConnectedTo(
|
|
623
|
+
to: NodeId,
|
|
624
|
+
fn: (nodeId: NodeId) => boolean | void,
|
|
625
|
+
type: AllEdgeTypes | TEdgeType | NullEdgeType = 1,
|
|
626
|
+
) {
|
|
627
|
+
const matches = (node) =>
|
|
628
|
+
type === ALL_EDGE_TYPES || type === this.#nodes.typeOf(node);
|
|
629
|
+
|
|
623
630
|
let node = this.#nodes.head(to);
|
|
624
631
|
while (node !== null) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
632
|
+
if (matches(node)) {
|
|
633
|
+
let edge = this.#nodes.firstIn(node);
|
|
634
|
+
while (edge !== null) {
|
|
635
|
+
let from = this.#edges.from(edge);
|
|
636
|
+
if (fn(from)) {
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
edge = this.#edges.nextIn(edge);
|
|
630
640
|
}
|
|
631
|
-
edge = this.#edges.nextIn(edge);
|
|
632
641
|
}
|
|
633
642
|
node = this.#nodes.next(node);
|
|
634
643
|
}
|
package/src/Graph.js
CHANGED
|
@@ -163,10 +163,14 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
|
163
163
|
return this.adjacencyList.hasEdge(from, to, type);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
forEachNodeIdConnectedTo(
|
|
166
|
+
forEachNodeIdConnectedTo(
|
|
167
|
+
to: NodeId,
|
|
168
|
+
fn: (nodeId: NodeId) => boolean | void,
|
|
169
|
+
type: AllEdgeTypes | TEdgeType | NullEdgeType = ALL_EDGE_TYPES,
|
|
170
|
+
) {
|
|
167
171
|
this._assertHasNodeId(to);
|
|
168
172
|
|
|
169
|
-
this.adjacencyList.forEachNodeIdConnectedTo(to, fn);
|
|
173
|
+
this.adjacencyList.forEachNodeIdConnectedTo(to, fn, type);
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
forEachNodeIdConnectedFrom(
|
|
@@ -7,6 +7,7 @@ import {Worker} from 'worker_threads';
|
|
|
7
7
|
|
|
8
8
|
import AdjacencyList, {NodeTypeMap, EdgeTypeMap} from '../src/AdjacencyList';
|
|
9
9
|
import {toNodeId} from '../src/types';
|
|
10
|
+
import {ALL_EDGE_TYPES} from '../src/Graph';
|
|
10
11
|
|
|
11
12
|
describe('AdjacencyList', () => {
|
|
12
13
|
it('constructor should initialize an empty graph', () => {
|
|
@@ -343,6 +344,44 @@ describe('AdjacencyList', () => {
|
|
|
343
344
|
|
|
344
345
|
assert.deepEqual(nodeIds, [a, c, b]);
|
|
345
346
|
});
|
|
347
|
+
|
|
348
|
+
it('respects the edge type', () => {
|
|
349
|
+
const graph = new AdjacencyList();
|
|
350
|
+
const a = graph.addNode();
|
|
351
|
+
const b = graph.addNode();
|
|
352
|
+
const c = graph.addNode();
|
|
353
|
+
|
|
354
|
+
graph.addEdge(a, b);
|
|
355
|
+
graph.addEdge(c, b, 2);
|
|
356
|
+
|
|
357
|
+
const nodeIds = [];
|
|
358
|
+
graph.forEachNodeIdConnectedTo(b, (id) => {
|
|
359
|
+
nodeIds.push(id);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
assert.deepEqual(nodeIds, [a]);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('iterates all edges if all edge type is provided', () => {
|
|
366
|
+
const graph = new AdjacencyList();
|
|
367
|
+
const a = graph.addNode();
|
|
368
|
+
const b = graph.addNode();
|
|
369
|
+
const c = graph.addNode();
|
|
370
|
+
|
|
371
|
+
graph.addEdge(a, b);
|
|
372
|
+
graph.addEdge(c, b, 2);
|
|
373
|
+
|
|
374
|
+
const nodeIds = [];
|
|
375
|
+
graph.forEachNodeIdConnectedTo(
|
|
376
|
+
b,
|
|
377
|
+
(id) => {
|
|
378
|
+
nodeIds.push(id);
|
|
379
|
+
},
|
|
380
|
+
ALL_EDGE_TYPES,
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
assert.deepEqual(nodeIds, [a, c]);
|
|
384
|
+
});
|
|
346
385
|
});
|
|
347
386
|
|
|
348
387
|
describe('forEachNodeIdConnectedFromReverse', () => {
|