@graphty/algorithms 1.3.1 → 1.4.2
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/README.md +358 -413
- package/dist/algorithms.js +564 -261
- package/dist/algorithms.js.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.d.ts +10 -0
- package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/betweenness.js +27 -6
- package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
- package/dist/src/algorithms/centrality/closeness.d.ts +11 -2
- package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/closeness.js +17 -3
- package/dist/src/algorithms/centrality/closeness.js.map +1 -1
- package/dist/src/algorithms/centrality/degree.d.ts +7 -0
- package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/degree.js +9 -6
- package/dist/src/algorithms/centrality/degree.js.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts +21 -3
- package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js +25 -7
- package/dist/src/algorithms/centrality/delta-pagerank-simple.js.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts +28 -2
- package/dist/src/algorithms/centrality/delta-pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/delta-pagerank.js +30 -4
- package/dist/src/algorithms/centrality/delta-pagerank.js.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -3
- package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/eigenvector.js +11 -4
- package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
- package/dist/src/algorithms/centrality/hits.d.ts +10 -3
- package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/hits.js +11 -4
- package/dist/src/algorithms/centrality/hits.js.map +1 -1
- package/dist/src/algorithms/centrality/index.d.ts +1 -1
- package/dist/src/algorithms/centrality/index.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/index.js +1 -1
- package/dist/src/algorithms/centrality/index.js.map +1 -1
- package/dist/src/algorithms/centrality/katz.d.ts +10 -3
- package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/katz.js +13 -8
- package/dist/src/algorithms/centrality/katz.js.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.d.ts +14 -0
- package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
- package/dist/src/algorithms/centrality/pagerank.js +16 -1
- package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.d.ts +2 -3
- package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
- package/dist/src/algorithms/community/girvan-newman.js +21 -4
- package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
- package/dist/src/algorithms/community/index.d.ts.map +1 -1
- package/dist/src/algorithms/community/index.js.map +1 -1
- package/dist/src/algorithms/community/label-propagation.d.ts +0 -3
- package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
- package/dist/src/algorithms/community/label-propagation.js +13 -6
- package/dist/src/algorithms/community/label-propagation.js.map +1 -1
- package/dist/src/algorithms/community/leiden.d.ts +0 -1
- package/dist/src/algorithms/community/leiden.d.ts.map +1 -1
- package/dist/src/algorithms/community/leiden.js +37 -6
- package/dist/src/algorithms/community/leiden.js.map +1 -1
- package/dist/src/algorithms/community/louvain-optimized.d.ts +37 -0
- package/dist/src/algorithms/community/louvain-optimized.d.ts.map +1 -1
- package/dist/src/algorithms/community/louvain-optimized.js +42 -7
- package/dist/src/algorithms/community/louvain-optimized.js.map +1 -1
- package/dist/src/algorithms/community/louvain.d.ts +2 -3
- package/dist/src/algorithms/community/louvain.d.ts.map +1 -1
- package/dist/src/algorithms/community/louvain.js +19 -6
- package/dist/src/algorithms/community/louvain.js.map +1 -1
- package/dist/src/algorithms/community/modularity-utils.d.ts +0 -4
- package/dist/src/algorithms/community/modularity-utils.d.ts.map +1 -1
- package/dist/src/algorithms/community/modularity-utils.js +1 -5
- package/dist/src/algorithms/community/modularity-utils.js.map +1 -1
- package/dist/src/algorithms/components/connected.d.ts +23 -0
- package/dist/src/algorithms/components/connected.d.ts.map +1 -1
- package/dist/src/algorithms/components/connected.js +29 -3
- package/dist/src/algorithms/components/connected.js.map +1 -1
- package/dist/src/algorithms/matching/bipartite.d.ts +10 -0
- package/dist/src/algorithms/matching/bipartite.d.ts.map +1 -1
- package/dist/src/algorithms/matching/bipartite.js +10 -0
- package/dist/src/algorithms/matching/bipartite.js.map +1 -1
- package/dist/src/algorithms/matching/index.d.ts.map +1 -1
- package/dist/src/algorithms/matching/index.js.map +1 -1
- package/dist/src/algorithms/matching/isomorphism.d.ts +8 -0
- package/dist/src/algorithms/matching/isomorphism.d.ts.map +1 -1
- package/dist/src/algorithms/matching/isomorphism.js +36 -2
- package/dist/src/algorithms/matching/isomorphism.js.map +1 -1
- package/dist/src/algorithms/mst/index.d.ts.map +1 -1
- package/dist/src/algorithms/mst/index.js.map +1 -1
- package/dist/src/algorithms/mst/kruskal.d.ts +14 -0
- package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
- package/dist/src/algorithms/mst/kruskal.js +17 -3
- package/dist/src/algorithms/mst/kruskal.js.map +1 -1
- package/dist/src/algorithms/mst/prim.d.ts +9 -0
- package/dist/src/algorithms/mst/prim.d.ts.map +1 -1
- package/dist/src/algorithms/mst/prim.js +9 -0
- package/dist/src/algorithms/mst/prim.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.d.ts +10 -0
- package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/bellman-ford.js +10 -0
- package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts +11 -4
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js +18 -16
- package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts +15 -0
- package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/dijkstra.js +15 -0
- package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +17 -0
- package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/floyd-warshall.js +17 -0
- package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
- package/dist/src/algorithms/shortest-path/index.d.ts.map +1 -1
- package/dist/src/algorithms/shortest-path/index.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.d.ts +13 -0
- package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-unified.js +37 -0
- package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.d.ts +23 -0
- package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs-variants.js +34 -0
- package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -1
- package/dist/src/algorithms/traversal/bfs.d.ts +1 -1
- package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/bfs.js +1 -1
- package/dist/src/algorithms/traversal/bfs.js.map +1 -1
- package/dist/src/algorithms/traversal/dfs.d.ts +10 -0
- package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/dfs.js +48 -0
- package/dist/src/algorithms/traversal/dfs.js.map +1 -1
- package/dist/src/algorithms/traversal/index.d.ts.map +1 -1
- package/dist/src/algorithms/traversal/index.js.map +1 -1
- package/dist/src/benchmark-all-algorithms.d.ts +2 -0
- package/dist/src/benchmark-all-algorithms.d.ts.map +1 -1
- package/dist/src/benchmark-all-algorithms.js +32 -3
- package/dist/src/benchmark-all-algorithms.js.map +1 -1
- package/dist/src/clustering/hierarchical.d.ts +8 -1
- package/dist/src/clustering/hierarchical.d.ts.map +1 -1
- package/dist/src/clustering/hierarchical.js +22 -6
- package/dist/src/clustering/hierarchical.js.map +1 -1
- package/dist/src/clustering/index.d.ts.map +1 -1
- package/dist/src/clustering/index.js.map +1 -1
- package/dist/src/clustering/k-core.d.ts +2 -5
- package/dist/src/clustering/k-core.d.ts.map +1 -1
- package/dist/src/clustering/k-core.js +14 -12
- package/dist/src/clustering/k-core.js.map +1 -1
- package/dist/src/clustering/mcl.d.ts +6 -0
- package/dist/src/clustering/mcl.d.ts.map +1 -1
- package/dist/src/clustering/mcl.js +34 -3
- package/dist/src/clustering/mcl.js.map +1 -1
- package/dist/src/clustering/spectral.d.ts +4 -1
- package/dist/src/clustering/spectral.d.ts.map +1 -1
- package/dist/src/clustering/spectral.js +61 -28
- package/dist/src/clustering/spectral.js.map +1 -1
- package/dist/src/core/graph.d.ts +45 -0
- package/dist/src/core/graph.d.ts.map +1 -1
- package/dist/src/core/graph.js +45 -1
- package/dist/src/core/graph.js.map +1 -1
- package/dist/src/data-structures/index.d.ts.map +1 -1
- package/dist/src/data-structures/index.js.map +1 -1
- package/dist/src/data-structures/priority-queue.d.ts +18 -1
- package/dist/src/data-structures/priority-queue.d.ts.map +1 -1
- package/dist/src/data-structures/priority-queue.js +26 -5
- package/dist/src/data-structures/priority-queue.js.map +1 -1
- package/dist/src/data-structures/union-find.d.ts +21 -0
- package/dist/src/data-structures/union-find.d.ts.map +1 -1
- package/dist/src/data-structures/union-find.js +21 -0
- package/dist/src/data-structures/union-find.js.map +1 -1
- package/dist/src/flow/ford-fulkerson.d.ts +4 -2
- package/dist/src/flow/ford-fulkerson.d.ts.map +1 -1
- package/dist/src/flow/ford-fulkerson.js +31 -2
- package/dist/src/flow/ford-fulkerson.js.map +1 -1
- package/dist/src/flow/min-cut.d.ts +0 -3
- package/dist/src/flow/min-cut.d.ts.map +1 -1
- package/dist/src/flow/min-cut.js +17 -4
- package/dist/src/flow/min-cut.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/link-prediction/adamic-adar.d.ts +26 -0
- package/dist/src/link-prediction/adamic-adar.d.ts.map +1 -1
- package/dist/src/link-prediction/adamic-adar.js +36 -10
- package/dist/src/link-prediction/adamic-adar.js.map +1 -1
- package/dist/src/link-prediction/common-neighbors.d.ts +21 -0
- package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
- package/dist/src/link-prediction/common-neighbors.js +27 -6
- package/dist/src/link-prediction/common-neighbors.js.map +1 -1
- package/dist/src/link-prediction/index.d.ts.map +1 -1
- package/dist/src/optimized/bit-packed.d.ts +103 -53
- package/dist/src/optimized/bit-packed.d.ts.map +1 -1
- package/dist/src/optimized/bit-packed.js +104 -54
- package/dist/src/optimized/bit-packed.js.map +1 -1
- package/dist/src/optimized/csr-graph.d.ts +87 -24
- package/dist/src/optimized/csr-graph.d.ts.map +1 -1
- package/dist/src/optimized/csr-graph.js +87 -24
- package/dist/src/optimized/csr-graph.js.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.d.ts +37 -16
- package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -1
- package/dist/src/optimized/direction-optimized-bfs.js +39 -20
- package/dist/src/optimized/direction-optimized-bfs.js.map +1 -1
- package/dist/src/optimized/graph-adapter.d.ts +58 -9
- package/dist/src/optimized/graph-adapter.d.ts.map +1 -1
- package/dist/src/optimized/graph-adapter.js +58 -10
- package/dist/src/optimized/graph-adapter.js.map +1 -1
- package/dist/src/optimized/index.d.ts +1 -1
- package/dist/src/optimized/index.d.ts.map +1 -1
- package/dist/src/optimized/index.js +3 -1
- package/dist/src/optimized/index.js.map +1 -1
- package/dist/src/pathfinding/astar.d.ts +25 -9
- package/dist/src/pathfinding/astar.d.ts.map +1 -1
- package/dist/src/pathfinding/astar.js +25 -10
- package/dist/src/pathfinding/astar.js.map +1 -1
- package/dist/src/pathfinding/utils.d.ts +15 -6
- package/dist/src/pathfinding/utils.d.ts.map +1 -1
- package/dist/src/pathfinding/utils.js +19 -7
- package/dist/src/pathfinding/utils.js.map +1 -1
- package/dist/src/research/grsbm.d.ts +0 -1
- package/dist/src/research/grsbm.d.ts.map +1 -1
- package/dist/src/research/grsbm.js +22 -9
- package/dist/src/research/grsbm.js.map +1 -1
- package/dist/src/research/index.d.ts.map +1 -1
- package/dist/src/research/index.js.map +1 -1
- package/dist/src/research/sync.d.ts +0 -1
- package/dist/src/research/sync.d.ts.map +1 -1
- package/dist/src/research/sync.js +28 -7
- package/dist/src/research/sync.js.map +1 -1
- package/dist/src/research/terahac.d.ts +0 -1
- package/dist/src/research/terahac.d.ts.map +1 -1
- package/dist/src/research/terahac.js +32 -4
- package/dist/src/research/terahac.js.map +1 -1
- package/dist/src/utils/graph-converters.d.ts +31 -0
- package/dist/src/utils/graph-converters.d.ts.map +1 -1
- package/dist/src/utils/graph-converters.js +31 -0
- package/dist/src/utils/graph-converters.js.map +1 -1
- package/dist/src/utils/graph-utilities.d.ts.map +1 -1
- package/dist/src/utils/graph-utilities.js.map +1 -1
- package/dist/src/utils/math-utilities.d.ts +11 -0
- package/dist/src/utils/math-utilities.d.ts.map +1 -1
- package/dist/src/utils/math-utilities.js +14 -5
- package/dist/src/utils/math-utilities.js.map +1 -1
- package/dist/src/utils/optimization-helpers.d.ts +9 -0
- package/dist/src/utils/optimization-helpers.d.ts.map +1 -1
- package/dist/src/utils/optimization-helpers.js +12 -0
- package/dist/src/utils/optimization-helpers.js.map +1 -1
- package/dist/src/utils/priorityQueue.d.ts +24 -0
- package/dist/src/utils/priorityQueue.d.ts.map +1 -1
- package/dist/src/utils/priorityQueue.js +34 -4
- package/dist/src/utils/priorityQueue.js.map +1 -1
- package/package.json +49 -45
- package/src/algorithms/centrality/betweenness.ts +34 -17
- package/src/algorithms/centrality/closeness.ts +34 -17
- package/src/algorithms/centrality/degree.ts +15 -19
- package/src/algorithms/centrality/delta-pagerank-simple.ts +36 -28
- package/src/algorithms/centrality/delta-pagerank.ts +34 -11
- package/src/algorithms/centrality/eigenvector.ts +14 -15
- package/src/algorithms/centrality/hits.ts +17 -17
- package/src/algorithms/centrality/index.ts +20 -15
- package/src/algorithms/centrality/katz.ts +17 -25
- package/src/algorithms/centrality/pagerank.ts +26 -17
- package/src/algorithms/community/girvan-newman.ts +39 -28
- package/src/algorithms/community/index.ts +6 -7
- package/src/algorithms/community/label-propagation.ts +20 -28
- package/src/algorithms/community/leiden.ts +61 -37
- package/src/algorithms/community/louvain-optimized.ts +49 -20
- package/src/algorithms/community/louvain.ts +35 -25
- package/src/algorithms/community/modularity-utils.ts +5 -17
- package/src/algorithms/components/connected.ts +40 -17
- package/src/algorithms/matching/bipartite.ts +17 -10
- package/src/algorithms/matching/index.ts +4 -4
- package/src/algorithms/matching/isomorphism.ts +53 -23
- package/src/algorithms/mst/index.ts +3 -4
- package/src/algorithms/mst/kruskal.ts +21 -6
- package/src/algorithms/mst/prim.ts +13 -4
- package/src/algorithms/shortest-path/bellman-ford.ts +16 -15
- package/src/algorithms/shortest-path/bidirectional-dijkstra.ts +28 -28
- package/src/algorithms/shortest-path/dijkstra.ts +23 -17
- package/src/algorithms/shortest-path/floyd-warshall.ts +21 -4
- package/src/algorithms/shortest-path/index.ts +5 -5
- package/src/algorithms/traversal/bfs-unified.ts +64 -60
- package/src/algorithms/traversal/bfs-variants.ts +61 -37
- package/src/algorithms/traversal/bfs.ts +1 -7
- package/src/algorithms/traversal/dfs.ts +61 -42
- package/src/algorithms/traversal/index.ts +3 -3
- package/src/benchmark-all-algorithms.ts +57 -25
- package/src/clustering/hierarchical.ts +40 -34
- package/src/clustering/index.ts +8 -8
- package/src/clustering/k-core.ts +26 -42
- package/src/clustering/mcl.ts +53 -23
- package/src/clustering/spectral.ts +91 -57
- package/src/core/graph.ts +54 -14
- package/src/data-structures/index.ts +2 -2
- package/src/data-structures/priority-queue.ts +36 -11
- package/src/data-structures/union-find.ts +22 -1
- package/src/flow/ford-fulkerson.ts +62 -35
- package/src/flow/min-cut.ts +43 -45
- package/src/index.ts +3 -2
- package/src/link-prediction/adamic-adar.ts +65 -51
- package/src/link-prediction/common-neighbors.ts +45 -36
- package/src/link-prediction/index.ts +1 -1
- package/src/optimized/bit-packed.ts +106 -56
- package/src/optimized/csr-graph.ts +93 -30
- package/src/optimized/direction-optimized-bfs.ts +44 -25
- package/src/optimized/graph-adapter.ts +64 -16
- package/src/optimized/index.ts +7 -9
- package/src/pathfinding/astar.ts +40 -25
- package/src/pathfinding/utils.ts +20 -13
- package/src/research/grsbm.ts +30 -24
- package/src/research/index.ts +4 -4
- package/src/research/sync.ts +39 -23
- package/src/research/terahac.ts +54 -20
- package/src/utils/graph-converters.ts +42 -14
- package/src/utils/graph-utilities.ts +11 -37
- package/src/utils/math-utilities.ts +17 -8
- package/src/utils/optimization-helpers.ts +27 -21
- package/src/utils/priorityQueue.ts +40 -6
|
@@ -6,6 +6,10 @@ import { TypedFastBitSet } from "typedfastbitset";
|
|
|
6
6
|
* with 8x memory reduction compared to standard JavaScript Set for boolean values.
|
|
7
7
|
*/
|
|
8
8
|
export class GraphBitSet {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new GraphBitSet with optional pre-allocated capacity.
|
|
11
|
+
* @param capacity - The initial capacity to pre-allocate for the bitset
|
|
12
|
+
*/
|
|
9
13
|
constructor(capacity) {
|
|
10
14
|
this._cardinality = 0;
|
|
11
15
|
this.bitset = new TypedFastBitSet();
|
|
@@ -15,8 +19,9 @@ export class GraphBitSet {
|
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
* Add a single element to the set.
|
|
23
|
+
* @param index - The element index to add
|
|
24
|
+
*/
|
|
20
25
|
add(index) {
|
|
21
26
|
if (!this.bitset.has(index)) {
|
|
22
27
|
this.bitset.add(index);
|
|
@@ -24,8 +29,9 @@ export class GraphBitSet {
|
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
* Remove a single element from the set.
|
|
33
|
+
* @param index - The element index to remove
|
|
34
|
+
*/
|
|
29
35
|
remove(index) {
|
|
30
36
|
if (this.bitset.has(index)) {
|
|
31
37
|
this.bitset.remove(index);
|
|
@@ -33,27 +39,32 @@ export class GraphBitSet {
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
* Check if an element exists in the set.
|
|
43
|
+
* @param index - The element index to check
|
|
44
|
+
* @returns True if the element exists, false otherwise
|
|
45
|
+
*/
|
|
38
46
|
has(index) {
|
|
39
47
|
return this.bitset.has(index);
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
* Clear all elements
|
|
51
|
+
*/
|
|
44
52
|
clear() {
|
|
45
53
|
this.bitset.clear();
|
|
46
54
|
this._cardinality = 0;
|
|
47
55
|
}
|
|
48
56
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
* Check if the set is empty.
|
|
58
|
+
* @returns True if the set contains no elements, false otherwise
|
|
59
|
+
*/
|
|
51
60
|
isEmpty() {
|
|
52
61
|
return this._cardinality === 0;
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
* Optimized for graph algorithms - add a range of indices.
|
|
65
|
+
* @param start - The starting index (inclusive)
|
|
66
|
+
* @param end - The ending index (exclusive)
|
|
67
|
+
*/
|
|
57
68
|
addRange(start, end) {
|
|
58
69
|
for (let i = start; i < end; i++) {
|
|
59
70
|
if (!this.bitset.has(i)) {
|
|
@@ -63,40 +74,52 @@ export class GraphBitSet {
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
* Fast cardinality tracking - get the number of elements in the set.
|
|
78
|
+
* @returns The number of elements in the set
|
|
79
|
+
*/
|
|
68
80
|
size() {
|
|
69
81
|
return this._cardinality;
|
|
70
82
|
}
|
|
71
83
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
* Batch operations for frontier management - swap contents with another GraphBitSet.
|
|
85
|
+
* @param other - The GraphBitSet to swap contents with
|
|
86
|
+
*/
|
|
74
87
|
swap(other) {
|
|
75
88
|
[this.bitset, other.bitset] = [other.bitset, this.bitset];
|
|
76
89
|
[this._cardinality, other._cardinality] = [other._cardinality, this._cardinality];
|
|
77
90
|
}
|
|
78
91
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
* Efficient iteration over all elements in the set.
|
|
93
|
+
* @yields The indices of elements in the set
|
|
94
|
+
*/
|
|
81
95
|
*[Symbol.iterator]() {
|
|
82
96
|
// Use TypedFastBitSet's optimized iteration
|
|
83
97
|
yield* this.bitset;
|
|
84
98
|
}
|
|
85
99
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
100
|
+
* Perform union operation with another GraphBitSet, updating this set in place.
|
|
101
|
+
* @param other - The GraphBitSet to union with
|
|
102
|
+
*/
|
|
88
103
|
union(other) {
|
|
89
104
|
const result = this.bitset.union(other.bitset);
|
|
90
105
|
this.bitset = result;
|
|
91
106
|
const size = this.bitset.size();
|
|
92
107
|
this._cardinality = size;
|
|
93
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Perform intersection operation with another GraphBitSet, updating this set in place.
|
|
111
|
+
* @param other - The GraphBitSet to intersect with
|
|
112
|
+
*/
|
|
94
113
|
intersection(other) {
|
|
95
114
|
const result = this.bitset.intersection(other.bitset);
|
|
96
115
|
this.bitset = result;
|
|
97
116
|
const size = this.bitset.size();
|
|
98
117
|
this._cardinality = size;
|
|
99
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Perform difference operation with another GraphBitSet, updating this set in place.
|
|
121
|
+
* @param other - The GraphBitSet to subtract from this set
|
|
122
|
+
*/
|
|
100
123
|
difference(other) {
|
|
101
124
|
const result = this.bitset.difference(other.bitset);
|
|
102
125
|
this.bitset = result;
|
|
@@ -104,8 +127,9 @@ export class GraphBitSet {
|
|
|
104
127
|
this._cardinality = size;
|
|
105
128
|
}
|
|
106
129
|
/**
|
|
107
|
-
|
|
108
|
-
|
|
130
|
+
* Clone the bitset.
|
|
131
|
+
* @returns A new GraphBitSet with the same elements
|
|
132
|
+
*/
|
|
109
133
|
clone() {
|
|
110
134
|
const cloned = new GraphBitSet();
|
|
111
135
|
cloned.bitset = this.bitset.clone();
|
|
@@ -120,14 +144,19 @@ export class GraphBitSet {
|
|
|
120
144
|
* that don't need set operations.
|
|
121
145
|
*/
|
|
122
146
|
export class VisitedBitArray {
|
|
147
|
+
/**
|
|
148
|
+
* Creates a new VisitedBitArray with the specified size.
|
|
149
|
+
* @param size - The number of bits to allocate
|
|
150
|
+
*/
|
|
123
151
|
constructor(size) {
|
|
124
152
|
this._size = size;
|
|
125
153
|
this.wordCount = Math.ceil(size / 32);
|
|
126
154
|
this.words = new Uint32Array(this.wordCount);
|
|
127
155
|
}
|
|
128
156
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
157
|
+
* Set bit at the specified index.
|
|
158
|
+
* @param index - The bit index to set
|
|
159
|
+
*/
|
|
131
160
|
set(index) {
|
|
132
161
|
if (index < 0 || index >= this._size) {
|
|
133
162
|
throw new Error(`Index ${String(index)} out of bounds [0, ${String(this._size)})`);
|
|
@@ -140,8 +169,10 @@ export class VisitedBitArray {
|
|
|
140
169
|
}
|
|
141
170
|
}
|
|
142
171
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
172
|
+
* Get bit value at the specified index.
|
|
173
|
+
* @param index - The bit index to get
|
|
174
|
+
* @returns True if the bit is set, false otherwise
|
|
175
|
+
*/
|
|
145
176
|
get(index) {
|
|
146
177
|
if (index < 0 || index >= this._size) {
|
|
147
178
|
return false;
|
|
@@ -152,14 +183,15 @@ export class VisitedBitArray {
|
|
|
152
183
|
return word !== undefined && (word & (1 << bitIndex)) !== 0;
|
|
153
184
|
}
|
|
154
185
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
186
|
+
* Clear all bits
|
|
187
|
+
*/
|
|
157
188
|
clear() {
|
|
158
189
|
this.words.fill(0);
|
|
159
190
|
}
|
|
160
191
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
192
|
+
* Toggle bit at the specified index.
|
|
193
|
+
* @param index - The bit index to toggle
|
|
194
|
+
*/
|
|
163
195
|
toggle(index) {
|
|
164
196
|
if (index < 0 || index >= this._size) {
|
|
165
197
|
throw new Error(`Index ${String(index)} out of bounds [0, ${String(this._size)})`);
|
|
@@ -172,8 +204,9 @@ export class VisitedBitArray {
|
|
|
172
204
|
}
|
|
173
205
|
}
|
|
174
206
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
207
|
+
* Population count for statistics - count the number of set bits.
|
|
208
|
+
* @returns The number of bits set to 1
|
|
209
|
+
*/
|
|
177
210
|
popcount() {
|
|
178
211
|
let count = 0;
|
|
179
212
|
for (let i = 0; i < this.wordCount; i++) {
|
|
@@ -185,24 +218,28 @@ export class VisitedBitArray {
|
|
|
185
218
|
return count;
|
|
186
219
|
}
|
|
187
220
|
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
221
|
+
* Efficient population count for a single word.
|
|
222
|
+
* Uses bit manipulation tricks for fast counting.
|
|
223
|
+
* @param n - The 32-bit word to count
|
|
224
|
+
* @returns The number of bits set to 1 in the word
|
|
225
|
+
*/
|
|
191
226
|
popcountWord(n) {
|
|
192
227
|
let x = n;
|
|
193
228
|
x = x - ((x >>> 1) & 0x55555555);
|
|
194
229
|
x = (x & 0x33333333) + ((x >>> 2) & 0x33333333);
|
|
195
|
-
return (((x + (x >>> 4)) &
|
|
230
|
+
return (((x + (x >>> 4)) & 0xf0f0f0f) * 0x1010101) >>> 24;
|
|
196
231
|
}
|
|
197
232
|
/**
|
|
198
|
-
|
|
199
|
-
|
|
233
|
+
* Get size of the bit array.
|
|
234
|
+
* @returns The total number of bits in the array
|
|
235
|
+
*/
|
|
200
236
|
size() {
|
|
201
237
|
return this._size;
|
|
202
238
|
}
|
|
203
239
|
/**
|
|
204
|
-
|
|
205
|
-
|
|
240
|
+
* Check if all bits are zero.
|
|
241
|
+
* @returns True if no bits are set, false otherwise
|
|
242
|
+
*/
|
|
206
243
|
isEmpty() {
|
|
207
244
|
for (let i = 0; i < this.wordCount; i++) {
|
|
208
245
|
if (this.words[i] !== 0) {
|
|
@@ -212,16 +249,18 @@ export class VisitedBitArray {
|
|
|
212
249
|
return true;
|
|
213
250
|
}
|
|
214
251
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
252
|
+
* Set multiple bits from an array of indices.
|
|
253
|
+
* @param indices - Array of bit indices to set
|
|
254
|
+
*/
|
|
217
255
|
setMultiple(indices) {
|
|
218
256
|
for (const index of indices) {
|
|
219
257
|
this.set(index);
|
|
220
258
|
}
|
|
221
259
|
}
|
|
222
260
|
/**
|
|
223
|
-
|
|
224
|
-
|
|
261
|
+
* Get indices of all set bits.
|
|
262
|
+
* @returns Array containing the indices of all bits that are set to 1
|
|
263
|
+
*/
|
|
225
264
|
getSetIndices() {
|
|
226
265
|
const indices = [];
|
|
227
266
|
for (let wordIndex = 0; wordIndex < this.wordCount; wordIndex++) {
|
|
@@ -248,14 +287,20 @@ export class VisitedBitArray {
|
|
|
248
287
|
* Still provides 2x memory savings compared to standard 32-bit numbers
|
|
249
288
|
*/
|
|
250
289
|
export class CompactDistanceArray {
|
|
290
|
+
/**
|
|
291
|
+
* Creates a new CompactDistanceArray with the specified size.
|
|
292
|
+
* @param size - The number of distance values to store
|
|
293
|
+
*/
|
|
251
294
|
constructor(size) {
|
|
252
295
|
this._size = size;
|
|
253
296
|
this.data = new Uint16Array(size);
|
|
254
297
|
this.data.fill(CompactDistanceArray.INFINITY); // Initialize with max value (unvisited)
|
|
255
298
|
}
|
|
256
299
|
/**
|
|
257
|
-
|
|
258
|
-
|
|
300
|
+
* Set distance at the specified index.
|
|
301
|
+
* @param index - The node index to set the distance for
|
|
302
|
+
* @param distance - The distance value to set
|
|
303
|
+
*/
|
|
259
304
|
set(index, distance) {
|
|
260
305
|
if (distance >= CompactDistanceArray.INFINITY) {
|
|
261
306
|
throw new Error(`Distance exceeds maximum value (${String(CompactDistanceArray.INFINITY - 1)})`);
|
|
@@ -263,27 +308,32 @@ export class CompactDistanceArray {
|
|
|
263
308
|
this.data[index] = distance;
|
|
264
309
|
}
|
|
265
310
|
/**
|
|
266
|
-
|
|
267
|
-
|
|
311
|
+
* Get distance at the specified index.
|
|
312
|
+
* @param index - The node index to get the distance for
|
|
313
|
+
* @returns The distance value, or INFINITY if not set
|
|
314
|
+
*/
|
|
268
315
|
get(index) {
|
|
269
316
|
const value = this.data[index];
|
|
270
317
|
return value ?? CompactDistanceArray.INFINITY; // Default to unvisited
|
|
271
318
|
}
|
|
272
319
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
320
|
+
* Check if a node has been visited (has a valid distance).
|
|
321
|
+
* @param index - The node index to check
|
|
322
|
+
* @returns True if the node has been visited, false otherwise
|
|
323
|
+
*/
|
|
275
324
|
isVisited(index) {
|
|
276
325
|
return this.data[index] !== CompactDistanceArray.INFINITY;
|
|
277
326
|
}
|
|
278
327
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
328
|
+
* Reset all distances to unvisited state.
|
|
329
|
+
*/
|
|
281
330
|
clear() {
|
|
282
331
|
this.data.fill(CompactDistanceArray.INFINITY);
|
|
283
332
|
}
|
|
284
333
|
/**
|
|
285
|
-
|
|
286
|
-
|
|
334
|
+
* Get the size of the distance array.
|
|
335
|
+
* @returns The number of elements in the array
|
|
336
|
+
*/
|
|
287
337
|
size() {
|
|
288
338
|
return this._size;
|
|
289
339
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bit-packed.js","sourceRoot":"","sources":["../../../src/optimized/bit-packed.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bit-packed.js","sourceRoot":"","sources":["../../../src/optimized/bit-packed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAIpB;;;OAGG;IACH,YAAY,QAAiB;QANrB,iBAAY,GAAG,CAAC,CAAC;QAOrB,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACpC,IAAI,QAAQ,EAAE,CAAC;YACX,8BAA8B;YAC9B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,KAAa;QACb,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACvB,IAAI,CAAC,YAAY,EAAE,CAAC;QACxB,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAa;QAChB,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,YAAY,EAAE,CAAC;QACxB,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAa;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IA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odeId = NodeId> implements ReadonlyGraph<TNodeId> {
|
|
21
21
|
private data;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new CSRGraph from an adjacency list representation.
|
|
24
|
+
* @param adjacencyList - Map of node IDs to arrays of neighbor node IDs
|
|
25
|
+
* @param weights - Optional map of edge weights keyed by "source-target" strings
|
|
26
|
+
* @param buildReverse - Whether to build reverse edges for bottom-up BFS (default true)
|
|
27
|
+
*/
|
|
22
28
|
constructor(adjacencyList: Map<TNodeId, TNodeId[]>, weights?: Map<string, number>, buildReverse?: boolean);
|
|
23
29
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
* Build CSR structure from adjacency list.
|
|
31
|
+
* @param adjacencyList - Map of node IDs to arrays of neighbor node IDs
|
|
32
|
+
* @param weights - Optional map of edge weights keyed by "source-target" strings
|
|
33
|
+
* @param buildReverse - Whether to build reverse edges for bottom-up BFS
|
|
34
|
+
* @returns The constructed CSR graph data structure
|
|
35
|
+
*/
|
|
26
36
|
private buildCSR;
|
|
37
|
+
/**
|
|
38
|
+
* Get the total number of nodes in the graph.
|
|
39
|
+
* @returns The number of nodes
|
|
40
|
+
*/
|
|
27
41
|
nodeCount(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Get the total number of edges in the graph.
|
|
44
|
+
* @returns The number of edges
|
|
45
|
+
*/
|
|
28
46
|
edgeCount(): number;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a node exists in the graph.
|
|
49
|
+
* @param nodeId - The node ID to check
|
|
50
|
+
* @returns True if the node exists, false otherwise
|
|
51
|
+
*/
|
|
29
52
|
hasNode(nodeId: TNodeId): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Check if an edge exists between two nodes.
|
|
55
|
+
* @param source - The source node ID
|
|
56
|
+
* @param target - The target node ID
|
|
57
|
+
* @returns True if the edge exists, false otherwise
|
|
58
|
+
*/
|
|
30
59
|
hasEdge(source: TNodeId, target: TNodeId): boolean;
|
|
31
60
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
61
|
+
* Get neighbors of a node as node IDs.
|
|
62
|
+
* @param nodeId - The node ID to get neighbors for
|
|
63
|
+
* @returns An iterator over neighbor node IDs
|
|
64
|
+
*/
|
|
34
65
|
neighbors(nodeId: TNodeId): IterableIterator<TNodeId>;
|
|
35
66
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
67
|
+
* Get all nodes in the graph.
|
|
68
|
+
* @returns An iterator over all node IDs
|
|
69
|
+
*/
|
|
38
70
|
nodes(): IterableIterator<TNodeId>;
|
|
39
71
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
72
|
+
* Get neighbors as indices (internal use).
|
|
73
|
+
* @param nodeIndex - The internal index of the node
|
|
74
|
+
* @returns Array of neighbor indices
|
|
75
|
+
*/
|
|
42
76
|
getNeighborIndices(nodeIndex: number): number[];
|
|
77
|
+
/**
|
|
78
|
+
* Get the out-degree (number of outgoing edges) of a node.
|
|
79
|
+
* @param nodeId - The node ID to get the out-degree for
|
|
80
|
+
* @returns The number of outgoing edges from the node
|
|
81
|
+
*/
|
|
43
82
|
outDegree(nodeId: TNodeId): number;
|
|
44
83
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
* Get out-degree by index (internal use).
|
|
85
|
+
* @param nodeIndex - The internal index of the node
|
|
86
|
+
* @returns The number of outgoing edges from the node
|
|
87
|
+
*/
|
|
47
88
|
outDegreeByIndex(nodeIndex: number): number;
|
|
48
89
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
* Iterator support for neighbor indices.
|
|
91
|
+
* @param nodeIndex - The internal index of the node
|
|
92
|
+
* @yields The indices of neighboring nodes
|
|
93
|
+
*/
|
|
51
94
|
iterateNeighborIndices(nodeIndex: number): Generator<number>;
|
|
52
95
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
96
|
+
* Iterator support for incoming neighbor indices (for bottom-up BFS).
|
|
97
|
+
* @param nodeIndex - The internal index of the node
|
|
98
|
+
* @yields The indices of nodes with edges pointing to this node
|
|
99
|
+
*/
|
|
55
100
|
iterateIncomingNeighborIndices(nodeIndex: number): Generator<number>;
|
|
56
101
|
/**
|
|
57
|
-
|
|
58
|
-
|
|
102
|
+
* Convert node ID to internal index.
|
|
103
|
+
* @param nodeId - The node ID to convert
|
|
104
|
+
* @returns The internal index for the node
|
|
105
|
+
*/
|
|
59
106
|
nodeToIndex(nodeId: TNodeId): number;
|
|
60
107
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
108
|
+
* Convert internal index to node ID.
|
|
109
|
+
* @param index - The internal index to convert
|
|
110
|
+
* @returns The node ID for the given index
|
|
111
|
+
*/
|
|
63
112
|
indexToNodeId(index: number): TNodeId;
|
|
64
113
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
114
|
+
* Get edge weight between two nodes.
|
|
115
|
+
* @param source - The source node ID
|
|
116
|
+
* @param target - The target node ID
|
|
117
|
+
* @returns The edge weight, or undefined if the edge doesn't exist or has no weight
|
|
118
|
+
*/
|
|
67
119
|
getEdgeWeight(source: TNodeId, target: TNodeId): number | undefined;
|
|
68
120
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
121
|
+
* Binary search for target in sorted array.
|
|
122
|
+
* @param arr - The typed array to search in
|
|
123
|
+
* @param target - The value to search for
|
|
124
|
+
* @param start - The starting index (inclusive)
|
|
125
|
+
* @param end - The ending index (exclusive)
|
|
126
|
+
* @returns The index of the target, or -1 if not found
|
|
127
|
+
*/
|
|
71
128
|
private binarySearch;
|
|
72
129
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
130
|
+
* Create CSR graph from standard Graph interface.
|
|
131
|
+
* @param graph - The graph object to convert, must implement nodes, neighbors, hasNode, and optionally getEdge
|
|
132
|
+
* @param graph.nodes - Function that returns an iterator over node objects with id property
|
|
133
|
+
* @param graph.neighbors - Function that returns an iterator over neighbor node IDs
|
|
134
|
+
* @param graph.hasNode - Function that checks if a node exists in the graph
|
|
135
|
+
* @param graph.getEdge - Optional function that returns edge data including weight
|
|
136
|
+
* @returns A new CSRGraph instance
|
|
137
|
+
*/
|
|
75
138
|
static fromGraph<TNodeId = NodeId>(graph: {
|
|
76
139
|
nodes(): IterableIterator<{
|
|
77
140
|
id: TNodeId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csr-graph.d.ts","sourceRoot":"","sources":["../../../src/optimized/csr-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"csr-graph.d.ts","sourceRoot":"","sources":["../../../src/optimized/csr-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,OAAO,GAAG,MAAM;IAC3C,SAAS,IAAI,MAAM,CAAC;IACpB,SAAS,IAAI,MAAM,CAAC;IACpB,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IAClC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IACnD,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtD,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACnC,KAAK,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;CACtC;AAwBD;;;;;GAKG;AACH,qBAAa,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAE,YAAW,aAAa,CAAC,OAAO,CAAC;IACrE,OAAO,CAAC,IAAI,CAAwB;IAEpC;;;;;OAKG;gBACS,aAAa,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,UAAO;IAItG;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ;IA8IhB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,SAAS,I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