@graphty/algorithms 1.7.3 → 1.8.1

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.
Files changed (87) hide show
  1. package/dist/algorithms.d.ts +2 -37
  2. package/dist/algorithms.js +736 -223
  3. package/dist/algorithms.js.map +1 -1
  4. package/dist/algorithms.standalone.js +24524 -0
  5. package/dist/algorithms.standalone.js.map +1 -0
  6. package/dist/src/algorithms/centrality/betweenness.d.ts +16 -11
  7. package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
  8. package/dist/src/algorithms/centrality/betweenness.js +17 -0
  9. package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
  10. package/dist/src/core/graph.d.ts +10 -0
  11. package/dist/src/core/graph.d.ts.map +1 -1
  12. package/dist/src/core/graph.js +31 -2
  13. package/dist/src/core/graph.js.map +1 -1
  14. package/dist/src/index.d.ts +10 -0
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +7 -0
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/indexed/accelerator.d.ts +161 -0
  19. package/dist/src/indexed/accelerator.d.ts.map +1 -0
  20. package/dist/src/indexed/accelerator.js +60 -0
  21. package/dist/src/indexed/accelerator.js.map +1 -0
  22. package/dist/src/indexed/bfs.d.ts +28 -0
  23. package/dist/src/indexed/bfs.d.ts.map +1 -0
  24. package/dist/src/indexed/bfs.js +39 -0
  25. package/dist/src/indexed/bfs.js.map +1 -0
  26. package/dist/src/indexed/common-neighbors.d.ts +17 -0
  27. package/dist/src/indexed/common-neighbors.d.ts.map +1 -0
  28. package/dist/src/indexed/common-neighbors.js +41 -0
  29. package/dist/src/indexed/common-neighbors.js.map +1 -0
  30. package/dist/src/indexed/components.d.ts +28 -0
  31. package/dist/src/indexed/components.d.ts.map +1 -0
  32. package/dist/src/indexed/components.js +58 -0
  33. package/dist/src/indexed/components.js.map +1 -0
  34. package/dist/src/indexed/dijkstra.d.ts +63 -0
  35. package/dist/src/indexed/dijkstra.d.ts.map +1 -0
  36. package/dist/src/indexed/dijkstra.js +98 -0
  37. package/dist/src/indexed/dijkstra.js.map +1 -0
  38. package/dist/src/indexed/index.d.ts +22 -0
  39. package/dist/src/indexed/index.d.ts.map +1 -0
  40. package/dist/src/indexed/index.js +22 -0
  41. package/dist/src/indexed/index.js.map +1 -0
  42. package/dist/src/indexed/mst.d.ts +26 -0
  43. package/dist/src/indexed/mst.d.ts.map +1 -0
  44. package/dist/src/indexed/mst.js +48 -0
  45. package/dist/src/indexed/mst.js.map +1 -0
  46. package/dist/src/indexed/pagerank.d.ts +30 -0
  47. package/dist/src/indexed/pagerank.d.ts.map +1 -0
  48. package/dist/src/indexed/pagerank.js +50 -0
  49. package/dist/src/indexed/pagerank.js.map +1 -0
  50. package/dist/src/indexed/structures/arc-source.d.ts +13 -0
  51. package/dist/src/indexed/structures/arc-source.d.ts.map +1 -0
  52. package/dist/src/indexed/structures/arc-source.js +25 -0
  53. package/dist/src/indexed/structures/arc-source.js.map +1 -0
  54. package/dist/src/indexed/structures/index.d.ts +9 -0
  55. package/dist/src/indexed/structures/index.d.ts.map +1 -0
  56. package/dist/src/indexed/structures/index.js +9 -0
  57. package/dist/src/indexed/structures/index.js.map +1 -0
  58. package/dist/src/indexed/structures/min-heap.d.ts +44 -0
  59. package/dist/src/indexed/structures/min-heap.d.ts.map +1 -0
  60. package/dist/src/indexed/structures/min-heap.js +112 -0
  61. package/dist/src/indexed/structures/min-heap.js.map +1 -0
  62. package/dist/src/indexed/structures/union-find.d.ts +39 -0
  63. package/dist/src/indexed/structures/union-find.d.ts.map +1 -0
  64. package/dist/src/indexed/structures/union-find.js +70 -0
  65. package/dist/src/indexed/structures/union-find.js.map +1 -0
  66. package/dist/src/indexed/to-snapshot.d.ts +38 -0
  67. package/dist/src/indexed/to-snapshot.d.ts.map +1 -0
  68. package/dist/src/indexed/to-snapshot.js +58 -0
  69. package/dist/src/indexed/to-snapshot.js.map +1 -0
  70. package/dist/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +7 -3
  72. package/src/algorithms/centrality/betweenness.ts +36 -11
  73. package/src/core/graph.ts +35 -2
  74. package/src/index.ts +46 -0
  75. package/src/indexed/accelerator.ts +225 -0
  76. package/src/indexed/bfs.ts +57 -0
  77. package/src/indexed/common-neighbors.ts +46 -0
  78. package/src/indexed/components.ts +78 -0
  79. package/src/indexed/dijkstra.ts +134 -0
  80. package/src/indexed/index.ts +28 -0
  81. package/src/indexed/mst.ts +62 -0
  82. package/src/indexed/pagerank.ts +73 -0
  83. package/src/indexed/structures/arc-source.ts +25 -0
  84. package/src/indexed/structures/index.ts +9 -0
  85. package/src/indexed/structures/min-heap.ts +122 -0
  86. package/src/indexed/structures/union-find.ts +74 -0
  87. package/src/indexed/to-snapshot.ts +78 -0
@@ -1,3 +1,7 @@
1
+ import { INVALID_INDEX, renumberPartition, GraphBuilder } from "@graphty/graph-format";
2
+ function isMirror(source, target) {
3
+ return typeof source === typeof target ? source > target : typeof source > typeof target;
4
+ }
1
5
  class Graph {
2
6
  /**
3
7
  * Creates a new Graph instance.
@@ -14,6 +18,7 @@ class Graph {
14
18
  this.adjacencyList = /* @__PURE__ */ new Map();
15
19
  this.incomingEdges = /* @__PURE__ */ new Map();
16
20
  this.edgeCount = 0;
21
+ this.mutations = 0;
17
22
  }
18
23
  /**
19
24
  * Add a node to the graph
@@ -27,6 +32,7 @@ class Graph {
27
32
  if (this.config.directed) {
28
33
  this.incomingEdges.set(id, /* @__PURE__ */ new Map());
29
34
  }
35
+ this.mutations++;
30
36
  }
31
37
  }
32
38
  /**
@@ -63,6 +69,7 @@ class Graph {
63
69
  if (this.config.directed) {
64
70
  this.incomingEdges.delete(id);
65
71
  }
72
+ this.mutations++;
66
73
  return true;
67
74
  }
68
75
  /**
@@ -101,6 +108,7 @@ class Graph {
101
108
  }
102
109
  }
103
110
  this.edgeCount++;
111
+ this.mutations++;
104
112
  }
105
113
  /**
106
114
  * Remove an edge from the graph
@@ -126,6 +134,7 @@ class Graph {
126
134
  }
127
135
  }
128
136
  this.edgeCount--;
137
+ this.mutations++;
129
138
  return true;
130
139
  }
131
140
  /**
@@ -171,6 +180,17 @@ class Graph {
171
180
  get nodeCount() {
172
181
  return this.nodeMap.size;
173
182
  }
183
+ /**
184
+ * A counter that increases on every topology change (`addNode` of a new id, `removeNode`,
185
+ * `addEdge`, `removeEdge`, `clear`) and never on a read. Callers memoise derived structures on
186
+ * `(graph, mutationCount)`; graph-format design 14.1 rule 4 names this counter, and `toSnapshot`
187
+ * is its first consumer. It is monotone and is NOT reset by `clear()`: a reset could hand a
188
+ * stale cache entry a matching key.
189
+ * @returns The number of topology changes made to this graph
190
+ */
191
+ get mutationCount() {
192
+ return this.mutations;
193
+ }
174
194
  /**
175
195
  * Get the number of edges in the graph
176
196
  * @returns The total count of edges
@@ -199,7 +219,7 @@ class Graph {
199
219
  *edges() {
200
220
  for (const [source, edges] of this.adjacencyList) {
201
221
  for (const edge of edges.values()) {
202
- if (!this.config.directed && source > edge.target) {
222
+ if (!this.config.directed && isMirror(source, edge.target)) {
203
223
  continue;
204
224
  }
205
225
  yield edge;
@@ -297,6 +317,7 @@ class Graph {
297
317
  this.adjacencyList.clear();
298
318
  this.incomingEdges.clear();
299
319
  this.edgeCount = 0;
320
+ this.mutations++;
300
321
  }
301
322
  /**
302
323
  * Get the number of unique edges in the graph
@@ -425,39 +446,39 @@ function requireSparseTypedFastBitSet() {
425
446
  }
426
447
  return newWords;
427
448
  };
428
- SparseTypedFastBitSet2.prototype.add = function(index) {
429
- var type = this.resize(index);
449
+ SparseTypedFastBitSet2.prototype.add = function(index2) {
450
+ var type = this.resize(index2);
430
451
  if (type === Type.ARRAY) {
431
452
  var array = this.data;
432
453
  if (this.arraySize === 0) {
433
- array[this.arraySize++] = index;
454
+ array[this.arraySize++] = index2;
434
455
  return;
435
456
  }
436
- var offset = array.indexOf(index);
457
+ var offset = array.indexOf(index2);
437
458
  if (offset === -1 || offset >= this.arraySize) {
438
459
  var biggest = array[0];
439
- if (index > biggest) {
440
- array[0] = index;
460
+ if (index2 > biggest) {
461
+ array[0] = index2;
441
462
  array[this.arraySize++] = biggest;
442
463
  } else {
443
- array[this.arraySize++] = index;
464
+ array[this.arraySize++] = index2;
444
465
  }
445
466
  }
446
467
  } else {
447
- this.data[index >>> 5] |= 1 << index;
468
+ this.data[index2 >>> 5] |= 1 << index2;
448
469
  }
449
470
  };
450
- SparseTypedFastBitSet2.prototype.flip = function(index) {
451
- var type = this.resize(index);
471
+ SparseTypedFastBitSet2.prototype.flip = function(index2) {
472
+ var type = this.resize(index2);
452
473
  if (type === Type.ARRAY) {
453
474
  var array = this.data;
454
- var arrayIndex = array.indexOf(index);
475
+ var arrayIndex = array.indexOf(index2);
455
476
  if (arrayIndex === -1) {
456
- if (this.arraySize > 0 && index > array[0]) {
477
+ if (this.arraySize > 0 && index2 > array[0]) {
457
478
  array[this.arraySize++] = array[0];
458
- array[0] = index;
479
+ array[0] = index2;
459
480
  } else {
460
- array[this.arraySize++] = index;
481
+ array[this.arraySize++] = index2;
461
482
  }
462
483
  } else {
463
484
  if (arrayIndex === 0 && this.arraySize > 1) {
@@ -476,18 +497,18 @@ function requireSparseTypedFastBitSet() {
476
497
  }
477
498
  }
478
499
  } else {
479
- this.data[index >>> 5] ^= 1 << index;
500
+ this.data[index2 >>> 5] ^= 1 << index2;
480
501
  }
481
502
  };
482
503
  SparseTypedFastBitSet2.prototype.clear = function() {
483
504
  this.arraySize = 0;
484
505
  this.data = new Uint32Array(8);
485
506
  };
486
- SparseTypedFastBitSet2.prototype.remove = function(index) {
487
- var type = this.resize(index);
507
+ SparseTypedFastBitSet2.prototype.remove = function(index2) {
508
+ var type = this.resize(index2);
488
509
  if (type === Type.ARRAY) {
489
510
  var array = this.data;
490
- var arrayIndex = array.indexOf(index);
511
+ var arrayIndex = array.indexOf(index2);
491
512
  if (arrayIndex !== -1 && arrayIndex < this.arraySize) {
492
513
  if (arrayIndex == this.arraySize - 1) {
493
514
  this.arraySize--;
@@ -507,7 +528,7 @@ function requireSparseTypedFastBitSet() {
507
528
  }
508
529
  }
509
530
  } else {
510
- this.data[index >>> 5] &= ~(1 << index);
531
+ this.data[index2 >>> 5] &= ~(1 << index2);
511
532
  }
512
533
  };
513
534
  SparseTypedFastBitSet2.prototype.addRange = function(start, end) {
@@ -609,40 +630,40 @@ function requireSparseTypedFastBitSet() {
609
630
  }
610
631
  return true;
611
632
  };
612
- SparseTypedFastBitSet2.prototype.has = function(index) {
633
+ SparseTypedFastBitSet2.prototype.has = function(index2) {
613
634
  if (this.arraySize === -1) {
614
- return (this.data[index >>> 5] & 1 << index) !== 0;
635
+ return (this.data[index2 >>> 5] & 1 << index2) !== 0;
615
636
  } else {
616
- var offset = this.data.indexOf(index);
637
+ var offset = this.data.indexOf(index2);
617
638
  return offset !== -1 && offset < this.arraySize;
618
639
  }
619
640
  };
620
- SparseTypedFastBitSet2.prototype.checkedAdd = function(index) {
621
- var type = this.resize(index);
641
+ SparseTypedFastBitSet2.prototype.checkedAdd = function(index2) {
642
+ var type = this.resize(index2);
622
643
  if (type === Type.ARRAY) {
623
644
  var array = this.data;
624
645
  if (this.arraySize === 0) {
625
- array[this.arraySize++] = index;
646
+ array[this.arraySize++] = index2;
626
647
  return 1;
627
648
  }
628
- var offset = array.indexOf(index);
649
+ var offset = array.indexOf(index2);
629
650
  if (offset === -1 || offset >= this.arraySize) {
630
651
  var biggest = array[0];
631
- if (index > biggest) {
632
- array[0] = index;
652
+ if (index2 > biggest) {
653
+ array[0] = index2;
633
654
  array[this.arraySize++] = biggest;
634
655
  } else {
635
- array[this.arraySize++] = index;
656
+ array[this.arraySize++] = index2;
636
657
  }
637
658
  return 1;
638
659
  }
639
660
  return 0;
640
661
  } else {
641
662
  var words = this.data;
642
- var word = words[index >>> 5];
643
- var newword = word | 1 << index;
644
- words[index >>> 5] = newword;
645
- return (newword ^ word) >>> index;
663
+ var word = words[index2 >>> 5];
664
+ var newword = word | 1 << index2;
665
+ words[index2 >>> 5] = newword;
666
+ return (newword ^ word) >>> index2;
646
667
  }
647
668
  };
648
669
  SparseTypedFastBitSet2.prototype.trim = function() {
@@ -688,15 +709,15 @@ function requireSparseTypedFastBitSet() {
688
709
  }
689
710
  }
690
711
  };
691
- SparseTypedFastBitSet2.prototype.resize = function(index, capacity) {
712
+ SparseTypedFastBitSet2.prototype.resize = function(index2, capacity) {
692
713
  if (capacity === void 0) {
693
714
  capacity = 0;
694
715
  }
695
716
  if (this.arraySize === -1) {
696
717
  var words = this.data;
697
- if (words.length << 5 > index)
718
+ if (words.length << 5 > index2)
698
719
  return Type.BITSET;
699
- var count = index + 32 >>> 5;
720
+ var count = index2 + 32 >>> 5;
700
721
  var newwords = new Uint32Array(count << 1);
701
722
  newwords.set(words);
702
723
  this.data = newwords;
@@ -712,7 +733,7 @@ function requireSparseTypedFastBitSet() {
712
733
  this.data = newData;
713
734
  return Type.ARRAY;
714
735
  } else {
715
- var count = Math.max(array[0], index) + 32 >>> 5;
736
+ var count = Math.max(array[0], index2) + 32 >>> 5;
716
737
  if (count > array.length + capacity && array.length + capacity << 1 < 1024) {
717
738
  var newData = new Uint32Array(array.length + capacity << 1);
718
739
  newData.set(array);
@@ -904,13 +925,13 @@ function requireSparseTypedFastBitSet() {
904
925
  var otherArray = otherbitmap.data;
905
926
  var newSize = 0;
906
927
  for (var i = 0; i < otherbitmap.arraySize; i++) {
907
- var index = otherArray[i];
908
- if (this.has(index)) {
909
- if (newSize > 0 && index > newWord[0]) {
928
+ var index2 = otherArray[i];
929
+ if (this.has(index2)) {
930
+ if (newSize > 0 && index2 > newWord[0]) {
910
931
  newWord[newSize++] = newWord[0];
911
- newWord[0] = index;
932
+ newWord[0] = index2;
912
933
  } else {
913
- newWord[newSize++] = index;
934
+ newWord[newSize++] = index2;
914
935
  }
915
936
  }
916
937
  }
@@ -992,13 +1013,13 @@ function requireSparseTypedFastBitSet() {
992
1013
  var newSize = 0;
993
1014
  var array = order.first.data;
994
1015
  for (var i = 0; i < order.first.arraySize; i++) {
995
- var index = array[i];
996
- if (order.second.has(index)) {
997
- if (newSize > 0 && index > newArray[0]) {
1016
+ var index2 = array[i];
1017
+ if (order.second.has(index2)) {
1018
+ if (newSize > 0 && index2 > newArray[0]) {
998
1019
  newArray[newSize++] = newArray[0];
999
- newArray[0] = index;
1020
+ newArray[0] = index2;
1000
1021
  } else {
1001
- newArray[newSize++] = index;
1022
+ newArray[newSize++] = index2;
1002
1023
  }
1003
1024
  }
1004
1025
  }
@@ -1076,9 +1097,9 @@ function requireSparseTypedFastBitSet() {
1076
1097
  } else {
1077
1098
  var otherArray = otherbitmap.data;
1078
1099
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1079
- var index = otherArray[i];
1080
- if (this.has(index)) {
1081
- this.remove(index);
1100
+ var index2 = otherArray[i];
1101
+ if (this.has(index2)) {
1102
+ this.remove(index2);
1082
1103
  }
1083
1104
  }
1084
1105
  return this;
@@ -1188,8 +1209,8 @@ function requireSparseTypedFastBitSet() {
1188
1209
  var answer = this.size();
1189
1210
  var otherArray = otherbitmap.data;
1190
1211
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1191
- var index = otherArray[i];
1192
- if (this.has(index)) {
1212
+ var index2 = otherArray[i];
1213
+ if (this.has(index2)) {
1193
1214
  answer--;
1194
1215
  }
1195
1216
  }
@@ -1236,11 +1257,11 @@ function requireSparseTypedFastBitSet() {
1236
1257
  this.resize(otherArray[0]);
1237
1258
  var words = this.words;
1238
1259
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1239
- var index = otherArray[i];
1240
- if ((words[index >>> 5] & 1 << index) !== 0) {
1241
- words[index >>> 5] &= ~(1 << index);
1260
+ var index2 = otherArray[i];
1261
+ if ((words[index2 >>> 5] & 1 << index2) !== 0) {
1262
+ words[index2 >>> 5] &= ~(1 << index2);
1242
1263
  } else {
1243
- words[index >>> 5] |= 1 << index;
1264
+ words[index2 >>> 5] |= 1 << index2;
1244
1265
  }
1245
1266
  }
1246
1267
  return this;
@@ -1253,11 +1274,11 @@ function requireSparseTypedFastBitSet() {
1253
1274
  words.set(otherbitmap.words);
1254
1275
  var array = this.data;
1255
1276
  for (var i = 0; i < this.arraySize; i++) {
1256
- var index = array[i];
1257
- if ((words[index >>> 5] & 1 << index) !== 0) {
1258
- words[index >>> 5] &= ~(1 << index);
1277
+ var index2 = array[i];
1278
+ if ((words[index2 >>> 5] & 1 << index2) !== 0) {
1279
+ words[index2 >>> 5] &= ~(1 << index2);
1259
1280
  } else {
1260
- words[index >>> 5] |= 1 << index;
1281
+ words[index2 >>> 5] |= 1 << index2;
1261
1282
  }
1262
1283
  }
1263
1284
  this.data = words;
@@ -1265,11 +1286,11 @@ function requireSparseTypedFastBitSet() {
1265
1286
  } else {
1266
1287
  var otherArray = otherbitmap.data;
1267
1288
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1268
- var index = otherArray[i];
1269
- if (this.has(index)) {
1270
- this.remove(index);
1289
+ var index2 = otherArray[i];
1290
+ if (this.has(index2)) {
1291
+ this.remove(index2);
1271
1292
  } else {
1272
- this.add(index);
1293
+ this.add(index2);
1273
1294
  }
1274
1295
  }
1275
1296
  }
@@ -1315,11 +1336,11 @@ function requireSparseTypedFastBitSet() {
1315
1336
  words.set(order.second.words);
1316
1337
  var array = order.first.data;
1317
1338
  for (var i = 0; i < order.first.arraySize; i++) {
1318
- var index = array[i];
1319
- if ((words[index >>> 5] & 1 << index) !== 0) {
1320
- words[index >>> 5] &= ~(1 << index);
1339
+ var index2 = array[i];
1340
+ if ((words[index2 >>> 5] & 1 << index2) !== 0) {
1341
+ words[index2 >>> 5] &= ~(1 << index2);
1321
1342
  } else {
1322
- words[index >>> 5] |= 1 << index;
1343
+ words[index2 >>> 5] |= 1 << index2;
1323
1344
  }
1324
1345
  }
1325
1346
  var answer = new SparseTypedFastBitSet2(void 0, words);
@@ -1332,12 +1353,12 @@ function requireSparseTypedFastBitSet() {
1332
1353
  var newSize = order.second.arraySize;
1333
1354
  var array = order.first.data;
1334
1355
  for (var i = 0; i < order.first.arraySize; i++) {
1335
- var index = array[i];
1336
- var offset = newArray.indexOf(index);
1356
+ var index2 = array[i];
1357
+ var offset = newArray.indexOf(index2);
1337
1358
  if (offset !== -1 && offset < newSize) {
1338
1359
  newArray[offset] = newArray[--newSize];
1339
1360
  } else {
1340
- newArray[newSize++] = index;
1361
+ newArray[newSize++] = index2;
1341
1362
  }
1342
1363
  }
1343
1364
  if (newSize > 1) {
@@ -1382,8 +1403,8 @@ function requireSparseTypedFastBitSet() {
1382
1403
  var array = order.first.data;
1383
1404
  var answer = order.second.size();
1384
1405
  for (var i = 0; i < order.first.arraySize; i++) {
1385
- var index = array[i];
1386
- if (order.second.has(index)) {
1406
+ var index2 = array[i];
1407
+ if (order.second.has(index2)) {
1387
1408
  answer--;
1388
1409
  } else {
1389
1410
  answer++;
@@ -1395,8 +1416,8 @@ function requireSparseTypedFastBitSet() {
1395
1416
  var answer = order.second.arraySize;
1396
1417
  var array = order.first.data;
1397
1418
  for (var i = 0; i < order.first.arraySize; i++) {
1398
- var index = array[i];
1399
- if (order.second.has(index)) {
1419
+ var index2 = array[i];
1420
+ if (order.second.has(index2)) {
1400
1421
  answer--;
1401
1422
  } else {
1402
1423
  answer++;
@@ -1444,8 +1465,8 @@ function requireSparseTypedFastBitSet() {
1444
1465
  } else {
1445
1466
  var otherArray = otherbitmap.data;
1446
1467
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1447
- var index = otherArray[i];
1448
- this.add(index);
1468
+ var index2 = otherArray[i];
1469
+ this.add(index2);
1449
1470
  }
1450
1471
  return this;
1451
1472
  }
@@ -1477,8 +1498,8 @@ function requireSparseTypedFastBitSet() {
1477
1498
  var answer = this.clone();
1478
1499
  var otherArray = otherbitmap.data;
1479
1500
  for (var i = 0; i < otherbitmap.arraySize; i++) {
1480
- var index = otherArray[i];
1481
- answer.add(index);
1501
+ var index2 = otherArray[i];
1502
+ answer.add(index2);
1482
1503
  }
1483
1504
  return answer;
1484
1505
  }
@@ -1619,20 +1640,20 @@ function requireTypedFastBitSet() {
1619
1640
  TypedFastBitSet2.fromWords = function(words) {
1620
1641
  return new TypedFastBitSet2(void 0, words);
1621
1642
  };
1622
- TypedFastBitSet2.prototype.add = function(index) {
1623
- this.resize(index);
1624
- this.words[index >>> 5] |= 1 << index;
1643
+ TypedFastBitSet2.prototype.add = function(index2) {
1644
+ this.resize(index2);
1645
+ this.words[index2 >>> 5] |= 1 << index2;
1625
1646
  };
1626
- TypedFastBitSet2.prototype.flip = function(index) {
1627
- this.resize(index);
1628
- this.words[index >>> 5] ^= 1 << index;
1647
+ TypedFastBitSet2.prototype.flip = function(index2) {
1648
+ this.resize(index2);
1649
+ this.words[index2 >>> 5] ^= 1 << index2;
1629
1650
  };
1630
1651
  TypedFastBitSet2.prototype.clear = function() {
1631
1652
  this.words = new Uint32Array(8);
1632
1653
  };
1633
- TypedFastBitSet2.prototype.remove = function(index) {
1634
- this.resize(index);
1635
- this.words[index >>> 5] &= ~(1 << index);
1654
+ TypedFastBitSet2.prototype.remove = function(index2) {
1655
+ this.resize(index2);
1656
+ this.words[index2 >>> 5] &= ~(1 << index2);
1636
1657
  };
1637
1658
  TypedFastBitSet2.prototype.addRange = function(start, end) {
1638
1659
  if (start >= end) {
@@ -1678,8 +1699,8 @@ function requireTypedFastBitSet() {
1678
1699
  }
1679
1700
  return true;
1680
1701
  };
1681
- TypedFastBitSet2.prototype.has = function(index) {
1682
- return (this.words[index >>> 5] & 1 << index) !== 0;
1702
+ TypedFastBitSet2.prototype.has = function(index2) {
1703
+ return (this.words[index2 >>> 5] & 1 << index2) !== 0;
1683
1704
  };
1684
1705
  TypedFastBitSet2.prototype.hasAnyInRange = function(start, end) {
1685
1706
  if (start >= end)
@@ -1693,18 +1714,18 @@ function requireTypedFastBitSet() {
1693
1714
  return (words[firstword] & (-1 << start & -1 >>> -end)) !== 0;
1694
1715
  if ((words[firstword] & -1 << start) !== 0)
1695
1716
  return true;
1696
- for (var index = firstword + 1; index < endword - 1; index++)
1697
- if (words[index] !== 0)
1717
+ for (var index2 = firstword + 1; index2 < endword - 1; index2++)
1718
+ if (words[index2] !== 0)
1698
1719
  return true;
1699
1720
  return (words[endword] & -1 >>> -end) !== 0;
1700
1721
  };
1701
- TypedFastBitSet2.prototype.checkedAdd = function(index) {
1722
+ TypedFastBitSet2.prototype.checkedAdd = function(index2) {
1702
1723
  var words = this.words;
1703
- this.resize(index);
1704
- var word = words[index >>> 5];
1705
- var newword = word | 1 << index;
1706
- words[index >>> 5] = newword;
1707
- return (newword ^ word) >>> index;
1724
+ this.resize(index2);
1725
+ var word = words[index2 >>> 5];
1726
+ var newword = word | 1 << index2;
1727
+ words[index2 >>> 5] = newword;
1728
+ return (newword ^ word) >>> index2;
1708
1729
  };
1709
1730
  TypedFastBitSet2.prototype.trim = function() {
1710
1731
  var words = this.words;
@@ -1714,11 +1735,11 @@ function requireTypedFastBitSet() {
1714
1735
  }
1715
1736
  this.words = words.slice(0, nl);
1716
1737
  };
1717
- TypedFastBitSet2.prototype.resize = function(index) {
1738
+ TypedFastBitSet2.prototype.resize = function(index2) {
1718
1739
  var words = this.words;
1719
- if (words.length << 5 > index)
1740
+ if (words.length << 5 > index2)
1720
1741
  return;
1721
- var count = index + 32 >>> 5;
1742
+ var count = index2 + 32 >>> 5;
1722
1743
  var newwords = new Uint32Array(count << 1);
1723
1744
  newwords.set(words);
1724
1745
  this.words = newwords;
@@ -2133,9 +2154,9 @@ class GraphBitSet {
2133
2154
  * Add a single element to the set.
2134
2155
  * @param index - The element index to add
2135
2156
  */
2136
- add(index) {
2137
- if (!this.bitset.has(index)) {
2138
- this.bitset.add(index);
2157
+ add(index2) {
2158
+ if (!this.bitset.has(index2)) {
2159
+ this.bitset.add(index2);
2139
2160
  this._cardinality++;
2140
2161
  }
2141
2162
  }
@@ -2143,9 +2164,9 @@ class GraphBitSet {
2143
2164
  * Remove a single element from the set.
2144
2165
  * @param index - The element index to remove
2145
2166
  */
2146
- remove(index) {
2147
- if (this.bitset.has(index)) {
2148
- this.bitset.remove(index);
2167
+ remove(index2) {
2168
+ if (this.bitset.has(index2)) {
2169
+ this.bitset.remove(index2);
2149
2170
  this._cardinality--;
2150
2171
  }
2151
2172
  }
@@ -2154,8 +2175,8 @@ class GraphBitSet {
2154
2175
  * @param index - The element index to check
2155
2176
  * @returns True if the element exists, false otherwise
2156
2177
  */
2157
- has(index) {
2158
- return this.bitset.has(index);
2178
+ has(index2) {
2179
+ return this.bitset.has(index2);
2159
2180
  }
2160
2181
  /**
2161
2182
  * Clear all elements
@@ -2261,12 +2282,12 @@ class VisitedBitArray {
2261
2282
  * Set bit at the specified index.
2262
2283
  * @param index - The bit index to set
2263
2284
  */
2264
- set(index) {
2265
- if (index < 0 || index >= this._size) {
2266
- throw new Error(`Index ${String(index)} out of bounds [0, ${String(this._size)})`);
2285
+ set(index2) {
2286
+ if (index2 < 0 || index2 >= this._size) {
2287
+ throw new Error(`Index ${String(index2)} out of bounds [0, ${String(this._size)})`);
2267
2288
  }
2268
- const wordIndex = index >>> 5;
2269
- const bitIndex = index & 31;
2289
+ const wordIndex = index2 >>> 5;
2290
+ const bitIndex = index2 & 31;
2270
2291
  const word = this.words[wordIndex];
2271
2292
  if (word !== void 0) {
2272
2293
  this.words[wordIndex] = word | 1 << bitIndex;
@@ -2277,12 +2298,12 @@ class VisitedBitArray {
2277
2298
  * @param index - The bit index to get
2278
2299
  * @returns True if the bit is set, false otherwise
2279
2300
  */
2280
- get(index) {
2281
- if (index < 0 || index >= this._size) {
2301
+ get(index2) {
2302
+ if (index2 < 0 || index2 >= this._size) {
2282
2303
  return false;
2283
2304
  }
2284
- const wordIndex = index >>> 5;
2285
- const bitIndex = index & 31;
2305
+ const wordIndex = index2 >>> 5;
2306
+ const bitIndex = index2 & 31;
2286
2307
  const word = this.words[wordIndex];
2287
2308
  return word !== void 0 && (word & 1 << bitIndex) !== 0;
2288
2309
  }
@@ -2296,12 +2317,12 @@ class VisitedBitArray {
2296
2317
  * Toggle bit at the specified index.
2297
2318
  * @param index - The bit index to toggle
2298
2319
  */
2299
- toggle(index) {
2300
- if (index < 0 || index >= this._size) {
2301
- throw new Error(`Index ${String(index)} out of bounds [0, ${String(this._size)})`);
2320
+ toggle(index2) {
2321
+ if (index2 < 0 || index2 >= this._size) {
2322
+ throw new Error(`Index ${String(index2)} out of bounds [0, ${String(this._size)})`);
2302
2323
  }
2303
- const wordIndex = index >>> 5;
2304
- const bitIndex = index & 31;
2324
+ const wordIndex = index2 >>> 5;
2325
+ const bitIndex = index2 & 31;
2305
2326
  const word = this.words[wordIndex];
2306
2327
  if (word !== void 0) {
2307
2328
  this.words[wordIndex] = word ^ 1 << bitIndex;
@@ -2357,8 +2378,8 @@ class VisitedBitArray {
2357
2378
  * @param indices - Array of bit indices to set
2358
2379
  */
2359
2380
  setMultiple(indices) {
2360
- for (const index of indices) {
2361
- this.set(index);
2381
+ for (const index2 of indices) {
2382
+ this.set(index2);
2362
2383
  }
2363
2384
  }
2364
2385
  /**
@@ -2374,9 +2395,9 @@ class VisitedBitArray {
2374
2395
  }
2375
2396
  for (let bitIndex = 0; bitIndex < 32; bitIndex++) {
2376
2397
  if (word & 1 << bitIndex) {
2377
- const index = (wordIndex << 5) + bitIndex;
2378
- if (index < this._size) {
2379
- indices.push(index);
2398
+ const index2 = (wordIndex << 5) + bitIndex;
2399
+ if (index2 < this._size) {
2400
+ indices.push(index2);
2380
2401
  }
2381
2402
  }
2382
2403
  }
@@ -2399,19 +2420,19 @@ const _CompactDistanceArray = class _CompactDistanceArray {
2399
2420
  * @param index - The node index to set the distance for
2400
2421
  * @param distance - The distance value to set
2401
2422
  */
2402
- set(index, distance) {
2423
+ set(index2, distance) {
2403
2424
  if (distance >= _CompactDistanceArray.INFINITY) {
2404
2425
  throw new Error(`Distance exceeds maximum value (${String(_CompactDistanceArray.INFINITY - 1)})`);
2405
2426
  }
2406
- this.data[index] = distance;
2427
+ this.data[index2] = distance;
2407
2428
  }
2408
2429
  /**
2409
2430
  * Get distance at the specified index.
2410
2431
  * @param index - The node index to get the distance for
2411
2432
  * @returns The distance value, or INFINITY if not set
2412
2433
  */
2413
- get(index) {
2414
- const value = this.data[index];
2434
+ get(index2) {
2435
+ const value = this.data[index2];
2415
2436
  return value ?? _CompactDistanceArray.INFINITY;
2416
2437
  }
2417
2438
  /**
@@ -2419,8 +2440,8 @@ const _CompactDistanceArray = class _CompactDistanceArray {
2419
2440
  * @param index - The node index to check
2420
2441
  * @returns True if the node has been visited, false otherwise
2421
2442
  */
2422
- isVisited(index) {
2423
- return this.data[index] !== _CompactDistanceArray.INFINITY;
2443
+ isVisited(index2) {
2444
+ return this.data[index2] !== _CompactDistanceArray.INFINITY;
2424
2445
  }
2425
2446
  /**
2426
2447
  * Reset all distances to unvisited state.
@@ -2659,9 +2680,9 @@ class CSRGraph {
2659
2680
  const nodeCount = nodes.length;
2660
2681
  const nodeIdToIndex = /* @__PURE__ */ new Map();
2661
2682
  const indexToNodeId = [];
2662
- nodes.forEach((nodeId, index) => {
2663
- nodeIdToIndex.set(nodeId, index);
2664
- indexToNodeId[index] = nodeId;
2683
+ nodes.forEach((nodeId, index2) => {
2684
+ nodeIdToIndex.set(nodeId, index2);
2685
+ indexToNodeId[index2] = nodeId;
2665
2686
  });
2666
2687
  let edgeCount = 0;
2667
2688
  for (const neighbors of adjacencyList.values()) {
@@ -2679,11 +2700,11 @@ class CSRGraph {
2679
2700
  }
2680
2701
  const neighbors = adjacencyList.get(nodeId) ?? [];
2681
2702
  const sortedNeighbors = neighbors.map((n) => {
2682
- const index = nodeIdToIndex.get(n);
2683
- if (index === void 0) {
2703
+ const index2 = nodeIdToIndex.get(n);
2704
+ if (index2 === void 0) {
2684
2705
  throw new Error(`Node ${String(n)} not found in nodeIdToIndex map`);
2685
2706
  }
2686
- return { id: n, index };
2707
+ return { id: n, index: index2 };
2687
2708
  }).sort((a, b) => a.index - b.index);
2688
2709
  for (const neighbor of sortedNeighbors) {
2689
2710
  columnIndices[currentEdge] = neighbor.index;
@@ -2904,21 +2925,21 @@ class CSRGraph {
2904
2925
  * @returns The internal index for the node
2905
2926
  */
2906
2927
  nodeToIndex(nodeId) {
2907
- const index = this.data.nodeIdToIndex.get(nodeId);
2908
- if (index === void 0) {
2928
+ const index2 = this.data.nodeIdToIndex.get(nodeId);
2929
+ if (index2 === void 0) {
2909
2930
  throw new Error(`Node ${String(nodeId)} not found in graph`);
2910
2931
  }
2911
- return index;
2932
+ return index2;
2912
2933
  }
2913
2934
  /**
2914
2935
  * Convert internal index to node ID.
2915
2936
  * @param index - The internal index to convert
2916
2937
  * @returns The node ID for the given index
2917
2938
  */
2918
- indexToNodeId(index) {
2919
- const nodeId = this.data.indexToNodeId[index];
2939
+ indexToNodeId(index2) {
2940
+ const nodeId = this.data.indexToNodeId[index2];
2920
2941
  if (nodeId === void 0) {
2921
- throw new Error(`Index ${String(index)} out of bounds`);
2942
+ throw new Error(`Index ${String(index2)} out of bounds`);
2922
2943
  }
2923
2944
  return nodeId;
2924
2945
  }
@@ -3198,7 +3219,7 @@ function getCSRGraph(graph) {
3198
3219
  }
3199
3220
  return csrGraph;
3200
3221
  }
3201
- function breadthFirstSearch(graph, startNode, options = {}) {
3222
+ function breadthFirstSearch$1(graph, startNode, options = {}) {
3202
3223
  if (!graph.hasNode(startNode)) {
3203
3224
  throw new Error(`Start node ${String(startNode)} not found in graph`);
3204
3225
  }
@@ -3799,20 +3820,20 @@ class PriorityQueue {
3799
3820
  * @returns True if the item was found and updated, false otherwise
3800
3821
  */
3801
3822
  updatePriority(item, newPriority) {
3802
- const index = this.heap.findIndex((element2) => element2.item === item);
3803
- if (index === -1) {
3823
+ const index2 = this.heap.findIndex((element2) => element2.item === item);
3824
+ if (index2 === -1) {
3804
3825
  return false;
3805
3826
  }
3806
- const element = this.heap[index];
3827
+ const element = this.heap[index2];
3807
3828
  if (!element) {
3808
3829
  return false;
3809
3830
  }
3810
3831
  const oldPriority = element.priority;
3811
3832
  element.priority = newPriority;
3812
3833
  if (this.compareFn(newPriority, oldPriority) < 0) {
3813
- this.heapifyUp(index);
3834
+ this.heapifyUp(index2);
3814
3835
  } else if (this.compareFn(newPriority, oldPriority) > 0) {
3815
- this.heapifyDown(index);
3836
+ this.heapifyDown(index2);
3816
3837
  }
3817
3838
  return true;
3818
3839
  }
@@ -3833,15 +3854,15 @@ class PriorityQueue {
3833
3854
  * Move element up the heap until heap property is satisfied
3834
3855
  * @param index - The index of the element to heapify up
3835
3856
  */
3836
- heapifyUp(index) {
3837
- if (index === 0) {
3857
+ heapifyUp(index2) {
3858
+ if (index2 === 0) {
3838
3859
  return;
3839
3860
  }
3840
- const parentIndex = Math.floor((index - 1) / 2);
3841
- const current = this.heap[index];
3861
+ const parentIndex = Math.floor((index2 - 1) / 2);
3862
+ const current = this.heap[index2];
3842
3863
  const parent = this.heap[parentIndex];
3843
3864
  if (current && parent && this.compareFn(current.priority, parent.priority) < 0) {
3844
- this.swap(index, parentIndex);
3865
+ this.swap(index2, parentIndex);
3845
3866
  this.heapifyUp(parentIndex);
3846
3867
  }
3847
3868
  }
@@ -3849,10 +3870,10 @@ class PriorityQueue {
3849
3870
  * Move element down the heap until heap property is satisfied
3850
3871
  * @param index - The index of the element to heapify down
3851
3872
  */
3852
- heapifyDown(index) {
3853
- const leftChildIndex = 2 * index + 1;
3854
- const rightChildIndex = 2 * index + 2;
3855
- let targetIndex = index;
3873
+ heapifyDown(index2) {
3874
+ const leftChildIndex = 2 * index2 + 1;
3875
+ const rightChildIndex = 2 * index2 + 2;
3876
+ let targetIndex = index2;
3856
3877
  const leftChild = this.heap[leftChildIndex];
3857
3878
  const target = this.heap[targetIndex];
3858
3879
  if (leftChildIndex < this.heap.length && leftChild && target && this.compareFn(leftChild.priority, target.priority) < 0) {
@@ -3863,8 +3884,8 @@ class PriorityQueue {
3863
3884
  if (rightChildIndex < this.heap.length && rightChild && newTarget && this.compareFn(rightChild.priority, newTarget.priority) < 0) {
3864
3885
  targetIndex = rightChildIndex;
3865
3886
  }
3866
- if (targetIndex !== index) {
3867
- this.swap(index, targetIndex);
3887
+ if (targetIndex !== index2) {
3888
+ this.swap(index2, targetIndex);
3868
3889
  this.heapifyDown(targetIndex);
3869
3890
  }
3870
3891
  }
@@ -4041,7 +4062,7 @@ class BidirectionalDijkstra {
4041
4062
  this.shortestDistance = Infinity;
4042
4063
  }
4043
4064
  }
4044
- function dijkstra(graph, source, options = {}) {
4065
+ function dijkstra$1(graph, source, options = {}) {
4045
4066
  if (!graph.hasNode(source)) {
4046
4067
  throw new Error(`Source node ${String(source)} not found in graph`);
4047
4068
  }
@@ -4130,7 +4151,7 @@ function dijkstraPath(graph, source, target, options = {}) {
4130
4151
  const biDijkstra = new BidirectionalDijkstra(graph);
4131
4152
  return biDijkstra.findShortestPath(source, target);
4132
4153
  }
4133
- const results = dijkstra(graph, source, { target });
4154
+ const results = dijkstra$1(graph, source, { target });
4134
4155
  return results.get(target) ?? null;
4135
4156
  }
4136
4157
  function singleSourceShortestPath(graph, source, cutoff) {
@@ -4619,6 +4640,13 @@ function bfsWeightedDistancesCSR(graph, source, cutoff) {
4619
4640
  }
4620
4641
  return distances;
4621
4642
  }
4643
+ function rejectIndexOptions(options, fn) {
4644
+ if (options.sources !== void 0 || options.k !== void 0) {
4645
+ throw new Error(
4646
+ `${fn}: 'sources' and 'k' are node INDICES and are meaningful only against a GraphSnapshot; call accelerated(accelerator).betweennessCentrality(snapshot, options) instead`
4647
+ );
4648
+ }
4649
+ }
4622
4650
  function brandesSingleSource(graph, source, optimized) {
4623
4651
  const result = bfsWithPathCounting(graph, source, optimized !== void 0 ? { optimized } : {});
4624
4652
  return {
@@ -4708,6 +4736,7 @@ function normalizeCentrality(centrality, nodeCount, isDirected) {
4708
4736
  }
4709
4737
  }
4710
4738
  function betweennessCentrality(graph, options = {}) {
4739
+ rejectIndexOptions(options, "betweennessCentrality");
4711
4740
  const nodes = Array.from(graph.nodes()).map((node) => node.id);
4712
4741
  const centrality = {};
4713
4742
  for (const nodeId of nodes) {
@@ -4732,6 +4761,7 @@ function betweennessCentrality(graph, options = {}) {
4732
4761
  return centrality;
4733
4762
  }
4734
4763
  function nodeBetweennessCentrality(graph, targetNode, options = {}) {
4764
+ rejectIndexOptions(options, "nodeBetweennessCentrality");
4735
4765
  if (!graph.hasNode(targetNode)) {
4736
4766
  throw new Error(`Node ${String(targetNode)} not found in graph`);
4737
4767
  }
@@ -4739,6 +4769,7 @@ function nodeBetweennessCentrality(graph, targetNode, options = {}) {
4739
4769
  return allCentralities[String(targetNode)] ?? 0;
4740
4770
  }
4741
4771
  function edgeBetweennessCentrality(graph, options = {}) {
4772
+ rejectIndexOptions(options, "edgeBetweennessCentrality");
4742
4773
  const nodes = Array.from(graph.nodes()).map((node) => node.id);
4743
4774
  const edgeCentrality = /* @__PURE__ */ new Map();
4744
4775
  for (const edge of Array.from(graph.edges())) {
@@ -5733,7 +5764,7 @@ class SimpleDeltaPageRank {
5733
5764
  }
5734
5765
  }
5735
5766
  }
5736
- function pageRank(graph, options = {}) {
5767
+ function pageRank$1(graph, options = {}) {
5737
5768
  const {
5738
5769
  dampingFactor = 0.85,
5739
5770
  maxIterations = 100,
@@ -5884,7 +5915,7 @@ function pageRank(graph, options = {}) {
5884
5915
  }
5885
5916
  function personalizedPageRank(graph, personalNodes, options = {}) {
5886
5917
  if (personalNodes.length === 0) {
5887
- return pageRank(graph, options);
5918
+ return pageRank$1(graph, options);
5888
5919
  }
5889
5920
  const nodes = Array.from(graph.nodes()).map((node) => node.id);
5890
5921
  const personalization = /* @__PURE__ */ new Map();
@@ -5898,17 +5929,17 @@ function personalizedPageRank(graph, personalNodes, options = {}) {
5898
5929
  }
5899
5930
  personalization.set(personalNode, personalValue);
5900
5931
  }
5901
- return pageRank(graph, {
5932
+ return pageRank$1(graph, {
5902
5933
  ...options,
5903
5934
  personalization
5904
5935
  });
5905
5936
  }
5906
5937
  function pageRankCentrality(graph, options = {}) {
5907
- const result = pageRank(graph, options);
5938
+ const result = pageRank$1(graph, options);
5908
5939
  return result.ranks;
5909
5940
  }
5910
5941
  function topPageRankNodes(graph, k, options = {}) {
5911
- const result = pageRank(graph, options);
5942
+ const result = pageRank$1(graph, options);
5912
5943
  const nodeRanks = [];
5913
5944
  for (const [nodeStr, rank] of Object.entries(result.ranks)) {
5914
5945
  nodeRanks.push({ node: nodeStr, rank });
@@ -6075,7 +6106,7 @@ class UnionFind {
6075
6106
  return this.parent.size;
6076
6107
  }
6077
6108
  }
6078
- function connectedComponents(graph) {
6109
+ function connectedComponents$1(graph) {
6079
6110
  if (graph.isDirected) {
6080
6111
  throw new Error(
6081
6112
  "Connected components algorithm requires an undirected graph. Use stronglyConnectedComponents for directed graphs."
@@ -6116,13 +6147,13 @@ function dfsComponent(graph, nodeId, visited, component) {
6116
6147
  }
6117
6148
  }
6118
6149
  function numberOfConnectedComponents(graph) {
6119
- return connectedComponents(graph).length;
6150
+ return connectedComponents$1(graph).length;
6120
6151
  }
6121
6152
  function isConnected(graph) {
6122
6153
  return numberOfConnectedComponents(graph) <= 1;
6123
6154
  }
6124
6155
  function largestConnectedComponent(graph) {
6125
- const components = connectedComponents(graph);
6156
+ const components = connectedComponents$1(graph);
6126
6157
  if (components.length === 0) {
6127
6158
  return [];
6128
6159
  }
@@ -6150,11 +6181,11 @@ function stronglyConnectedComponents(graph) {
6150
6181
  const lowLinks = /* @__PURE__ */ new Map();
6151
6182
  const onStack = /* @__PURE__ */ new Set();
6152
6183
  const stack = [];
6153
- let index = 0;
6184
+ let index2 = 0;
6154
6185
  function tarjanSCC(nodeId) {
6155
- indices.set(nodeId, index);
6156
- lowLinks.set(nodeId, index);
6157
- index++;
6186
+ indices.set(nodeId, index2);
6187
+ lowLinks.set(nodeId, index2);
6188
+ index2++;
6158
6189
  stack.push(nodeId);
6159
6190
  onStack.add(nodeId);
6160
6191
  for (const neighbor of Array.from(graph.neighbors(nodeId))) {
@@ -6200,7 +6231,7 @@ function isStronglyConnected(graph) {
6200
6231
  const components = stronglyConnectedComponents(graph);
6201
6232
  return components.length <= 1;
6202
6233
  }
6203
- function weaklyConnectedComponents(graph) {
6234
+ function weaklyConnectedComponents$1(graph) {
6204
6235
  if (!graph.isDirected) {
6205
6236
  throw new Error(
6206
6237
  "Weakly connected components are for directed graphs. Use connectedComponents for undirected graphs."
@@ -6220,7 +6251,7 @@ function isWeaklyConnected(graph) {
6220
6251
  if (!graph.isDirected) {
6221
6252
  throw new Error("Weak connectivity check requires a directed graph");
6222
6253
  }
6223
- return weaklyConnectedComponents(graph).length <= 1;
6254
+ return weaklyConnectedComponents$1(graph).length <= 1;
6224
6255
  }
6225
6256
  function condensationGraph(graph) {
6226
6257
  if (!graph.isDirected) {
@@ -6256,7 +6287,7 @@ function condensationGraph(graph) {
6256
6287
  components
6257
6288
  };
6258
6289
  }
6259
- function kruskalMST(graph) {
6290
+ function kruskalMST$1(graph) {
6260
6291
  if (graph.isDirected) {
6261
6292
  throw new Error("Kruskal's algorithm requires an undirected graph");
6262
6293
  }
@@ -6293,7 +6324,7 @@ function kruskalMST(graph) {
6293
6324
  };
6294
6325
  }
6295
6326
  function minimumSpanningTree(graph) {
6296
- return kruskalMST(graph);
6327
+ return kruskalMST$1(graph);
6297
6328
  }
6298
6329
  function primMST(graph, startNode) {
6299
6330
  if (graph.isDirected) {
@@ -6564,11 +6595,11 @@ function getNodeDegree$1(graph, nodeId) {
6564
6595
  return degree;
6565
6596
  }
6566
6597
  function getConnectedComponentsResult(graph) {
6567
- const components = connectedComponents(graph);
6598
+ const components = connectedComponents$1(graph);
6568
6599
  const componentMap = /* @__PURE__ */ new Map();
6569
- components.forEach((component, index) => {
6600
+ components.forEach((component, index2) => {
6570
6601
  component.forEach((nodeId) => {
6571
- componentMap.set(nodeId, index);
6602
+ componentMap.set(nodeId, index2);
6572
6603
  });
6573
6604
  });
6574
6605
  return { components, componentMap };
@@ -6703,8 +6734,8 @@ function labelPropagationImpl(graph, options = {}) {
6703
6734
  if (labelCounts.get(currentLabel) === maxCount) {
6704
6735
  candidateLabels.push(currentLabel);
6705
6736
  }
6706
- const index = Math.floor(random() * candidateLabels.length);
6707
- const selectedLabel = candidateLabels[index];
6737
+ const index2 = Math.floor(random() * candidateLabels.length);
6738
+ const selectedLabel = candidateLabels[index2];
6708
6739
  if (selectedLabel !== void 0) {
6709
6740
  newLabel = selectedLabel;
6710
6741
  }
@@ -6860,8 +6891,8 @@ function labelPropagationSemiSupervisedImpl(graph, seedLabels, options = {}) {
6860
6891
  }
6861
6892
  let newLabel = currentLabel;
6862
6893
  if (candidateLabels.length > 0) {
6863
- const index = Math.floor(random() * candidateLabels.length);
6864
- const selectedLabel = candidateLabels[index];
6894
+ const index2 = Math.floor(random() * candidateLabels.length);
6895
+ const selectedLabel = candidateLabels[index2];
6865
6896
  if (selectedLabel !== void 0) {
6866
6897
  newLabel = selectedLabel;
6867
6898
  }
@@ -7760,24 +7791,24 @@ class MinPriorityQueue {
7760
7791
  this.heap[j] = temp;
7761
7792
  }
7762
7793
  }
7763
- heapifyUp(index) {
7764
- while (index > 0) {
7765
- const parentIndex = this.parent(index);
7766
- const current = this.heap[index];
7794
+ heapifyUp(index2) {
7795
+ while (index2 > 0) {
7796
+ const parentIndex = this.parent(index2);
7797
+ const current = this.heap[index2];
7767
7798
  const parent = this.heap[parentIndex];
7768
7799
  if (current !== void 0 && parent !== void 0 && this.compare(current, parent) < 0) {
7769
- this.swap(index, parentIndex);
7770
- index = parentIndex;
7800
+ this.swap(index2, parentIndex);
7801
+ index2 = parentIndex;
7771
7802
  } else {
7772
7803
  break;
7773
7804
  }
7774
7805
  }
7775
7806
  }
7776
- heapifyDown(index) {
7777
- while (index < this.heap.length) {
7778
- let minIndex = index;
7779
- const left = this.leftChild(index);
7780
- const right = this.rightChild(index);
7807
+ heapifyDown(index2) {
7808
+ while (index2 < this.heap.length) {
7809
+ let minIndex = index2;
7810
+ const left = this.leftChild(index2);
7811
+ const right = this.rightChild(index2);
7781
7812
  const leftItem = this.heap[left];
7782
7813
  const minItem = this.heap[minIndex];
7783
7814
  if (left < this.heap.length && leftItem !== void 0 && minItem !== void 0 && this.compare(leftItem, minItem) < 0) {
@@ -7788,9 +7819,9 @@ class MinPriorityQueue {
7788
7819
  if (right < this.heap.length && rightItem !== void 0 && newMinItem !== void 0 && this.compare(rightItem, newMinItem) < 0) {
7789
7820
  minIndex = right;
7790
7821
  }
7791
- if (minIndex !== index) {
7792
- this.swap(index, minIndex);
7793
- index = minIndex;
7822
+ if (minIndex !== index2) {
7823
+ this.swap(index2, minIndex);
7824
+ index2 = minIndex;
7794
7825
  } else {
7795
7826
  break;
7796
7827
  }
@@ -8451,9 +8482,9 @@ function contractNodes(graph, nodes, s, t) {
8451
8482
  }
8452
8483
  graph.delete(t);
8453
8484
  sNeighbors.delete(t);
8454
- const index = nodes.indexOf(t);
8455
- if (index > -1) {
8456
- nodes.splice(index, 1);
8485
+ const index2 = nodes.indexOf(t);
8486
+ if (index2 > -1) {
8487
+ nodes.splice(index2, 1);
8457
8488
  }
8458
8489
  }
8459
8490
  function makeUndirected(graph) {
@@ -9021,7 +9052,7 @@ function buildTransitionMatrix(graph, nodeIds, selfLoops) {
9021
9052
  const n = nodeIds.length;
9022
9053
  const matrix = Array.from({ length: n }, () => Array(n).fill(0));
9023
9054
  const nodeToIndex = /* @__PURE__ */ new Map();
9024
- nodeIds.forEach((id, index) => nodeToIndex.set(id, index));
9055
+ nodeIds.forEach((id, index2) => nodeToIndex.set(id, index2));
9025
9056
  for (let i = 0; i < n; i++) {
9026
9057
  const nodeId = nodeIds[i];
9027
9058
  if (nodeId === void 0) {
@@ -9273,9 +9304,9 @@ function calculateMCLModularity(graph, communities) {
9273
9304
  }
9274
9305
  let modularity = 0;
9275
9306
  const communityMap = /* @__PURE__ */ new Map();
9276
- communities.forEach((community, index) => {
9307
+ communities.forEach((community, index2) => {
9277
9308
  community.forEach((nodeId) => {
9278
- communityMap.set(nodeId, index);
9309
+ communityMap.set(nodeId, index2);
9279
9310
  });
9280
9311
  });
9281
9312
  for (const edge of graph.edges()) {
@@ -9302,7 +9333,7 @@ function spectralClustering(graph, options) {
9302
9333
  if (k >= n) {
9303
9334
  const communities2 = nodeIds.map((id) => [id]);
9304
9335
  const clusterAssignments2 = /* @__PURE__ */ new Map();
9305
- nodeIds.forEach((id, index) => clusterAssignments2.set(id, index));
9336
+ nodeIds.forEach((id, index2) => clusterAssignments2.set(id, index2));
9306
9337
  return { communities: communities2, clusterAssignments: clusterAssignments2 };
9307
9338
  }
9308
9339
  const adjacencyMatrix = buildAdjacencyMatrix(graph, nodeIds);
@@ -9357,7 +9388,7 @@ function buildAdjacencyMatrix(graph, nodeIds) {
9357
9388
  const n = nodeIds.length;
9358
9389
  const matrix = Array.from({ length: n }, () => Array(n).fill(0));
9359
9390
  const nodeToIndex = /* @__PURE__ */ new Map();
9360
- nodeIds.forEach((id, index) => nodeToIndex.set(id, index));
9391
+ nodeIds.forEach((id, index2) => nodeToIndex.set(id, index2));
9361
9392
  for (let i = 0; i < n; i++) {
9362
9393
  const nodeId = nodeIds[i];
9363
9394
  if (!nodeId) {
@@ -10261,7 +10292,7 @@ function compareAdamicAdarWithCommonNeighbors(graph, testEdges, nonEdges, option
10261
10292
  commonNeighbors: commonNeighborsResults
10262
10293
  };
10263
10294
  }
10264
- function commonNeighborsScore(graph, source, target, options = {}) {
10295
+ function commonNeighborsScore$1(graph, source, target, options = {}) {
10265
10296
  if (!graph.hasNode(source) || !graph.hasNode(target)) {
10266
10297
  return 0;
10267
10298
  }
@@ -10283,7 +10314,7 @@ function commonNeighborsPrediction(graph, options = {}) {
10283
10314
  if (!includeExisting && graph.hasEdge(source, target)) {
10284
10315
  continue;
10285
10316
  }
10286
- const score = commonNeighborsScore(graph, source, target, { directed });
10317
+ const score = commonNeighborsScore$1(graph, source, target, { directed });
10287
10318
  if (score > 0) {
10288
10319
  scores.push({ source, target, score });
10289
10320
  if (!directed && source !== target) {
@@ -10302,7 +10333,7 @@ function commonNeighborsForPairs(graph, pairs, options = {}) {
10302
10333
  return pairs.map(([source, target]) => ({
10303
10334
  source,
10304
10335
  target,
10305
- score: commonNeighborsScore(graph, source, target, options)
10336
+ score: commonNeighborsScore$1(graph, source, target, options)
10306
10337
  }));
10307
10338
  }
10308
10339
  function getTopCandidatesForNode(graph, node, options = {}) {
@@ -10319,7 +10350,7 @@ function getTopCandidatesForNode(graph, node, options = {}) {
10319
10350
  if (!includeExisting && graph.hasEdge(node, target)) {
10320
10351
  continue;
10321
10352
  }
10322
- const score = commonNeighborsScore(graph, node, target, { directed });
10353
+ const score = commonNeighborsScore$1(graph, node, target, { directed });
10323
10354
  if (score > 0) {
10324
10355
  scores.push({ source: node, target, score });
10325
10356
  }
@@ -11084,7 +11115,7 @@ function spectralBisection(graph, cluster, _numEigenvectors, tolerance, maxItera
11084
11115
  if (!eigenvector) {
11085
11116
  return null;
11086
11117
  }
11087
- const sortedIndices = eigenvector.map((value, index) => ({ value, index })).sort((a, b) => a.value - b.value);
11118
+ const sortedIndices = eigenvector.map((value, index2) => ({ value, index: index2 })).sort((a, b) => a.value - b.value);
11088
11119
  let bestSplitIndex = Math.floor(n / 2);
11089
11120
  let bestModularity = -Infinity;
11090
11121
  for (let splitIndex = Math.floor(n * 0.2); splitIndex <= Math.floor(n * 0.8); splitIndex++) {
@@ -11301,6 +11332,485 @@ function calculateModularity(graph, assignment) {
11301
11332
  }
11302
11333
  return modularity;
11303
11334
  }
11335
+ function breadthFirstSearch(g, start, options = {}) {
11336
+ const { nodeCount, rowPtr, colIdx } = g;
11337
+ const parent = new Uint32Array(nodeCount).fill(INVALID_INDEX);
11338
+ const depth = new Uint32Array(nodeCount).fill(INVALID_INDEX);
11339
+ const order = new Uint32Array(nodeCount);
11340
+ const maxDepth = options.maxDepth ?? INVALID_INDEX;
11341
+ let head = 0;
11342
+ let tail = 0;
11343
+ order[tail++] = start;
11344
+ depth[start] = 0;
11345
+ while (head < tail) {
11346
+ const u = order[head++];
11347
+ const d = depth[u];
11348
+ if (d >= maxDepth) {
11349
+ continue;
11350
+ }
11351
+ const end = rowPtr[u + 1];
11352
+ for (let a = rowPtr[u]; a < end; a++) {
11353
+ const v = colIdx[a];
11354
+ if (depth[v] === INVALID_INDEX) {
11355
+ depth[v] = d + 1;
11356
+ parent[v] = u;
11357
+ order[tail++] = v;
11358
+ }
11359
+ }
11360
+ }
11361
+ return { order: order.subarray(0, tail), parent, depth, visitedCount: tail };
11362
+ }
11363
+ function commonNeighborsScore(s, u, v, o = {}) {
11364
+ const fwd = s;
11365
+ const bwd = o.directed === true ? s.reverse() : s;
11366
+ let i = fwd.rowPtr[u];
11367
+ const iEnd = fwd.rowPtr[u + 1];
11368
+ let j = bwd.rowPtr[v];
11369
+ const jEnd = bwd.rowPtr[v + 1];
11370
+ let count = 0;
11371
+ while (i < iEnd && j < jEnd) {
11372
+ const a = fwd.colIdx[i];
11373
+ const b = bwd.colIdx[j];
11374
+ if (a === b) {
11375
+ count++;
11376
+ i++;
11377
+ j++;
11378
+ while (i < iEnd && fwd.colIdx[i] === a) {
11379
+ i++;
11380
+ }
11381
+ while (j < jEnd && bwd.colIdx[j] === b) {
11382
+ j++;
11383
+ }
11384
+ } else if (a < b) {
11385
+ i++;
11386
+ } else {
11387
+ j++;
11388
+ }
11389
+ }
11390
+ return count;
11391
+ }
11392
+ class IntUnionFind {
11393
+ /**
11394
+ * Create a union-find whose every element is a singleton set.
11395
+ * @param size - The number of elements, each initially its own singleton set
11396
+ */
11397
+ constructor(size) {
11398
+ this.parent = new Uint32Array(size);
11399
+ this.rank = new Uint32Array(size);
11400
+ for (let i = 0; i < size; i++) {
11401
+ this.parent[i] = i;
11402
+ }
11403
+ }
11404
+ /**
11405
+ * Find the representative of an element's set, halving the path on the way up.
11406
+ * @param x - An element index
11407
+ * @returns The representative of x's set
11408
+ */
11409
+ find(x) {
11410
+ let node = x;
11411
+ while (this.parent[node] !== node) {
11412
+ this.parent[node] = this.parent[this.parent[node]];
11413
+ node = this.parent[node];
11414
+ }
11415
+ return node;
11416
+ }
11417
+ /**
11418
+ * Merge the sets of two elements, attaching the shallower tree under the deeper one.
11419
+ * @param a - An element index
11420
+ * @param b - An element index
11421
+ * @returns True when the two sets were distinct and have now been merged
11422
+ */
11423
+ union(a, b) {
11424
+ const ra = this.find(a);
11425
+ const rb = this.find(b);
11426
+ if (ra === rb) {
11427
+ return false;
11428
+ }
11429
+ if (this.rank[ra] < this.rank[rb]) {
11430
+ this.parent[ra] = rb;
11431
+ } else if (this.rank[ra] > this.rank[rb]) {
11432
+ this.parent[rb] = ra;
11433
+ } else {
11434
+ this.parent[rb] = ra;
11435
+ this.rank[ra]++;
11436
+ }
11437
+ return true;
11438
+ }
11439
+ /**
11440
+ * Dense labels in FIRST-SEEN order, which is what makes `groups()` identical to the legacy
11441
+ * iteration order and identical to the GPU's after its own `renumberPartition` readback
11442
+ * (design 9.7's connectedComponents row).
11443
+ * @returns The labels and the number of distinct sets
11444
+ */
11445
+ toLabels() {
11446
+ const roots = new Uint32Array(this.parent.length);
11447
+ for (let i = 0; i < roots.length; i++) {
11448
+ roots[i] = this.find(i);
11449
+ }
11450
+ return renumberPartition(roots);
11451
+ }
11452
+ }
11453
+ function withGroups(labels, count) {
11454
+ let cached = null;
11455
+ return {
11456
+ labels,
11457
+ count,
11458
+ groups() {
11459
+ if (cached === null) {
11460
+ const sizes = new Uint32Array(count);
11461
+ for (let i = 0; i < labels.length; i++) {
11462
+ sizes[labels[i]]++;
11463
+ }
11464
+ const out = [];
11465
+ for (let c = 0; c < count; c++) {
11466
+ out.push(new Uint32Array(sizes[c]));
11467
+ }
11468
+ const fill = new Uint32Array(count);
11469
+ for (let i = 0; i < labels.length; i++) {
11470
+ const c = labels[i];
11471
+ out[c][fill[c]++] = i;
11472
+ }
11473
+ cached = out;
11474
+ }
11475
+ return cached;
11476
+ }
11477
+ };
11478
+ }
11479
+ function unionEdges(s) {
11480
+ const uf = new IntUnionFind(s.nodeCount);
11481
+ const el = s.edgeList();
11482
+ for (let e = 0; e < s.edgeCount; e++) {
11483
+ uf.union(el.src[e], el.dst[e]);
11484
+ }
11485
+ const { labels, count } = uf.toLabels();
11486
+ return withGroups(labels, count);
11487
+ }
11488
+ function connectedComponents(s) {
11489
+ if (s.directed) {
11490
+ throw new Error(
11491
+ "Connected components requires an undirected graph. Use weaklyConnectedComponents, or pass s.toUndirected().snapshot."
11492
+ );
11493
+ }
11494
+ return unionEdges(s);
11495
+ }
11496
+ function weaklyConnectedComponents(s) {
11497
+ return unionEdges(s);
11498
+ }
11499
+ function arcSourceIn(rowPtr, arc) {
11500
+ let lo = 0;
11501
+ let hi = rowPtr.length - 1;
11502
+ while (lo < hi) {
11503
+ const mid = lo + hi >> 1;
11504
+ if (rowPtr[mid + 1] <= arc) {
11505
+ lo = mid + 1;
11506
+ } else {
11507
+ hi = mid;
11508
+ }
11509
+ }
11510
+ return lo;
11511
+ }
11512
+ class IndexedMinHeap {
11513
+ /**
11514
+ * Create an empty heap over node indices in `[0, capacity)`.
11515
+ * @param capacity - The number of distinct node indices the heap may hold
11516
+ */
11517
+ constructor(capacity) {
11518
+ this.size = 0;
11519
+ this.heap = new Uint32Array(capacity);
11520
+ this.slot = new Uint32Array(capacity).fill(INVALID_INDEX);
11521
+ this.key = new Float64Array(capacity);
11522
+ }
11523
+ /**
11524
+ * Whether the heap holds no entries.
11525
+ * @returns True when the heap holds no entries
11526
+ */
11527
+ isEmpty() {
11528
+ return this.size === 0;
11529
+ }
11530
+ /**
11531
+ * Insert a node that is not in the heap.
11532
+ * @param node - The node index
11533
+ * @param key - Its key
11534
+ */
11535
+ push(node, key) {
11536
+ this.key[node] = key;
11537
+ this.heap[this.size] = node;
11538
+ this.slot[node] = this.size;
11539
+ this.size++;
11540
+ this.siftUp(this.size - 1);
11541
+ }
11542
+ /**
11543
+ * Insert the node, or lower its key if it is already present and the new key is smaller.
11544
+ * @param node - The node index
11545
+ * @param key - Its candidate key
11546
+ */
11547
+ pushOrDecrease(node, key) {
11548
+ const at = this.slot[node];
11549
+ if (at === INVALID_INDEX) {
11550
+ this.push(node, key);
11551
+ return;
11552
+ }
11553
+ if (key < this.key[node]) {
11554
+ this.key[node] = key;
11555
+ this.siftUp(at);
11556
+ }
11557
+ }
11558
+ /**
11559
+ * Remove and return the node with the smallest key. Undefined behaviour on an empty heap;
11560
+ * callers guard with `isEmpty()`.
11561
+ * @returns The node index
11562
+ */
11563
+ pop() {
11564
+ const top = this.heap[0];
11565
+ this.slot[top] = INVALID_INDEX;
11566
+ this.size--;
11567
+ if (this.size > 0) {
11568
+ const moved = this.heap[this.size];
11569
+ this.heap[0] = moved;
11570
+ this.slot[moved] = 0;
11571
+ this.siftDown(0);
11572
+ }
11573
+ return top;
11574
+ }
11575
+ siftUp(from) {
11576
+ let at = from;
11577
+ const node = this.heap[at];
11578
+ const key = this.key[node];
11579
+ while (at > 0) {
11580
+ const parent = at - 1 >> 1;
11581
+ const parentNode = this.heap[parent];
11582
+ if (this.key[parentNode] <= key) {
11583
+ break;
11584
+ }
11585
+ this.heap[at] = parentNode;
11586
+ this.slot[parentNode] = at;
11587
+ at = parent;
11588
+ }
11589
+ this.heap[at] = node;
11590
+ this.slot[node] = at;
11591
+ }
11592
+ siftDown(from) {
11593
+ let at = from;
11594
+ const node = this.heap[at];
11595
+ const key = this.key[node];
11596
+ for (; ; ) {
11597
+ const left = 2 * at + 1;
11598
+ if (left >= this.size) {
11599
+ break;
11600
+ }
11601
+ const right = left + 1;
11602
+ const child = right < this.size && this.key[this.heap[right]] < this.key[this.heap[left]] ? right : left;
11603
+ const childNode = this.heap[child];
11604
+ if (key <= this.key[childNode]) {
11605
+ break;
11606
+ }
11607
+ this.heap[at] = childNode;
11608
+ this.slot[childNode] = at;
11609
+ at = child;
11610
+ }
11611
+ this.heap[at] = node;
11612
+ this.slot[node] = at;
11613
+ }
11614
+ }
11615
+ function walkPredArcs(g, predArc, source, target) {
11616
+ if (target === source) {
11617
+ return Uint32Array.of(source);
11618
+ }
11619
+ if (predArc[target] === INVALID_INDEX) {
11620
+ return new Uint32Array(0);
11621
+ }
11622
+ const reversed = [target];
11623
+ let node = target;
11624
+ while (node !== source) {
11625
+ node = arcSourceIn(g.rowPtr, predArc[node]);
11626
+ reversed.push(node);
11627
+ }
11628
+ const out = new Uint32Array(reversed.length);
11629
+ for (let i = 0; i < reversed.length; i++) {
11630
+ out[i] = reversed[reversed.length - 1 - i];
11631
+ }
11632
+ return out;
11633
+ }
11634
+ function walkPredEdges(g, predArc, source, target) {
11635
+ if (target === source || predArc[target] === INVALID_INDEX) {
11636
+ return new Uint32Array(0);
11637
+ }
11638
+ const reversed = [];
11639
+ let node = target;
11640
+ while (node !== source) {
11641
+ const arc = predArc[node];
11642
+ reversed.push(g.arcToEdge[arc]);
11643
+ node = arcSourceIn(g.rowPtr, arc);
11644
+ }
11645
+ const out = new Uint32Array(reversed.length);
11646
+ for (let i = 0; i < reversed.length; i++) {
11647
+ out[i] = reversed[reversed.length - 1 - i];
11648
+ }
11649
+ return out;
11650
+ }
11651
+ function dijkstra(g, source, options = {}) {
11652
+ const { nodeCount, rowPtr, colIdx } = g;
11653
+ const weights = options.weights ?? g.weights;
11654
+ const dist = new Float64Array(nodeCount).fill(Infinity);
11655
+ const predArc = new Uint32Array(nodeCount).fill(INVALID_INDEX);
11656
+ const heap = new IndexedMinHeap(nodeCount);
11657
+ const cutoff = options.cutoff ?? Infinity;
11658
+ dist[source] = 0;
11659
+ heap.push(source, 0);
11660
+ while (!heap.isEmpty()) {
11661
+ const u = heap.pop();
11662
+ const du = dist[u];
11663
+ const end = rowPtr[u + 1];
11664
+ for (let a = rowPtr[u]; a < end; a++) {
11665
+ const w = weights === null ? 1 : weights[a];
11666
+ const v = colIdx[a];
11667
+ const dv = du + w;
11668
+ if (dv < dist[v] && dv <= cutoff) {
11669
+ dist[v] = dv;
11670
+ predArc[v] = a;
11671
+ heap.pushOrDecrease(v, dv);
11672
+ }
11673
+ }
11674
+ }
11675
+ return {
11676
+ dist,
11677
+ predArc,
11678
+ pathTo: (target) => walkPredArcs(g, predArc, source, target),
11679
+ pathEdges: (target) => walkPredEdges(g, predArc, source, target)
11680
+ };
11681
+ }
11682
+ function kruskalMST(s, o = {}) {
11683
+ const el = s.edgeList();
11684
+ const m = s.edgeCount;
11685
+ const keys = new Float64Array(m);
11686
+ if (o.weights !== void 0) {
11687
+ for (let e = 0; e < m; e++) {
11688
+ keys[e] = o.weights[el.arc[e]];
11689
+ }
11690
+ } else if (el.weights !== null) {
11691
+ for (let e = 0; e < m; e++) {
11692
+ keys[e] = el.weights[e];
11693
+ }
11694
+ } else {
11695
+ keys.fill(1);
11696
+ }
11697
+ const order = new Array(m);
11698
+ for (let e = 0; e < m; e++) {
11699
+ order[e] = e;
11700
+ }
11701
+ order.sort((a, b) => keys[a] - keys[b] || a - b);
11702
+ const uf = new IntUnionFind(s.nodeCount);
11703
+ const accepted = new Uint32Array(Math.max(s.nodeCount - 1, 0));
11704
+ let taken = 0;
11705
+ let totalWeight = 0;
11706
+ for (const e of order) {
11707
+ if (uf.union(el.src[e], el.dst[e])) {
11708
+ accepted[taken++] = e;
11709
+ totalWeight += keys[e];
11710
+ }
11711
+ }
11712
+ return { edges: accepted.subarray(0, taken), totalWeight };
11713
+ }
11714
+ function pageRank(s, o = {}) {
11715
+ if (!s.directed) {
11716
+ throw new Error("PageRank requires a directed graph");
11717
+ }
11718
+ const n = s.nodeCount;
11719
+ const d = o.dampingFactor ?? 0.85;
11720
+ const maxIter = o.maxIterations ?? 100;
11721
+ const tol = o.tolerance ?? 1e-6;
11722
+ const rev = s.reverse();
11723
+ const weighted = o.weighted === true && rev.weights !== null;
11724
+ const outW = weighted ? s.weightedOutDegree() : s.outDegree();
11725
+ let rank = new Float64Array(n).fill(1 / n);
11726
+ let next = new Float64Array(n);
11727
+ let it = 0;
11728
+ let converged = false;
11729
+ for (; it < maxIter && !converged; it++) {
11730
+ let dangling = 0;
11731
+ for (let u = 0; u < n; u++) {
11732
+ if (outW[u] === 0) {
11733
+ dangling += rank[u];
11734
+ }
11735
+ }
11736
+ const base = (1 - d) / n + d * dangling / n;
11737
+ let delta = 0;
11738
+ for (let v = 0; v < n; v++) {
11739
+ let acc = 0;
11740
+ const end = rev.rowPtr[v + 1];
11741
+ for (let a = rev.rowPtr[v]; a < end; a++) {
11742
+ const u = rev.colIdx[a];
11743
+ const ow = outW[u];
11744
+ if (ow > 0) {
11745
+ acc += rank[u] * (weighted && rev.weights !== null ? rev.weights[a] : 1) / ow;
11746
+ }
11747
+ }
11748
+ next[v] = base + d * acc;
11749
+ delta += Math.abs(next[v] - rank[v]);
11750
+ }
11751
+ [rank, next] = [next, rank];
11752
+ converged = delta < tol;
11753
+ }
11754
+ return { scores: rank, iterations: it, converged };
11755
+ }
11756
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
11757
+ __proto__: null,
11758
+ IndexedMinHeap,
11759
+ IntUnionFind,
11760
+ arcSourceIn,
11761
+ breadthFirstSearch,
11762
+ commonNeighborsScore,
11763
+ connectedComponents,
11764
+ dijkstra,
11765
+ kruskalMST,
11766
+ pageRank,
11767
+ walkPredArcs,
11768
+ walkPredEdges,
11769
+ weaklyConnectedComponents
11770
+ }, Symbol.toStringTag, { value: "Module" }));
11771
+ const SNAPSHOT_CACHE = /* @__PURE__ */ new WeakMap();
11772
+ function toSnapshot(graph, options = {}) {
11773
+ const checksum = options.checksum === true;
11774
+ const cached = SNAPSHOT_CACHE.get(graph);
11775
+ if (cached !== void 0 && cached.mutationCount === graph.mutationCount && (cached.checksum || !checksum)) {
11776
+ return cached.snapshot;
11777
+ }
11778
+ const builder = new GraphBuilder({
11779
+ directed: graph.isDirected,
11780
+ weightDtype: "f64",
11781
+ expectedNodes: graph.nodeCount,
11782
+ expectedEdges: graph.totalEdgeCount
11783
+ });
11784
+ for (const node of graph.nodes()) {
11785
+ builder.addNode(node.id);
11786
+ }
11787
+ for (const edge of graph.edges()) {
11788
+ builder.addEdge(edge.source, edge.target, edge.weight);
11789
+ }
11790
+ const snapshot = builder.freeze({ label: "algorithms.toSnapshot", checksum });
11791
+ SNAPSHOT_CACHE.set(graph, { mutationCount: graph.mutationCount, checksum, snapshot });
11792
+ return snapshot;
11793
+ }
11794
+ function decorateSssp(s, source, like) {
11795
+ const { predArc } = like;
11796
+ return {
11797
+ dist: like.dist,
11798
+ predArc,
11799
+ pathTo: (target) => walkPredArcs(s, predArc, source, target),
11800
+ pathEdges: (target) => walkPredEdges(s, predArc, source, target)
11801
+ };
11802
+ }
11803
+ function accelerated(acc) {
11804
+ return {
11805
+ accelerator: acc ?? null,
11806
+ pageRank: (s, options) => acc?.pageRank !== void 0 ? acc.pageRank(s, options) : Promise.resolve(pageRank(s, options)),
11807
+ sssp: (s, source, options) => acc?.sssp !== void 0 ? acc.sssp(s, source, options).then((like) => decorateSssp(s, source, like)) : Promise.resolve(dijkstra(s, source, options)),
11808
+ breadthFirstSearch: (s, source, options) => acc?.breadthFirstSearch !== void 0 ? acc.breadthFirstSearch(s, source, options) : Promise.resolve(breadthFirstSearch(s, source, options)),
11809
+ connectedComponents: (s) => acc?.connectedComponents !== void 0 ? acc.connectedComponents(s) : Promise.resolve(connectedComponents(s)),
11810
+ weaklyConnectedComponents: (s) => acc?.weaklyConnectedComponents !== void 0 ? acc.weaklyConnectedComponents(s) : Promise.resolve(weaklyConnectedComponents(s)),
11811
+ minimumSpanningTree: (s, options) => acc?.minimumSpanningTree !== void 0 ? acc.minimumSpanningTree(s, options) : Promise.resolve(kruskalMST(s, options))
11812
+ };
11813
+ }
11304
11814
  export {
11305
11815
  CSRGraph,
11306
11816
  CompactDistanceArray,
@@ -11312,6 +11822,7 @@ export {
11312
11822
  PriorityQueue,
11313
11823
  UnionFind,
11314
11824
  VisitedBitArray,
11825
+ accelerated,
11315
11826
  adamicAdarForPairs,
11316
11827
  adamicAdarPrediction,
11317
11828
  adamicAdarScore,
@@ -11322,22 +11833,22 @@ export {
11322
11833
  bellmanFordPath,
11323
11834
  betweennessCentrality,
11324
11835
  bipartitePartition,
11325
- breadthFirstSearch,
11836
+ breadthFirstSearch$1 as breadthFirstSearch,
11326
11837
  calculateMCLModularity,
11327
11838
  closenessCentrality,
11328
11839
  commonNeighborsForPairs,
11329
11840
  commonNeighborsPrediction,
11330
- commonNeighborsScore,
11841
+ commonNeighborsScore$1 as commonNeighborsScore,
11331
11842
  compareAdamicAdarWithCommonNeighbors,
11332
11843
  condensationGraph,
11333
11844
  configureOptimizations,
11334
- connectedComponents,
11845
+ connectedComponents$1 as connectedComponents,
11335
11846
  connectedComponentsDFS,
11336
11847
  createBipartiteFlowNetwork,
11337
11848
  createOptimizedGraph,
11338
11849
  degreeCentrality,
11339
11850
  depthFirstSearch,
11340
- dijkstra,
11851
+ dijkstra$1 as dijkstra,
11341
11852
  dijkstraPath,
11342
11853
  edgeBetweennessCentrality,
11343
11854
  edmondsKarp,
@@ -11362,6 +11873,7 @@ export {
11362
11873
  heuristics,
11363
11874
  hierarchicalClustering,
11364
11875
  hits,
11876
+ index as indexed,
11365
11877
  isBipartite,
11366
11878
  isCSRGraph,
11367
11879
  isConnected,
@@ -11371,7 +11883,7 @@ export {
11371
11883
  kCoreDecomposition,
11372
11884
  kargerMinCut,
11373
11885
  katzCentrality,
11374
- kruskalMST,
11886
+ kruskalMST$1 as kruskalMST,
11375
11887
  labelPropagation,
11376
11888
  labelPropagationAsync,
11377
11889
  labelPropagationSemiSupervised,
@@ -11390,7 +11902,7 @@ export {
11390
11902
  nodeKatzCentrality,
11391
11903
  nodeWeightedClosenessCentrality,
11392
11904
  numberOfConnectedComponents,
11393
- pageRank,
11905
+ pageRank$1 as pageRank,
11394
11906
  pageRankCentrality,
11395
11907
  pathfindingUtils,
11396
11908
  personalizedPageRank,
@@ -11404,10 +11916,11 @@ export {
11404
11916
  syncClustering,
11405
11917
  teraHAC,
11406
11918
  toCSRGraph,
11919
+ toSnapshot,
11407
11920
  topPageRankNodes,
11408
11921
  topologicalSort,
11409
11922
  transitiveClosure,
11410
- weaklyConnectedComponents,
11923
+ weaklyConnectedComponents$1 as weaklyConnectedComponents,
11411
11924
  weightedClosenessCentrality
11412
11925
  };
11413
11926
  //# sourceMappingURL=algorithms.js.map