@parcel/graph 2.7.1-nightly.2800 → 2.7.1-nightly.2802
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 -2
- package/package.json +3 -3
- package/src/AdjacencyList.js +11 -3
- package/src/Graph.js +1 -1
- package/test/AdjacencyList.test.js +15 -0
package/lib/AdjacencyList.js
CHANGED
@@ -284,8 +284,16 @@ class AdjacencyList {
|
|
284
284
|
|
285
285
|
|
286
286
|
hasEdge(from, to, type = 1) {
|
287
|
-
let
|
288
|
-
|
287
|
+
let hasEdge = type => {
|
288
|
+
let hash = this.#edges.hash(from, to, type);
|
289
|
+
return this.#edges.addressOf(hash, from, to, type) !== null;
|
290
|
+
};
|
291
|
+
|
292
|
+
if (Array.isArray(type)) {
|
293
|
+
return type.some(hasEdge);
|
294
|
+
}
|
295
|
+
|
296
|
+
return hasEdge(type);
|
289
297
|
}
|
290
298
|
/**
|
291
299
|
*
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/graph",
|
3
|
-
"version": "2.7.1-nightly.
|
3
|
+
"version": "2.7.1-nightly.2802+4ba031aa4",
|
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.
|
23
|
+
"@parcel/utils": "2.0.0-nightly.1179+4ba031aa4",
|
24
24
|
"nullthrows": "^1.1.1"
|
25
25
|
},
|
26
|
-
"gitHead": "
|
26
|
+
"gitHead": "4ba031aa44d14b48e97d8172daeae8c24a423294"
|
27
27
|
}
|
package/src/AdjacencyList.js
CHANGED
@@ -329,10 +329,18 @@ export default class AdjacencyList<TEdgeType: number = 1> {
|
|
329
329
|
hasEdge(
|
330
330
|
from: NodeId,
|
331
331
|
to: NodeId,
|
332
|
-
type: TEdgeType | NullEdgeType = 1,
|
332
|
+
type: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
|
333
333
|
): boolean {
|
334
|
-
let
|
335
|
-
|
334
|
+
let hasEdge = (type: TEdgeType | NullEdgeType) => {
|
335
|
+
let hash = this.#edges.hash(from, to, type);
|
336
|
+
return this.#edges.addressOf(hash, from, to, type) !== null;
|
337
|
+
};
|
338
|
+
|
339
|
+
if (Array.isArray(type)) {
|
340
|
+
return type.some(hasEdge);
|
341
|
+
}
|
342
|
+
|
343
|
+
return hasEdge(type);
|
336
344
|
}
|
337
345
|
|
338
346
|
/**
|
package/src/Graph.js
CHANGED
@@ -104,7 +104,7 @@ export default class Graph<TNode, TEdgeType: number = 1> {
|
|
104
104
|
hasEdge(
|
105
105
|
from: NodeId,
|
106
106
|
to: NodeId,
|
107
|
-
type?: TEdgeType | NullEdgeType = 1,
|
107
|
+
type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> = 1,
|
108
108
|
): boolean {
|
109
109
|
return this.adjacencyList.hasEdge(from, to, type);
|
110
110
|
}
|
@@ -243,6 +243,21 @@ describe('AdjacencyList', () => {
|
|
243
243
|
AdjacencyList.prototype.hash = originalHash;
|
244
244
|
});
|
245
245
|
|
246
|
+
it('hasEdge should accept an array of edge types', () => {
|
247
|
+
let graph = new AdjacencyList();
|
248
|
+
let a = graph.addNode();
|
249
|
+
let b = graph.addNode();
|
250
|
+
let c = graph.addNode();
|
251
|
+
|
252
|
+
graph.addEdge(a, b, 1);
|
253
|
+
graph.addEdge(b, c, 2);
|
254
|
+
|
255
|
+
assert.ok(!graph.hasEdge(a, b, [2, 3]));
|
256
|
+
assert.ok(graph.hasEdge(a, b, [1, 2]));
|
257
|
+
assert.ok(!graph.hasEdge(b, c, [1, 3]));
|
258
|
+
assert.ok(graph.hasEdge(b, c, [2, 3]));
|
259
|
+
});
|
260
|
+
|
246
261
|
describe('deserialize', function () {
|
247
262
|
this.timeout(10000);
|
248
263
|
|