@parcel/graph 3.1.1-nightly.3121 → 3.1.1-nightly.3124
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 +532 -159
- package/package.json +2 -2
- package/src/AdjacencyList.js +594 -184
- package/test/AdjacencyList.test.js +37 -23
@@ -19,18 +19,18 @@ describe('AdjacencyList', () => {
|
|
19
19
|
let id = graph.addNode();
|
20
20
|
assert.equal(id, 0);
|
21
21
|
assert.equal(graph.stats.nodes, 1);
|
22
|
+
let id2 = graph.addNode();
|
23
|
+
assert.equal(id2, 1);
|
24
|
+
assert.equal(graph.stats.nodes, 2);
|
22
25
|
});
|
23
26
|
|
24
|
-
it('addNode should resize nodes array
|
27
|
+
it('addNode should resize nodes array', () => {
|
25
28
|
let graph = new AdjacencyList();
|
26
29
|
let size = graph.serialize().nodes.byteLength;
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
graph.
|
31
|
-
graph.addEdge(a, b, 2);
|
32
|
-
graph.addEdge(a, b, 3);
|
33
|
-
graph.addEdge(a, b, 4);
|
30
|
+
graph.addNode();
|
31
|
+
graph.addNode();
|
32
|
+
graph.addNode();
|
33
|
+
graph.addNode();
|
34
34
|
assert(size < graph.serialize().nodes.byteLength);
|
35
35
|
});
|
36
36
|
|
@@ -168,6 +168,18 @@ describe('AdjacencyList', () => {
|
|
168
168
|
assert.equal(graph.addEdge(a, b), false);
|
169
169
|
});
|
170
170
|
|
171
|
+
it('addEdge should resize nodes array when necessary', () => {
|
172
|
+
let graph = new AdjacencyList();
|
173
|
+
let a = graph.addNode();
|
174
|
+
let b = graph.addNode();
|
175
|
+
let size = graph.serialize().nodes.byteLength;
|
176
|
+
graph.addEdge(a, b, 1);
|
177
|
+
graph.addEdge(a, b, 2);
|
178
|
+
graph.addEdge(a, b, 3);
|
179
|
+
graph.addEdge(a, b, 4);
|
180
|
+
assert(size < graph.serialize().nodes.byteLength);
|
181
|
+
});
|
182
|
+
|
171
183
|
it('addEdge should resize edges array when necessary', () => {
|
172
184
|
let graph = new AdjacencyList();
|
173
185
|
let size = graph.serialize().edges.byteLength;
|
@@ -226,21 +238,23 @@ describe('AdjacencyList', () => {
|
|
226
238
|
// $FlowFixMe[prop-missing]
|
227
239
|
AdjacencyList.prototype.hash = () => 1;
|
228
240
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
241
|
+
try {
|
242
|
+
let graph = new AdjacencyList({initialCapacity: 3});
|
243
|
+
let n0 = graph.addNode();
|
244
|
+
let n1 = graph.addNode();
|
245
|
+
graph.addEdge(n0, n1, 2);
|
246
|
+
graph.removeEdge(n0, n1, 2);
|
247
|
+
assert(graph.addEdge(n0, n1, 2));
|
248
|
+
assert(graph.stats.edges === 1);
|
249
|
+
assert(graph.stats.deleted === 1);
|
250
|
+
// Resize to reclaim deleted edge space.
|
251
|
+
graph.resizeEdges(2);
|
252
|
+
assert(graph.stats.edges === 1);
|
253
|
+
assert(graph.stats.deleted === 0);
|
254
|
+
} finally {
|
255
|
+
// $FlowFixMe[prop-missing]
|
256
|
+
AdjacencyList.prototype.hash = originalHash;
|
257
|
+
}
|
244
258
|
});
|
245
259
|
|
246
260
|
it('hasEdge should accept an array of edge types', () => {
|