twokeys 2.0.1 → 2.2.0

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/dist/index.d.ts CHANGED
@@ -1,3 +1,472 @@
1
+ type GraphNodeInput<NodeId extends string = string> = NodeId | {
2
+ id: NodeId;
3
+ };
4
+ interface GraphEdge<NodeId extends string = string> {
5
+ from: NodeId;
6
+ to: NodeId;
7
+ weight?: number;
8
+ }
9
+ interface GraphBuildOptions {
10
+ directed?: boolean;
11
+ }
12
+ interface GraphNeighbor<NodeId extends string = string> {
13
+ id: NodeId;
14
+ weight: number;
15
+ }
16
+ interface GraphAdjacency<NodeId extends string = string> {
17
+ nodes: NodeId[];
18
+ neighborsByNode: Map<NodeId, GraphNeighbor<NodeId>[]>;
19
+ incomingByNode: Map<NodeId, GraphNeighbor<NodeId>[]>;
20
+ edges: Array<Required<GraphEdge<NodeId>>>;
21
+ directed: boolean;
22
+ }
23
+ type GraphAlgorithmErrorCode = 'NEGATIVE_WEIGHT' | 'NEGATIVE_CYCLE' | 'INVALID_ARGUMENT';
24
+ declare class GraphAlgorithmError extends Error {
25
+ readonly code: GraphAlgorithmErrorCode;
26
+ constructor(code: GraphAlgorithmErrorCode, message: string);
27
+ }
28
+ interface TopologicalSortOptions<NodeId extends string = string> {
29
+ tieBreaker?: (left: NodeId, right: NodeId) => number;
30
+ priority?: (nodeId: NodeId) => number;
31
+ priorityByNode?: Map<NodeId, number> | Partial<Record<NodeId, number>>;
32
+ }
33
+ interface TopologicalSortResult<NodeId extends string = string> {
34
+ order: NodeId[];
35
+ cycleNodes: NodeId[];
36
+ isDag: boolean;
37
+ }
38
+ interface StronglyConnectedComponentsOptions extends GraphBuildOptions {
39
+ }
40
+ interface StronglyConnectedComponentsResult<NodeId extends string = string> {
41
+ components: NodeId[][];
42
+ componentByNode: Map<NodeId, number>;
43
+ }
44
+ interface WeaklyConnectedComponentsResult<NodeId extends string = string> {
45
+ components: NodeId[][];
46
+ componentByNode: Map<NodeId, number>;
47
+ }
48
+ interface DegreeCentralityRecord {
49
+ inDegree: number;
50
+ outDegree: number;
51
+ degree: number;
52
+ normalized: number;
53
+ }
54
+ type ClosenessCentralityMode = 'classic' | 'harmonic';
55
+ interface ClosenessCentralityRecord {
56
+ reachableCount: number;
57
+ distanceSum: number;
58
+ score: number;
59
+ normalized: number;
60
+ mode: ClosenessCentralityMode;
61
+ negativeCycle: boolean;
62
+ }
63
+ interface BetweennessCentralityRecord {
64
+ raw: number;
65
+ normalized: number;
66
+ }
67
+ interface PageRankOptions extends GraphBuildOptions {
68
+ dampingFactor?: number;
69
+ tolerance?: number;
70
+ maxIterations?: number;
71
+ }
72
+ interface PageRankRecord {
73
+ score: number;
74
+ normalized: number;
75
+ rank: number;
76
+ }
77
+ interface PageRankResult<NodeId extends string = string> {
78
+ byNode: Map<NodeId, PageRankRecord>;
79
+ order: NodeId[];
80
+ iterations: number;
81
+ converged: boolean;
82
+ dampingFactor: number;
83
+ }
84
+ interface MinimumSpanningTreeOptions<NodeId extends string = string> {
85
+ tieBreaker?: (left: NodeId, right: NodeId) => number;
86
+ }
87
+ interface MinimumSpanningTreeResult<NodeId extends string = string> {
88
+ edges: Array<Required<GraphEdge<NodeId>>>;
89
+ totalWeight: number;
90
+ componentCount: number;
91
+ spanning: boolean;
92
+ }
93
+ interface ArticulationBridgeResult<NodeId extends string = string> {
94
+ articulationPoints: NodeId[];
95
+ bridges: Array<Required<GraphEdge<NodeId>>>;
96
+ }
97
+ interface GraphAnalysisResult<NodeId extends string = string> {
98
+ degree: Map<NodeId, DegreeCentralityRecord>;
99
+ closeness: Map<NodeId, ClosenessCentralityRecord>;
100
+ betweenness: Map<NodeId, BetweennessCentralityRecord>;
101
+ pageRank: Map<NodeId, PageRankRecord>;
102
+ stronglyConnectedComponents: NodeId[][];
103
+ weaklyConnectedComponents: NodeId[][];
104
+ articulationPoints: NodeId[];
105
+ bridges: Array<Required<GraphEdge<NodeId>>>;
106
+ }
107
+ interface GraphAnalysisOptions extends GraphBuildOptions {
108
+ closenessMode?: ClosenessCentralityMode;
109
+ shortestPathAlgorithm?: ShortestPathAlgorithm;
110
+ pageRankOptions?: Omit<PageRankOptions, 'directed'>;
111
+ }
112
+ type ShortestPathAlgorithm = 'auto' | 'dijkstra' | 'bellman-ford';
113
+ interface ShortestPathOptions extends GraphBuildOptions {
114
+ algorithm?: ShortestPathAlgorithm;
115
+ failOnNegativeCycle?: boolean;
116
+ }
117
+ interface ShortestPathResult<NodeId extends string = string> {
118
+ source: NodeId;
119
+ target: NodeId;
120
+ path: NodeId[];
121
+ distance: number;
122
+ reachable: boolean;
123
+ explored: number;
124
+ algorithm: ShortestPathAlgorithm;
125
+ hasNegativeWeights: boolean;
126
+ negativeCycle: boolean;
127
+ }
128
+ interface LabelPropagationOptions<NodeId extends string = string> extends GraphBuildOptions {
129
+ maxIterations?: number;
130
+ tieBreaker?: (left: NodeId, right: NodeId) => number;
131
+ }
132
+ interface LouvainOptions<NodeId extends string = string> extends GraphBuildOptions {
133
+ maxPasses?: number;
134
+ tolerance?: number;
135
+ tieBreaker?: (left: NodeId, right: NodeId) => number;
136
+ }
137
+ interface CommunityDetectionResult<NodeId extends string = string> {
138
+ communities: NodeId[][];
139
+ communityByNode: Map<NodeId, number>;
140
+ iterations: number;
141
+ converged: boolean;
142
+ algorithm: 'label-propagation' | 'louvain';
143
+ modularity: number;
144
+ }
145
+ type SimilarityMetric = 'common-neighbors' | 'jaccard' | 'cosine' | 'overlap' | 'adamic-adar' | 'resource-allocation' | 'preferential-attachment';
146
+ interface SimilarityOptions extends GraphBuildOptions {
147
+ metric?: SimilarityMetric;
148
+ minScore?: number;
149
+ }
150
+ interface NodeSimilarityRecord<NodeId extends string = string> {
151
+ left: NodeId;
152
+ right: NodeId;
153
+ score: number;
154
+ metric: SimilarityMetric;
155
+ rank: number;
156
+ }
157
+ interface NodeSimilarityResult<NodeId extends string = string> {
158
+ metric: SimilarityMetric;
159
+ pairs: NodeSimilarityRecord<NodeId>[];
160
+ }
161
+ interface KNearestNeighborsOptions extends GraphBuildOptions {
162
+ metric?: SimilarityMetric;
163
+ k?: number;
164
+ minScore?: number;
165
+ }
166
+ interface KNearestNeighbor<NodeId extends string = string> {
167
+ nodeId: NodeId;
168
+ score: number;
169
+ }
170
+ interface KNearestNeighborsResult<NodeId extends string = string> {
171
+ metric: SimilarityMetric;
172
+ k: number;
173
+ neighborsByNode: Map<NodeId, KNearestNeighbor<NodeId>[]>;
174
+ }
175
+ interface LinkPredictionOptions<NodeId extends string = string> extends GraphBuildOptions {
176
+ metric?: SimilarityMetric;
177
+ limit?: number;
178
+ minScore?: number;
179
+ allowExistingEdges?: boolean;
180
+ sourceFilter?: NodeId[];
181
+ targetFilter?: NodeId[];
182
+ }
183
+ interface LinkPredictionRecord<NodeId extends string = string> {
184
+ from: NodeId;
185
+ to: NodeId;
186
+ score: number;
187
+ metric: SimilarityMetric;
188
+ rank: number;
189
+ }
190
+ interface LinkPredictionResult<NodeId extends string = string> {
191
+ metric: SimilarityMetric;
192
+ predictions: LinkPredictionRecord<NodeId>[];
193
+ }
194
+ interface AStarOptions<NodeId extends string = string> extends GraphBuildOptions {
195
+ heuristic?: (nodeId: NodeId, targetId: NodeId) => number;
196
+ }
197
+ interface AStarResult<NodeId extends string = string> {
198
+ source: NodeId;
199
+ target: NodeId;
200
+ path: NodeId[];
201
+ distance: number;
202
+ reachable: boolean;
203
+ explored: number;
204
+ estimatedDistance: number;
205
+ }
206
+ interface PathRecord<NodeId extends string = string> {
207
+ path: NodeId[];
208
+ distance: number;
209
+ }
210
+ interface YenKShortestPathsOptions extends GraphBuildOptions {
211
+ k?: number;
212
+ shortestPathAlgorithm?: ShortestPathAlgorithm;
213
+ }
214
+ interface YenKShortestPathsResult<NodeId extends string = string> {
215
+ source: NodeId;
216
+ target: NodeId;
217
+ paths: PathRecord<NodeId>[];
218
+ complete: boolean;
219
+ }
220
+ interface AllPairsShortestPathsOptions extends GraphBuildOptions {
221
+ algorithm?: ShortestPathAlgorithm;
222
+ failOnNegativeCycle?: boolean;
223
+ }
224
+ interface AllPairsShortestPathsResult<NodeId extends string = string> {
225
+ nodes: NodeId[];
226
+ distanceBySource: Map<NodeId, Map<NodeId, number>>;
227
+ previousBySource: Map<NodeId, Map<NodeId, NodeId>>;
228
+ algorithm: ShortestPathAlgorithm;
229
+ hasNegativeWeights: boolean;
230
+ negativeCycle: boolean;
231
+ }
232
+ interface FlowEdge<NodeId extends string = string> {
233
+ from: NodeId;
234
+ to: NodeId;
235
+ capacity: number;
236
+ cost?: number;
237
+ }
238
+ interface FlowEdgeResult<NodeId extends string = string> {
239
+ from: NodeId;
240
+ to: NodeId;
241
+ flow: number;
242
+ capacity: number;
243
+ }
244
+ interface MaximumFlowOptions extends GraphBuildOptions {
245
+ }
246
+ interface MaximumFlowResult<NodeId extends string = string> {
247
+ source: NodeId;
248
+ sink: NodeId;
249
+ maxFlow: number;
250
+ augmentations: number;
251
+ flowByEdge: FlowEdgeResult<NodeId>[];
252
+ sourcePartition: NodeId[];
253
+ sinkPartition: NodeId[];
254
+ cutEdges: Array<Required<GraphEdge<NodeId>>>;
255
+ }
256
+ interface MinCostMaxFlowOptions extends GraphBuildOptions {
257
+ targetFlow?: number;
258
+ }
259
+ interface MinCostFlowEdgeResult<NodeId extends string = string> extends FlowEdgeResult<NodeId> {
260
+ cost: number;
261
+ }
262
+ interface MinCostMaxFlowResult<NodeId extends string = string> {
263
+ source: NodeId;
264
+ sink: NodeId;
265
+ flow: number;
266
+ cost: number;
267
+ complete: boolean;
268
+ augmentations: number;
269
+ flowByEdge: MinCostFlowEdgeResult<NodeId>[];
270
+ }
271
+ type KMeansNormalization = 'none' | 'zscore' | 'minmax';
272
+ interface KMeansOptions {
273
+ maxIterations?: number;
274
+ tolerance?: number;
275
+ seed?: number;
276
+ nInit?: number;
277
+ normalization?: KMeansNormalization;
278
+ useKMeansPlusPlus?: boolean;
279
+ }
280
+ interface KMeansCluster {
281
+ centroid: number[];
282
+ indices: number[];
283
+ }
284
+ interface KMeansResult {
285
+ assignments: number[];
286
+ clusters: KMeansCluster[];
287
+ iterations: number;
288
+ inertia: number;
289
+ converged: boolean;
290
+ silhouette: number | null;
291
+ selectedSeed: number;
292
+ }
293
+ interface KMeansAutoOptions extends KMeansOptions {
294
+ kMin?: number;
295
+ kMax?: number;
296
+ }
297
+ interface KMeansAutoCandidate {
298
+ k: number;
299
+ silhouette: number | null;
300
+ inertia: number;
301
+ }
302
+ interface KMeansAutoResult extends KMeansResult {
303
+ selectedK: number;
304
+ candidates: KMeansAutoCandidate[];
305
+ }
306
+ interface TravelingSalesmanOptions<NodeId extends string = string> extends GraphBuildOptions {
307
+ start?: NodeId;
308
+ returnToStart?: boolean;
309
+ twoOptPasses?: number;
310
+ multiStartCount?: number;
311
+ startCandidates?: NodeId[];
312
+ seed?: number;
313
+ shortestPathAlgorithm?: ShortestPathAlgorithm;
314
+ }
315
+ interface TravelingSalesmanSegment<NodeId extends string = string> {
316
+ from: NodeId;
317
+ to: NodeId;
318
+ distance: number;
319
+ path: NodeId[];
320
+ }
321
+ interface TravelingSalesmanResult<NodeId extends string = string> {
322
+ order: NodeId[];
323
+ distance: number;
324
+ segments: TravelingSalesmanSegment<NodeId>[];
325
+ visitedCount: number;
326
+ complete: boolean;
327
+ unreachableNodes: NodeId[];
328
+ lowerBound: number;
329
+ optimalityGap: number | null;
330
+ }
331
+ declare function buildGraphAdjacency<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: GraphBuildOptions): GraphAdjacency<NodeId>;
332
+ declare function stronglyConnectedComponents<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: StronglyConnectedComponentsOptions): StronglyConnectedComponentsResult<NodeId>;
333
+ declare function weaklyConnectedComponents<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[]): WeaklyConnectedComponentsResult<NodeId>;
334
+ declare function topologicalSort<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: TopologicalSortOptions<NodeId>): TopologicalSortResult<NodeId>;
335
+ declare function degreeCentrality<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: GraphBuildOptions): Map<NodeId, DegreeCentralityRecord>;
336
+ interface ClosenessCentralityOptions extends GraphBuildOptions {
337
+ mode?: ClosenessCentralityMode;
338
+ shortestPathAlgorithm?: ShortestPathAlgorithm;
339
+ }
340
+ declare function closenessCentrality<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: ClosenessCentralityOptions): Map<NodeId, ClosenessCentralityRecord>;
341
+ declare function betweennessCentrality<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: GraphBuildOptions): Map<NodeId, BetweennessCentralityRecord>;
342
+ declare function pageRank<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: PageRankOptions): PageRankResult<NodeId>;
343
+ declare function minimumSpanningTree<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: MinimumSpanningTreeOptions<NodeId>): MinimumSpanningTreeResult<NodeId>;
344
+ declare function articulationPointsAndBridges<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[]): ArticulationBridgeResult<NodeId>;
345
+ declare function analyzeGraph<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: GraphAnalysisOptions): GraphAnalysisResult<NodeId>;
346
+ declare function shortestPath<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], source: NodeId, target: NodeId, options?: ShortestPathOptions): ShortestPathResult<NodeId>;
347
+ declare function labelPropagationCommunities<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: LabelPropagationOptions<NodeId>): CommunityDetectionResult<NodeId>;
348
+ declare function louvainCommunities<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: LouvainOptions<NodeId>): CommunityDetectionResult<NodeId>;
349
+ declare function nodeSimilarity<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: SimilarityOptions): NodeSimilarityResult<NodeId>;
350
+ declare function kNearestNeighbors<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: KNearestNeighborsOptions): KNearestNeighborsResult<NodeId>;
351
+ declare function predictLinks<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: LinkPredictionOptions<NodeId>): LinkPredictionResult<NodeId>;
352
+ declare function linkPrediction<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: LinkPredictionOptions<NodeId>): LinkPredictionResult<NodeId>;
353
+ declare function aStarShortestPath<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], source: NodeId, target: NodeId, options?: AStarOptions<NodeId>): AStarResult<NodeId>;
354
+ declare function allPairsShortestPaths<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: AllPairsShortestPathsOptions): AllPairsShortestPathsResult<NodeId>;
355
+ declare function yenKShortestPaths<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], source: NodeId, target: NodeId, options?: YenKShortestPathsOptions): YenKShortestPathsResult<NodeId>;
356
+ declare function maximumFlow<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], source: NodeId, sink: NodeId, options?: MaximumFlowOptions): MaximumFlowResult<NodeId>;
357
+ declare function minCostMaxFlow<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: FlowEdge<NodeId>[], source: NodeId, sink: NodeId, options?: MinCostMaxFlowOptions): MinCostMaxFlowResult<NodeId>;
358
+ declare function kMeansClustering(points: number[][], k: number, options?: KMeansOptions): KMeansResult;
359
+ declare function kMeansAuto(points: number[][], options?: KMeansAutoOptions): KMeansAutoResult;
360
+ declare function travelingSalesmanApprox<NodeId extends string>(nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: TravelingSalesmanOptions<NodeId>): TravelingSalesmanResult<NodeId>;
361
+
362
+ interface GdsProjectOptions {
363
+ directed?: boolean;
364
+ replace?: boolean;
365
+ metadata?: Record<string, unknown>;
366
+ }
367
+ interface GdsGraphProjection<NodeId extends string = string> {
368
+ name: string;
369
+ nodes: NodeId[];
370
+ edges: Array<Required<GraphEdge<NodeId>>>;
371
+ directed: boolean;
372
+ createdAt: number;
373
+ metadata: Record<string, unknown>;
374
+ }
375
+ interface GdsCatalogEntry {
376
+ name: string;
377
+ nodeCount: number;
378
+ edgeCount: number;
379
+ directed: boolean;
380
+ createdAt: number;
381
+ metadata: Record<string, unknown>;
382
+ }
383
+ type GdsPipelineStep<NodeId extends string = string> = {
384
+ id: string;
385
+ kind: 'page-rank';
386
+ options?: PageRankOptions;
387
+ } | {
388
+ id: string;
389
+ kind: 'louvain';
390
+ options?: LouvainOptions<NodeId>;
391
+ } | {
392
+ id: string;
393
+ kind: 'label-propagation';
394
+ options?: LabelPropagationOptions<NodeId>;
395
+ } | {
396
+ id: string;
397
+ kind: 'similarity';
398
+ options?: SimilarityOptions;
399
+ } | {
400
+ id: string;
401
+ kind: 'knn';
402
+ options?: KNearestNeighborsOptions;
403
+ } | {
404
+ id: string;
405
+ kind: 'link-prediction';
406
+ options?: LinkPredictionOptions<NodeId>;
407
+ } | {
408
+ id: string;
409
+ kind: 'shortest-path';
410
+ source: NodeId;
411
+ target: NodeId;
412
+ options?: ShortestPathOptions;
413
+ } | {
414
+ id: string;
415
+ kind: 'a-star';
416
+ source: NodeId;
417
+ target: NodeId;
418
+ options?: AStarOptions<NodeId>;
419
+ } | {
420
+ id: string;
421
+ kind: 'yen-k-shortest-paths';
422
+ source: NodeId;
423
+ target: NodeId;
424
+ options?: YenKShortestPathsOptions;
425
+ } | {
426
+ id: string;
427
+ kind: 'max-flow';
428
+ source: NodeId;
429
+ sink: NodeId;
430
+ options?: MaximumFlowOptions;
431
+ } | {
432
+ id: string;
433
+ kind: 'min-cost-max-flow';
434
+ source: NodeId;
435
+ sink: NodeId;
436
+ edges?: FlowEdge<NodeId>[] | null;
437
+ options?: MinCostMaxFlowOptions;
438
+ } | {
439
+ id: string;
440
+ kind: 'all-pairs-shortest-paths';
441
+ options?: AllPairsShortestPathsOptions;
442
+ };
443
+ type GdsPipelineOutput<NodeId extends string = string> = PageRankResult<NodeId> | CommunityDetectionResult<NodeId> | NodeSimilarityResult<NodeId> | KNearestNeighborsResult<NodeId> | LinkPredictionResult<NodeId> | ShortestPathResult<NodeId> | AStarResult<NodeId> | YenKShortestPathsResult<NodeId> | MaximumFlowResult<NodeId> | MinCostMaxFlowResult<NodeId> | AllPairsShortestPathsResult<NodeId>;
444
+ declare class GraphCatalog<NodeId extends string = string> {
445
+ private projections;
446
+ project(name: string, nodes: GraphNodeInput<NodeId>[], edges: GraphEdge<NodeId>[], options?: GdsProjectOptions): GdsGraphProjection<NodeId>;
447
+ drop(name: string): boolean;
448
+ clear(): void;
449
+ exists(name: string): boolean;
450
+ get(name: string): GdsGraphProjection<NodeId> | null;
451
+ list(): GdsCatalogEntry[];
452
+ pageRank(name: string, options?: PageRankOptions): PageRankResult<NodeId>;
453
+ louvain(name: string, options?: LouvainOptions<NodeId>): CommunityDetectionResult<NodeId>;
454
+ labelPropagation(name: string, options?: LabelPropagationOptions<NodeId>): CommunityDetectionResult<NodeId>;
455
+ similarity(name: string, options?: SimilarityOptions): NodeSimilarityResult<NodeId>;
456
+ knn(name: string, options?: KNearestNeighborsOptions): KNearestNeighborsResult<NodeId>;
457
+ linkPrediction(name: string, options?: LinkPredictionOptions<NodeId>): LinkPredictionResult<NodeId>;
458
+ shortestPath(name: string, source: NodeId, target: NodeId, options?: ShortestPathOptions): ShortestPathResult<NodeId>;
459
+ aStar(name: string, source: NodeId, target: NodeId, options?: AStarOptions<NodeId>): AStarResult<NodeId>;
460
+ yen(name: string, source: NodeId, target: NodeId, options?: YenKShortestPathsOptions): YenKShortestPathsResult<NodeId>;
461
+ allPairs(name: string, options?: AllPairsShortestPathsOptions): AllPairsShortestPathsResult<NodeId>;
462
+ maxFlow(name: string, source: NodeId, sink: NodeId, options?: MaximumFlowOptions): MaximumFlowResult<NodeId>;
463
+ minCostMaxFlow(name: string, source: NodeId, sink: NodeId, edges?: FlowEdge<NodeId>[] | null, options?: MinCostMaxFlowOptions): MinCostMaxFlowResult<NodeId>;
464
+ runPipeline(name: string, steps: GdsPipelineStep<NodeId>[]): Map<string, GdsPipelineOutput<NodeId>>;
465
+ private requireProjection;
466
+ }
467
+ declare function createGraphCatalog<NodeId extends string = string>(): GraphCatalog<NodeId>;
468
+ declare const gds: GraphCatalog<string>;
469
+
1
470
  /**
2
471
  * Twokeys - A small data exploration and manipulation library
3
472
  * Named after John Tukey, pioneer of exploratory data analysis (EDA)
@@ -190,4 +659,4 @@ declare class Twokeys {
190
659
  static randomPoints: typeof randomPoints;
191
660
  }
192
661
 
193
- export { type BinnedResult, type MedianResult, type ModeResult, Points, type PointsDescription, type PointsOptions, type RankInfo, type RankedResult, Series, type SeriesDescription, type SeriesOptions, Twokeys, Twokeys as default };
662
+ export { type AStarOptions, type AStarResult, type AllPairsShortestPathsOptions, type AllPairsShortestPathsResult, type ArticulationBridgeResult, type BetweennessCentralityRecord, type BinnedResult, type ClosenessCentralityMode, type ClosenessCentralityOptions, type ClosenessCentralityRecord, type CommunityDetectionResult, type DegreeCentralityRecord, type FlowEdge, type FlowEdgeResult, type GdsCatalogEntry, type GdsGraphProjection, type GdsPipelineOutput, type GdsPipelineStep, type GdsProjectOptions, type GraphAdjacency, GraphAlgorithmError, type GraphAlgorithmErrorCode, type GraphAnalysisOptions, type GraphAnalysisResult, type GraphBuildOptions, GraphCatalog, type GraphEdge, type GraphNeighbor, type GraphNodeInput, type KMeansAutoCandidate, type KMeansAutoOptions, type KMeansAutoResult, type KMeansCluster, type KMeansNormalization, type KMeansOptions, type KMeansResult, type KNearestNeighbor, type KNearestNeighborsOptions, type KNearestNeighborsResult, type LabelPropagationOptions, type LinkPredictionOptions, type LinkPredictionRecord, type LinkPredictionResult, type LouvainOptions, type MaximumFlowOptions, type MaximumFlowResult, type MedianResult, type MinCostFlowEdgeResult, type MinCostMaxFlowOptions, type MinCostMaxFlowResult, type MinimumSpanningTreeOptions, type MinimumSpanningTreeResult, type ModeResult, type NodeSimilarityRecord, type NodeSimilarityResult, type PageRankOptions, type PageRankRecord, type PageRankResult, type PathRecord, Points, type PointsDescription, type PointsOptions, type RankInfo, type RankedResult, Series, type SeriesDescription, type SeriesOptions, type ShortestPathAlgorithm, type ShortestPathOptions, type ShortestPathResult, type SimilarityMetric, type SimilarityOptions, type StronglyConnectedComponentsOptions, type StronglyConnectedComponentsResult, type TopologicalSortOptions, type TopologicalSortResult, type TravelingSalesmanOptions, type TravelingSalesmanResult, type TravelingSalesmanSegment, Twokeys, type WeaklyConnectedComponentsResult, type YenKShortestPathsOptions, type YenKShortestPathsResult, aStarShortestPath, allPairsShortestPaths, analyzeGraph, articulationPointsAndBridges, betweennessCentrality, buildGraphAdjacency, closenessCentrality, createGraphCatalog, Twokeys as default, degreeCentrality, gds, kMeansAuto, kMeansClustering, kNearestNeighbors, labelPropagationCommunities, linkPrediction, louvainCommunities, maximumFlow, minCostMaxFlow, minimumSpanningTree, nodeSimilarity, pageRank, predictLinks, shortestPath, stronglyConnectedComponents, topologicalSort, travelingSalesmanApprox, weaklyConnectedComponents, yenKShortestPaths };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function R(b=100){return Math.floor(Math.random()*b)}function E(b=1e3,t=100){let n=[];for(let e=0;e<b;e++)n.push(R(t));return n}function _(b=2,t=100){let n=[];for(let e=0;e<b;e++)n.push(Math.floor(Math.random()*(t/10)%t));return n}function f(b=1e3,t=2,n=100){let e=[];for(let r=0;r<b;r++)e.push(_(t,n));return e}var g=class{data;constructor(t={}){this.data={original:t.data??E()};}sorted(){return this.data.sorted||(this.data.sorted=this.getSorted(this.data.original)),this.data.sorted}getSorted(t){return [...t].sort((n,e)=>n>e?1:n===e?0:-1)}median(){return this.sorted(),this.data.median===void 0&&(this.data.median=this.getMedian(this.data.sorted)),this.data.medianDepth===void 0&&(this.data.medianDepth=this.getMedianDepth(this.data.sorted)),{datum:this.data.median,depth:this.data.medianDepth}}getMedianDepth(t,n=0){return t.length?n+(t.length+1)/2:NaN}getMedian(t){let n=t.length;if(!n)return NaN;if(n===1)return t[0];let e=Math.floor(n/2);return n%2===0?(t[e-1]+t[e])/2:t[e]}mean(){return this.data.mean===void 0&&(this.data.mean=this.getMean(this.data.original)),this.data.mean}getMean(t){if(!t.length)return NaN;let n=0;for(let e of t)n+=e;return n/t.length}mode(){return this.data.mode||(this.sorted(),this.data.mode=this.getMode(this.data.sorted)),this.data.mode}getMode(t){if(!t.length)return {count:0,data:[]};let n={},e=0;for(let i of t)n[i]=(n[i]||0)+1,n[i]>e&&(e=n[i]);let r=[];for(let[i,s]of Object.entries(n))s===e&&r.push(Number(i));return {count:e,data:r.sort((i,s)=>i-s)}}extremes(){return this.data.extremes||(this.sorted(),this.data.extremes=this.getExtremes(this.data.sorted)),this.data.extremes}getExtremes(t){return t.length?[t[0],t[t.length-1]]:[]}counts(){return this.data.counts||(this.sorted(),this.data.counts=this.getCounts(this.data.sorted)),this.data.counts}getCounts(t){let n=new Map;for(let r of t)n.set(r,(n.get(r)||0)+1);let e=[];for(let[r,i]of n)e.push([r,i]);return e.sort((r,i)=>r[0]-i[0])}hinges(){return this.data.hinges||(this.sorted(),this.data.hinges=this.getHinges(this.data.sorted)),this.data.hinges}getHinges(t,n=2,e=[]){let r=[...t],i=r.length,s=n;if(s%2!==0&&s++,i<=s||s<=0)return e;let m=Math.floor(i/s),h=Math.floor(i/m)-1;for(let a=0;a<=h;a++){let o=r.slice(a*m,a*m+m);e.push({datum:this.getMedian(o),depth:this.getMedianDepth(o,a*m)});}return e}iqr(){return this.data.iqr===void 0&&(this.hinges(),this.data.iqr=this.getIQR(this.data.hinges)),this.data.iqr}getIQR(t){let n=t[0]?.datum,e=t[1]?.datum;return n===void 0||e===void 0?NaN:Math.abs(n-e)}fences(){return this.data.fences||(this.median(),this.iqr(),this.data.fences=this.getFences()),this.data.fences}getFences(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=e*t;return [n-r,n+r]}outer(){return this.data.outer||(this.median(),this.iqr(),this.data.outer=this.getOuter()),this.data.outer}getOuter(t=1.5){let n=this.data.median,e=this.data.iqr;if(n===void 0||e===void 0||isNaN(e))return [];let r=2*e*t;return [n-r,n+r]}outside(){return this.data.outside||(this.outer(),this.data.outside=this.getOutside()),this.data.outside}getOutside(){let t=[],n=this.data.sorted,e=this.data.outer;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}inside(){return this.data.inside||(this.fences(),this.data.inside=this.getInside()),this.data.inside}getInside(){let t=[],n=this.data.sorted,e=this.data.fences;if(!e||e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)s<i&&s>r&&t.push(s);return t}outliers(){return this.data.outliers||(this.fences(),this.data.outliers=this.getOutliers()),this.data.outliers}getOutliers(){let t=[],n=this.data.sorted,e=this.data.fences;if(e.length===0)return [];let r=Math.min(...e),i=Math.max(...e);for(let s of n)(s>i||s<r)&&t.push(s);return t}ranked(){return this.data.ranked||(this.sorted(),this.data.ranked=this.getRanked(this.data.sorted)),this.data.ranked}getRanked(t,n=true){let e={},r={},i=t.length,s=[],m=NaN,h=[],a=()=>{m=NaN,h=[];};for(let d=0;d<t.length;d++){let u=t[d];if(!n)e[u]={rank:d+1,peers:0},r[u]={rank:i-d,peers:0};else {let c=d+1,l=d-1;u===t[l]?(!isNaN(m)&&h.length===0?(h.push(u),s.push(h),a()):(h.push(u),m=l),u!==t[c]&&(s.push(h),a())):u!==t[c]?h.length>0?(s.push(h),a()):s.push(u):h.push(u);}}let o=0;for(let d=0;d<s.length;d++){let u=s[d];if(typeof u=="number")r[u]={rank:d+1+o,peers:0},e[u]={rank:i-d-o,peers:0};else if(Array.isArray(u)){o+=u.length;let c=u[0];r[c]={rank:d+1+o,peers:u.length},e[c]={rank:i-d-o,peers:u.length};}else o+=1;}return {up:e,down:r,groups:{down:[...s],up:[...s].reverse()}}}adjacent(){return this.data.adjacent||(this.fences(),this.data.adjacent=this.getAdjacent(this.data.sorted,this.data.fences)),this.data.adjacent}getAdjacent(t,n){if(n.length===0)return [];let e=n[0],r=[],i=n[1],s=[];for(let m of t)m>e&&r.push(m),m<i&&s.push(m);return r.sort((m,h)=>m-h),s.sort((m,h)=>m-h),[r[0],s[s.length-1]]}binned(t=NaN){return this.data.binned||(this.sorted(),this.extremes(),this.data.binned=this.getBinned(this.data.sorted,t)),this.data.binned}getBinned(t,n=10,e=NaN,r=true){let i={},s=t.length,m=r?0:1;if(s===0)return {bins:0,width:NaN,binned:{}};let h=this.data.extremes,a=e;if(h&&isNaN(a)&&h.length===2){a=(h[1]-h[0])/(Math.log(t.length)/Math.LN2),a=Math.floor(a);let d=true;for(let u of t)if(u%1!==0){d=false;break}d&&(a=Math.floor(a));}let o=Math.floor(h[1]/a)+1;(!o||o<1)&&(o=1);for(let d of t){let u=Math.floor((d-m)/a);i[u]||(i[u]={from:u*a+m,to:(u+1)*a+m-1,data:[]}),i[u].data.push(d);}return {bins:o,width:a,binned:i}}logs(){return this.data.logs||(this.data.logs=this.getLogs(this.data.original)),this.data.logs}getLogs(t){return t.map(n=>Math.log(n))}roots(){return this.data.roots||(this.data.roots=this.getRoots(this.data.original)),this.data.roots}getRoots(t){return t.map(n=>Math.sqrt(n))}inverse(){return this.data.inverse||(this.data.inverse=this.getInverse(this.data.original)),this.data.inverse}getInverse(t){return t.map(n=>1/n)}hanning(){return this.data.hanning||(this.data.hanning=this.getSkipMeans(this.data.original)),this.data.hanning}getSkipMeans(t){let n=[];for(let e=0;e<t.length;e++)e!==0&&e!==t.length-1&&n.push((t[e]+t[e+1])/2);return n.unshift(t[0]),n.push(t[t.length-1]),n}smooth(){return this.data.smooth||(this.sorted(),this.data.smooth=this.getSmooth(this.data.original)),this.data.rough=this.getRough(this.data.original,this.data.smooth),this.data.smooth}getRough(t,n){let e=[];for(let r=0;r<t.length;r++)e.push(t[r]-n[r]);return e}getSmooth(t,n=3){let e=[...t];return e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothSplit(e,2),e=this.smoothMedian(e,n),e=this.smoothExtremes(e,-1),e=this.smoothMedian(e,n),e}smoothExtremes(t,n=1,e=0,r="both"){let i=t.length;if(i<=2)return [...t];let s=[...t];for(let m=e;m<n||n===-1;m++){let h=false;if(r==="both"||r==="head"){let a=s[0],o=s[1],d=s[2],u=o-2*(d-o),c=a<=o?o<=u?o:a<=u?u:a:a<=u?a:o<=u?u:o;s[0]!==c&&(s[0]=c,h=true);}if(r==="both"||r==="tail"){let a=s[i-3],o=s[i-2],d=s[i-1],u=o-2*(a-o),c=d<=o?o<=u?o:d<=u?u:d:d<=u?d:o<=u?u:o;s[i-1]!==c&&(s[i-1]=c,h=true);}if(n===-1&&!h)break}return s}smoothSplit(t,n=2,e=0){let r=[...t],i=t.length;for(let s=e;s<n||n===-1;s++){let m=false;for(let h=2;h<i-1;h++){let a=r[h],o=r[h-1],d=r[h-2],u=r[h+1];if(a===o&&(o>d&&a>u||o<d&&a<u)){let c=this.smoothExtremes(r.slice(0,h)),l=this.smoothExtremes(r.slice(h));r=c.concat(l),m=true;}}if(n===-1&&!m)return r}return r}smoothMedian(t,n=1,e=0){let r=t,i=t.length;if(i<=2)return [...t];for(let s=e;s<n||n===-1;s++){let m=new Array(i);m[0]=r[0],m[i-1]=r[i-1];let h=false;for(let a=1;a<i-1;a++){let o=r[a],d=Math.min(Math.max(r[a-1],o),r[a+1]);m[a]=d,d!==o&&(h=true);}if(n===-1&&!h)return r;r=m;}return r}jitter(t,n=1,e=NaN,r=1,i=NaN,s=0){let m=s+1,h=[...t];if(m<=n){let a=[];for(let o of h){let d=i;!d&&!isNaN(d)&&(d=(1+Math.floor(o/10))*(Math.random()>.5?1:-1));let u=o+Math.floor(Math.random()*r*d);!isNaN(e)&&u<e&&(u=e),a.push(u);}return this.jitter(a,n,e,r,i,m)}return h}trimean(){let t=this.median(),n=this.hinges();return n.length<2?t.datum:(n[0].datum+2*t.datum+n[1].datum)/4}letterValues(){this.sorted();let t=this.data.sorted.length;if(t<2)return [];let n=["M","F","E","D","C","B","A","Z","Y","X","W","V","U","T","S"],e=[],r=(t+1)/2,i=this.median().datum;e.push({letter:"M",depth:r,lower:i,upper:i,mid:i,spread:0});let s=r,m=1;for(;s>1&&m<n.length&&(s=Math.floor((Math.floor(s)+1)/2),!(s<1));){let h=Math.ceil(s)-1,a=t-Math.ceil(s);if(h<0||a>=t||h>=a)break;let o=this.data.sorted[h],d=this.data.sorted[a],u=(o+d)/2,c=d-o;e.push({letter:n[m],depth:s,lower:o,upper:d,mid:u,spread:c}),m++;}return e}rough(){return this.data.rough||this.smooth(),this.data.rough||[]}stemLeaf(t=1){this.sorted();let n=this.data.sorted;if(!n.length)return {stems:[],leaves:{},display:[]};let e=Math.pow(10,t),r=new Map;for(let a of n){let o=Math.floor(a/e),d=Math.abs(Math.round(a%e));r.has(o)||r.set(o,[]),r.get(o).push(d);}let i=Array.from(r.keys()).sort((a,o)=>a-o),s=[],m={},h=[];for(let a of i){let o=String(a);s.push(o);let d=r.get(a).sort((u,c)=>u-c).map(String);m[o]=d,h.push(`${o.padStart(4)} | ${d.join(" ")}`);}return {stems:s,leaves:m,display:h}}midSummaries(){return this.letterValues().map(({depth:n,mid:e,spread:r})=>({depth:n,mid:e,spread:r}))}describe(){return this.data.description={original:this.data.original,summary:{median:this.median(),mean:this.mean(),mode:this.mode(),hinges:this.hinges(),adjacent:this.adjacent(),outliers:this.outliers(),outer:this.outer(),outside:this.outside(),inside:this.inside(),extremes:this.extremes(),iqr:this.iqr(),fences:this.fences()},smooths:{smooth:this.smooth(),hanning:this.hanning()},transforms:{logs:this.logs(),roots:this.roots(),inverse:this.inverse()},counts:this.counts(),sorted:this.sorted(),ranked:this.ranked(),binned:this.binned()},this.data.description}},p=class{data;dimension;count;constructor(t={}){typeof t=="number"?(this.count=t,this.dimension=2,this.data={original:f(this.count,this.dimension)}):(this.dimension=t.dimensionality??2,this.count=t.count??100,this.data={original:t.data??f(this.count,this.dimension)});}describe(){return this.data.description={original:this.data.original},this.data.description}},M=class{smoothed=false;static DEFAULT_MAX_RANDOM_INTEGER=100;static DEFAULT_MIN_RANDOM_INTEGER=0;static DEFAULT_RANDOM_SERIES_COUNT=1e3;static DEFAULT_OUTLIER_MULTIPLE=1.5;static DEFAULT_JITTER_MULTIPLIER=1;static DEFAULT_SPLIT_PASSES=2;static DEFAULT_MAX_RANDOM_DIMENSIONALITY=2;static Series=g;static Points=p;static randomInteger=R;static randomSeries=E;static randomPoint=_;static randomPoints=f},A=M;export{p as Points,g as Series,M as Twokeys,A as default};//# sourceMappingURL=index.js.map
1
+ var E=class extends Error{code;constructor(n,t){super(t),this.name="GraphAlgorithmError",this.code=n;}},C=class{heap=[];get size(){return this.heap.length}push(n,t){this.heap.push({priority:t,value:n}),this.siftUp(this.heap.length-1);}pop(){if(this.heap.length===0)return;let n=this.heap[0],t=this.heap.pop();return this.heap.length>0&&t&&(this.heap[0]=t,this.siftDown(0)),n}siftUp(n){let t=n;for(;t>0;){let e=Math.floor((t-1)/2),o=this.heap[t],r=this.heap[e];if(!o||!r||r.priority<=o.priority)return;this.heap[e]=o,this.heap[t]=r,t=e;}}siftDown(n){let t=n;for(;;){let e=t*2+1,o=t*2+2,r=t,s=this.heap[r],c=this.heap[e],i=this.heap[o];s&&c&&c.priority<s.priority&&(r=e);let d=this.heap[r];if(d&&i&&i.priority<d.priority&&(r=o),r===t)return;let a=this.heap[t],h=this.heap[r];if(!a||!h)return;this.heap[t]=h,this.heap[r]=a,t=r;}}};function P(u,n){return u.localeCompare(n)}function V(u,n){return P(u,n)<=0?{from:u,to:n}:{from:n,to:u}}function F(u,n){let t=V(u,n);return `${t.from}\0${t.to}`}function Pe(u){return typeof u=="string"?u:u.id}var Y=class{parent=new Map;rank=new Map;constructor(n){for(let t of n)this.parent.set(t,t),this.rank.set(t,0);}find(n){let t=this.parent.get(n);if(!t||t===n)return n;let e=this.find(t);return this.parent.set(n,e),e}union(n,t){let e=this.find(n),o=this.find(t);if(e===o)return false;let r=this.rank.get(e)??0,s=this.rank.get(o)??0;return r<s?(this.parent.set(e,o),true):r>s?(this.parent.set(o,e),true):(this.parent.set(o,e),this.rank.set(e,r+1),true)}};function q(u,n){let t=new Set,e=[];for(let o of u){let r=Pe(o);t.has(r)||(t.add(r),e.push(r));}for(let o of n)t.has(o.from)||(t.add(o.from),e.push(o.from)),t.has(o.to)||(t.add(o.to),e.push(o.to));return e}function Ae(u){if(u===void 0)return 1;if(!Number.isFinite(u))throw new E("INVALID_ARGUMENT",`Graph edge weight must be finite, received ${u}`);return u}function ve(u){let n=new Map;for(let t of u)n.set(t,new Map);return n}function se(u,n,t,e){let o=u.get(n);if(!o)return;let r=o.get(t);(r===void 0||e<r)&&o.set(t,e);}function ke(u,n,t){let e=ve(u);for(let o of n){if(o.from===o.to)continue;let r=Ae(o.weight);!e.has(o.from)||!e.has(o.to)||(se(e,o.from,o.to,r),t||se(e,o.to,o.from,r));}return e}function Ge(u){let n=new Map;for(let[t,e]of u.entries()){let o=[];for(let[r,s]of e.entries())o.push({id:r,weight:s});n.set(t,o);}return n}function Te(u,n){let t=new Map;for(let e of u)t.set(e,[]);for(let[e,o]of n.entries())for(let r of o){let s=t.get(r.id);s&&s.push({id:e,weight:r.weight});}return t}function Oe(u){let n=[];for(let[t,e]of u.entries())for(let o of e)n.push({from:t,to:o.id,weight:o.weight});return n}function G(u){for(let n of u.edges)if(n.weight<0)return true;return false}function $(u,n,t){if(u===n)return [u];let e=[n],o=n;for(;o&&o!==u;){let r=t.get(o);if(!r)return [];e.push(r),o=r;}return e.reverse(),e[0]===u?e:[]}function ae(u){return u.reduce((n,t)=>n+t.weight,0)}function Ce(u){let n=new Map;for(let t of u.edges){let e=V(t.from,t.to),o=F(e.from,e.to),r=n.get(o);(!r||t.weight<r.weight-1e-12)&&n.set(o,{from:e.from,to:e.to,weight:t.weight});}return Array.from(n.values())}function Fe(u,n){let t=Ce(u),e=0;for(let i of t)e+=i.weight;if(!Number.isFinite(e)||e<=0)return 0;let o=new Map;for(let i of u.nodes)o.set(i,ae(u.neighborsByNode.get(i)??[]));let r=new Map,s=new Map;for(let i of u.nodes){let d=n.get(i);if(d===void 0)continue;let a=o.get(i)??0;r.set(d,(r.get(d)??0)+a);}for(let i of t){let d=n.get(i.from),a=n.get(i.to);d===void 0||a===void 0||d===a&&s.set(d,(s.get(d)??0)+i.weight);}let c=0;for(let[i,d]of r.entries()){let a=s.get(i)??0;c+=a/e-Math.pow(d/(2*e),2);}return c}function U(u,n,t,e,o){let r=new Map;for(let i of u.nodes){let d=n.get(i);if(d===void 0)continue;let a=r.get(d)??[];a.push(i),r.set(d,a);}let s=Array.from(r.values()).map(i=>[...i].sort(P));s.sort((i,d)=>P(i[0]??"",d[0]??""));let c=new Map;for(let i=0;i<s.length;i+=1)for(let d of s[i]??[])c.set(d,i);return {communities:s,communityByNode:c,iterations:t,converged:e,algorithm:o,modularity:Fe(u,c)}}function H(u){let n=new Map;for(let t of u.nodes)n.set(t,new Set);for(let[t,e]of u.neighborsByNode.entries()){let o=n.get(t);if(o)for(let r of e)o.add(r.id);}return n}function L(u,n,t,e){let o=t.get(u)??new Set,r=t.get(n)??new Set,s=o.size,c=r.size,i=s<=c?o:r,d=i===o?r:o,a=0,h=0,l=0;for(let N of i){if(!d.has(N))continue;a+=1;let b=t.get(N)?.size??0;b>1&&(h+=1/Math.log(b)),b>0&&(l+=1/b);}if(e==="common-neighbors")return a;if(e==="preferential-attachment")return s*c;if(e==="adamic-adar")return h;if(e==="resource-allocation")return l;if(e==="jaccard"){let N=s+c-a;return N>0?a/N:0}if(e==="cosine")return s>0&&c>0?a/Math.sqrt(s*c):0;let m=Math.min(s,c);return m>0?a/m:0}function Be(u,n){if(u.length<=1)return 0;let t=0;for(let e=1;e<u.length;e+=1){let o=u[e-1],r=u[e];if(!o||!r)return Number.POSITIVE_INFINITY;let s=n.neighborsByNode.get(o)?.find(c=>c.id===r)?.weight;if(s===void 0||!Number.isFinite(s))return Number.POSITIVE_INFINITY;t+=s;}return t}function _(u){return u.join("\0")}function De(u,n){if(n.length>u.length)return false;for(let t=0;t<n.length;t+=1)if(u[t]!==n[t])return false;return true}function ce(u,n){return u==="auto"?n?"bellman-ford":"dijkstra":u}function _e(u,n){if(G(u))throw new E("NEGATIVE_WEIGHT","Dijkstra cannot run on negative graph weights.");let t=new Map,e=new Map,o=new Set,r=new C;for(let s of u.nodes)t.set(s,Number.POSITIVE_INFINITY);for(t.set(n,0),r.push(n,0);r.size>0;){let s=r.pop();if(!s)break;let c=s.value;if(o.has(c))continue;o.add(c);let i=t.get(c);if(i===void 0||!Number.isFinite(i))continue;let d=u.neighborsByNode.get(c)??[];for(let a of d){let h=i+a.weight,l=t.get(a.id);(l===void 0||h<l-1e-12)&&(t.set(a.id,h),e.set(a.id,c),r.push(a.id,h));}}return {distanceByNode:t,previousByNode:e,explored:o.size,negativeCycleNodes:new Set}}function Le(u,n){let t=new Map,e=new Map;for(let d of u.nodes)t.set(d,Number.POSITIVE_INFINITY);t.set(n,0);let o=u.nodes.length;for(let d=0;d<o-1;d+=1){let a=false;for(let h of u.edges){let l=t.get(h.from);if(l===void 0||!Number.isFinite(l))continue;let m=l+h.weight,N=t.get(h.to);(N===void 0||m<N-1e-12)&&(t.set(h.to,m),e.set(h.to,h.from),a=true);}if(!a)break}let r=new Set,s=[];for(let d of u.edges){let a=t.get(d.from),h=t.get(d.to);a!==void 0&&Number.isFinite(a)&&h!==void 0&&a+d.weight<h-1e-12&&(r.has(d.to)||(r.add(d.to),s.push(d.to)),r.has(d.from)||(r.add(d.from),s.push(d.from)));}let c=0;for(;c<s.length;){let d=s[c];if(c+=1,!!d)for(let a of u.neighborsByNode.get(d)??[])r.has(a.id)||(r.add(a.id),s.push(a.id));}if(r.size>0)for(let d of r)t.set(d,Number.NEGATIVE_INFINITY),e.delete(d);let i=0;for(let d of u.nodes){let a=t.get(d);a!==void 0&&Number.isFinite(a)&&(i+=1);}return {distanceByNode:t,previousByNode:e,explored:i,negativeCycleNodes:r}}function z(u,n,t){let e=G(u),o=ce(t,e);return o==="dijkstra"?{algorithm:o,result:_e(u,n),hasNegativeWeights:e}:{algorithm:o,result:Le(u,n),hasNegativeWeights:e}}function ue(u){if(u===void 0||!Number.isFinite(u))return Math.random;let n=Math.floor(u)>>>0||1;return ()=>(n=n*1664525+1013904223>>>0,n/4294967296)}function O(u,n){let t=0;for(let e=0;e<u.length;e+=1){let o=(u[e]??0)-(n[e]??0);t+=o*o;}return t}function de(u,n){return Math.sqrt(O(u,n))}function je(u,n){let t=u[0]?.length??0;if(n==="none")return {normalize:i=>[...i],denormalize:i=>[...i]};let e=new Array(t).fill(0),o=new Array(t).fill(Number.POSITIVE_INFINITY),r=new Array(t).fill(Number.NEGATIVE_INFINITY);for(let i of u)for(let d=0;d<t;d+=1){let a=i[d]??0;e[d]=(e[d]??0)+a,o[d]=Math.min(o[d]??a,a),r[d]=Math.max(r[d]??a,a);}for(let i=0;i<t;i+=1)e[i]=(e[i]??0)/u.length;if(n==="minmax"){let i=r.map((d,a)=>{let h=o[a]??0;return d-h});return {normalize:d=>d.map((a,h)=>{let l=o[h]??0,m=i[h]??0;return Math.abs(m)<1e-12?0:(a-l)/m}),denormalize:d=>d.map((a,h)=>{let l=o[h]??0,m=i[h]??0;return a*m+l})}}let s=new Array(t).fill(0);for(let i of u)for(let d=0;d<t;d+=1){let a=(i[d]??0)-(e[d]??0);s[d]=(s[d]??0)+a*a;}let c=s.map(i=>Math.sqrt(i/u.length));return {normalize:i=>i.map((d,a)=>{let h=c[a]??0;return h<1e-12?0:(d-(e[a]??0))/h}),denormalize:i=>i.map((d,a)=>{let h=c[a]??0;return d*h+(e[a]??0)})}}function Ve(u,n,t,e){if(u.length===0)return [];if(!e){let c=[],i=new Set;for(;c.length<n;){let d=Math.floor(t()*u.length);i.has(d)||(i.add(d),c.push([...u[d]??u[0]??[]]));}return c}let o=[],r=new Set,s=Math.floor(t()*u.length);for(r.add(s),o.push([...u[s]??u[0]??[]]);o.length<n;){let c=new Array(u.length).fill(0),i=0;for(let l=0;l<u.length;l+=1){if(r.has(l))continue;let m=u[l];if(!m)continue;let N=Number.POSITIVE_INFINITY;for(let b of o)N=Math.min(N,O(m,b));c[l]=N,i+=N;}if(!Number.isFinite(i)||i<=0){for(let l=0;l<u.length;l+=1)if(!r.has(l)){r.add(l),o.push([...u[l]??u[0]??[]]);break}continue}let d=t()*i,a=0,h=-1;for(let l=0;l<u.length;l+=1)if(!r.has(l)&&(a+=c[l]??0,a>=d)){h=l;break}if(h<0){for(let l=0;l<u.length;l+=1)if(!r.has(l)){h=l;break}}if(h<0)break;r.add(h),o.push([...u[h]??u[0]??[]]);}return o}function qe(u,n,t,e,o,r){let s=u[0]?.length??0,c=Ve(u,n,t,r);if(c.length!==n)throw new E("INVALID_ARGUMENT","Unable to initialize centroids for k-means.");let i=new Array(u.length).fill(-1),d=0,a=false,h=Number.POSITIVE_INFINITY;for(;d<e;){d+=1;let l=false;h=0;for(let p=0;p<u.length;p+=1){let g=u[p];if(!g)continue;let f=0,I=Number.POSITIVE_INFINITY;for(let x=0;x<c.length;x+=1){let M=c[x];if(!M)continue;let w=O(g,M);w<I&&(I=w,f=x);}h+=I,i[p]!==f&&(i[p]=f,l=true);}let m=new Array(n),N=new Array(n).fill(0);for(let p=0;p<n;p+=1)m[p]=new Array(s).fill(0);for(let p=0;p<u.length;p+=1){let g=i[p];if(g<0)continue;let f=u[p],I=m[g];if(!(!f||!I)){N[g]=(N[g]??0)+1;for(let x=0;x<s;x+=1)I[x]=(I[x]??0)+(f[x]??0);}}for(let p=0;p<n;p+=1){let g=N[p]??0;if(g>0){let f=m[p];if(!f)continue;for(let I=0;I<s;I+=1)f[I]=(f[I]??0)/g;}else {let f=0,I=-1;for(let x=0;x<u.length;x+=1){let M=i[x],w=c[M],y=u[x];if(!w||!y)continue;let R=O(y,w);R>I&&(I=R,f=x);}m[p]=[...u[f]??u[0]??[]];}}let b=0;for(let p=0;p<n;p+=1){let g=c[p],f=m[p];!g||!f||(b=Math.max(b,Math.sqrt(O(g,f))));}if(c=m,!l||b<=o){a=true;break}}return {assignments:i,centroidsNormalized:c,iterations:d,inertia:h,converged:a}}function ze(u,n,t){if(u.length<=1||t<=1)return null;let e=Array.from({length:t},()=>[]);for(let s=0;s<n.length;s+=1){let c=n[s]??-1;if(c>=0&&c<t){let i=e[c];i&&i.push(s);}}let o=0,r=0;for(let s=0;s<u.length;s+=1){let c=u[s],i=n[s]??-1;if(!c||i<0||i>=t)continue;let d=e[i]??[];if(d.length<=1)continue;let a=0;for(let m of d){if(m===s)continue;let N=u[m];N&&(a+=de(c,N));}a/=d.length-1;let h=Number.POSITIVE_INFINITY;for(let m=0;m<t;m+=1){if(m===i)continue;let N=e[m]??[];if(N.length===0)continue;let b=0;for(let p of N){let g=u[p];g&&(b+=de(c,g));}b/=N.length,h=Math.min(h,b);}if(!Number.isFinite(h))continue;let l=Math.max(a,h);l<=0||(o+=(h-a)/l,r+=1);}return r===0?null:o/r}function W(u,n){let t=0;for(let e=1;e<u.length;e+=1){let o=u[e-1],r=u[e];if(!o||!r)return Number.POSITIVE_INFINITY;let s=n.get(o)?.get(r);if(s===void 0||!Number.isFinite(s))return Number.POSITIVE_INFINITY;t+=s;}return t}function Ke(u,n,t){if(u.length<4||t<=0)return u;let e=[...u],o=W(e,n);if(!Number.isFinite(o))return e;for(let r=0;r<t;r+=1){let s=false;for(let c=1;c<e.length-2;c+=1)for(let i=c+1;i<e.length-1;i+=1){let d=e.slice(0,c),a=e.slice(c,i+1).reverse(),h=e.slice(i+1),l=d.concat(a,h),m=W(l,n);m+1e-9<o&&(e=l,o=m,s=true);}if(!s)break}return e}function Ye(u,n){let t=[],e=new Set;n.start&&u.includes(n.start)&&(t.push(n.start),e.add(n.start));for(let c of n.startCandidates??[])u.includes(c)&&!e.has(c)&&(t.push(c),e.add(c));let o=ue(n.seed),r=u.filter(c=>!e.has(c));for(let c=r.length-1;c>0;c-=1){let i=Math.floor(o()*(c+1)),d=r[c],a=r[i];d!==void 0&&a!==void 0&&(r[c]=a,r[i]=d);}let s=Math.max(1,Math.min(u.length,n.multiStartCount??Math.min(8,u.length)));for(let c of r){if(t.length>=s)break;t.push(c);}return t.length===0&&u.length>0&&t.push(u[0]),t}function Ue(u,n,t,e){let o=[u],r=new Set(n.filter(c=>c!==u)),s=u;for(;r.size>0;){let c=null,i=Number.POSITIVE_INFINITY,d=t.get(s);for(let a of r){let h=d?.get(a)??Number.POSITIVE_INFINITY;h<i&&(i=h,c=a);}if(!c||!Number.isFinite(i))break;o.push(c),r.delete(c),s=c;}return e&&o.length>1&&o.push(u),o}function We(u,n){if(u.length<=1)return 0;let t=new Set;t.add(u[0]);let e=0;for(;t.size<u.length;){let o=Number.POSITIVE_INFINITY,r=null;for(let s of t){let c=n.get(s);for(let i of u){if(t.has(i))continue;let d=c?.get(i)??Number.POSITIVE_INFINITY;d<o&&(o=d,r=i);}}if(!r||!Number.isFinite(o))return Number.POSITIVE_INFINITY;t.add(r),e+=o;}return e}function v(u,n,t={}){let e=t.directed??true,o=q(u,n),r=ke(o,n,e),s=Ge(r),c=Te(o,s);return {nodes:o,neighborsByNode:s,incomingByNode:c,edges:Oe(s),directed:e}}function le(u,n,t={}){let e=v(u,n,t),o=[];if(e.directed){let s=0,c=new Map,i=new Map,d=[],a=new Set,h=l=>{c.set(l,s),i.set(l,s),s+=1,d.push(l),a.add(l);for(let m of e.neighborsByNode.get(l)??[])if(c.has(m.id)){if(a.has(m.id)){let N=i.get(l)??0,b=c.get(m.id)??0;i.set(l,Math.min(N,b));}}else {h(m.id);let N=i.get(l)??0,b=i.get(m.id)??0;i.set(l,Math.min(N,b));}if((i.get(l)??-1)===(c.get(l)??-2)){let m=[];for(;d.length>0;){let N=d.pop();if(!N||(a.delete(N),m.push(N),N===l))break}m.sort(P),o.push(m);}};for(let l of e.nodes)c.has(l)||h(l);}else {let s=new Set;for(let c of e.nodes){if(s.has(c))continue;let i=[c];s.add(c);let d=[],a=0;for(;a<i.length;){let h=i[a];if(a+=1,!!h){d.push(h);for(let l of e.neighborsByNode.get(h)??[])s.has(l.id)||(s.add(l.id),i.push(l.id));}}d.sort(P),o.push(d);}}o.sort((s,c)=>{let i=s[0]??"",d=c[0]??"";return P(i,d)});let r=new Map;for(let s=0;s<o.length;s+=1)for(let c of o[s]??[])r.set(c,s);return {components:o,componentByNode:r}}function $e(u,n){let t=v(u,n,{directed:false}),e=[],o=new Map,r=new Set;for(let s of t.nodes){if(r.has(s))continue;let c=[s];r.add(s);let i=[],d=0;for(;d<c.length;){let h=c[d];if(d+=1,!!h){i.push(h);for(let l of t.neighborsByNode.get(h)??[])r.has(l.id)||(r.add(l.id),c.push(l.id));}}i.sort(P);let a=e.length;e.push(i);for(let h of i)o.set(h,a);}e.sort((s,c)=>{let i=s[0]??"",d=c[0]??"";return P(i,d)}),o.clear();for(let s=0;s<e.length;s+=1){let c=e[s]??[];for(let i of c)o.set(i,s);}return {components:e,componentByNode:o}}function nt(u,n,t={}){let e=q(u,n),o=t.tieBreaker??((g,f)=>P(g,f)),r=t.priorityByNode,s=t.priority??(g=>r instanceof Map?r.get(g)??0:r?r[g]??0:0),c=(g,f)=>{let I=s(f)-s(g);return Math.abs(I)>1e-12?I:o(g,f)},i=new Map,d=new Map;for(let g of e)i.set(g,new Set),d.set(g,0);for(let g of n){if(g.from===g.to||!i.has(g.from)||!i.has(g.to))continue;let f=i.get(g.from);!f||f.has(g.to)||(f.add(g.to),d.set(g.to,(d.get(g.to)??0)+1));}let a=e.filter(g=>(d.get(g)??0)===0).sort(c),h=[];for(;a.length>0;){let g=a.shift();if(!g)continue;h.push(g);let f=Array.from(i.get(g)??[]).sort(c);for(let I of f){let x=(d.get(I)??0)-1;d.set(I,x),x===0&&a.push(I);}a.sort(c);}let l=new Set(h),m=e.filter(g=>!l.has(g));m.sort(c);let N=le(e,n,{directed:true}),b=new Set(n.filter(g=>g.from===g.to).map(g=>g.from)),p=new Set;for(let g of N.components)if(g.length>1)for(let f of g)p.add(f);else if(g.length===1){let f=g[0];f&&b.has(f)&&p.add(f);}for(let g of m)p.add(g);for(let g of m)l.has(g)||(h.push(g),l.add(g));return {order:h,cycleNodes:Array.from(p).sort(c),isDag:p.size===0}}function He(u,n,t={}){let e=v(u,n,t),o=e.nodes.length,r=o<=1?1:e.directed?2*(o-1):Math.max(1,o-1),s=new Map;for(let c of e.nodes){let i=e.neighborsByNode.get(c)?.length??0,d=e.incomingByNode.get(c)?.length??0,a=e.directed?d+i:i;s.set(c,{inDegree:d,outDegree:i,degree:a,normalized:a/r});}return s}function Xe(u,n,t={}){let e=v(u,n,t),o=e.nodes.length,r=Math.max(0,o-1),s=t.mode??"harmonic",c=new Map;for(let i of e.nodes){let d=z(e,i,t.shortestPathAlgorithm??"auto"),a=d.result.distanceByNode,h=d.result.negativeCycleNodes.size>0,l=0,m=0,N=0;for(let g of e.nodes){if(g===i)continue;let f=a.get(g);f===void 0||!Number.isFinite(f)||f<=0||(l+=1,m+=f,N+=1/f);}let b=0,p=0;h||(s==="classic"?(b=l>0&&m>0?l/m:0,p=r>0?b*(l/r):0):(b=N,p=r>0?N/r:0)),c.set(i,{reachableCount:l,distanceSum:m,score:b,normalized:p,mode:s,negativeCycle:h});}return c}function Je(u,n,t={}){let e=v(u,n,t);if(G(e))throw new E("NEGATIVE_WEIGHT","Betweenness centrality requires non-negative graph weights.");let o=new Map;for(let i of e.nodes)o.set(i,0);for(let i of e.nodes){let d=[],a=new Map,h=new Map,l=new Map,m=new C,N=new Set;for(let p of e.nodes)a.set(p,[]),h.set(p,0),l.set(p,Number.POSITIVE_INFINITY);for(h.set(i,1),l.set(i,0),m.push(i,0);m.size>0;){let p=m.pop();if(!p)break;let g=p.value;if(N.has(g))continue;N.add(g),d.push(g);let f=l.get(g);if(f===void 0||!Number.isFinite(f))continue;let I=h.get(g)??0;for(let x of e.neighborsByNode.get(g)??[]){let M=f+x.weight,w=l.get(x.id);w===void 0||M<w-1e-12?(l.set(x.id,M),m.push(x.id,M),h.set(x.id,I),a.set(x.id,[g])):w!==void 0&&Math.abs(M-w)<=1e-12&&(h.set(x.id,(h.get(x.id)??0)+I),a.get(x.id)?.push(g));}}let b=new Map;for(let p of e.nodes)b.set(p,0);for(;d.length>0;){let p=d.pop();if(!p)continue;let g=h.get(p)??0,f=b.get(p)??0;for(let I of a.get(p)??[]){let x=h.get(I)??0;if(g<=0)continue;let M=x/g*(1+f);b.set(I,(b.get(I)??0)+M);}p!==i&&o.set(p,(o.get(p)??0)+f);}}if(!e.directed)for(let i of e.nodes)o.set(i,(o.get(i)??0)/2);let r=e.nodes.length,s=r<=2?Number.POSITIVE_INFINITY:e.directed?(r-1)*(r-2):(r-1)*(r-2)/2,c=new Map;for(let i of e.nodes){let d=o.get(i)??0;c.set(i,{raw:d,normalized:Number.isFinite(s)&&s>0?d/s:0});}return c}function X(u,n,t={}){let e=v(u,n,t);if(G(e))throw new E("NEGATIVE_WEIGHT","PageRank requires non-negative graph weights.");let o=e.nodes.length;if(o===0)return {byNode:new Map,order:[],iterations:0,converged:true,dampingFactor:t.dampingFactor??.85};let r=t.dampingFactor??.85;if(!Number.isFinite(r)||r<0||r>=1)throw new E("INVALID_ARGUMENT",`PageRank dampingFactor must be in [0, 1), received ${r}.`);let s=Math.max(0,t.tolerance??1e-9),c=Math.max(1,Math.floor(t.maxIterations??200)),i=1/o,d=new Map;for(let g of e.nodes){let f=(e.neighborsByNode.get(g)??[]).reduce((I,x)=>I+x.weight,0);d.set(g,f);}let a=new Map;for(let g of e.nodes)a.set(g,i);let h=0,l=false;for(let g=0;g<c;g+=1){h=g+1;let f=new Map,I=(1-r)/o,x=0;for(let y of e.nodes)(d.get(y)??0)<=1e-12&&(x+=a.get(y)??0),f.set(y,I);let M=r*x/o;if(M>0)for(let y of e.nodes)f.set(y,(f.get(y)??0)+M);for(let y of e.nodes){let R=d.get(y)??0;if(R<=1e-12)continue;let S=a.get(y)??0;for(let A of e.neighborsByNode.get(y)??[]){let k=r*S*A.weight/R;f.set(A.id,(f.get(A.id)??0)+k);}}let w=0;for(let y of e.nodes){let R=a.get(y)??0,S=f.get(y)??0;w+=Math.abs(R-S);}if(a=f,w<=s){l=true;break}}let m=0;for(let g of e.nodes)m+=a.get(g)??0;if(!Number.isFinite(m)||m<=0){a=new Map;for(let g of e.nodes)a.set(g,i);m=1;}else if(Math.abs(m-1)>1e-12)for(let g of e.nodes)a.set(g,(a.get(g)??0)/m);let N=[...e.nodes].sort((g,f)=>{let I=(a.get(f)??0)-(a.get(g)??0);return Math.abs(I)>1e-12?I:P(g,f)}),b=N.length>0?a.get(N[0])??0:0,p=new Map;for(let g=0;g<N.length;g+=1){let f=N[g];if(!f)continue;let I=a.get(f)??0;p.set(f,{score:I,normalized:b>0?I/b:0,rank:g+1});}return {byNode:p,order:N,iterations:h,converged:l,dampingFactor:r}}function ot(u,n,t={}){let e=v(u,n,{directed:false}),o=t.tieBreaker??((l,m)=>P(l,m)),r=new Map;for(let l of e.edges){if(l.from===l.to)continue;let m=V(l.from,l.to),N=F(m.from,m.to),b=r.get(N);(!b||l.weight<b.weight-1e-12)&&r.set(N,{from:m.from,to:m.to,weight:l.weight});}let s=Array.from(r.values());s.sort((l,m)=>{let N=l.weight-m.weight;if(Math.abs(N)>1e-12)return N;let b=o(l.from,m.from);return b!==0?b:o(l.to,m.to)});let c=new Y(e.nodes),i=[],d=0;for(let l of s)c.union(l.from,l.to)&&(i.push(l),d+=l.weight);let a=new Set;for(let l of e.nodes)a.add(c.find(l));let h=a.size;return {edges:i,totalWeight:d,componentCount:h,spanning:e.nodes.length<=1||h===1&&i.length===e.nodes.length-1}}function Qe(u,n){let t=v(u,n,{directed:false}),e=new Map,o=new Map,r=new Map,s=new Set,c=new Map,i=0,d=h=>{e.set(h,i),o.set(h,i),i+=1;let l=0,m=r.get(h)??null;for(let N of t.neighborsByNode.get(h)??[]){let b=e.get(N.id);if(b===void 0){r.set(N.id,h),l+=1,d(N.id);let p=o.get(h)??0,g=o.get(N.id)??0;o.set(h,Math.min(p,g));let f=e.get(h)??0;if(m===null&&l>1&&s.add(h),m!==null&&g>=f&&s.add(h),g>f){let I=V(h,N.id),x=F(I.from,I.to),M=c.get(x);(!M||N.weight<M.weight-1e-12)&&c.set(x,{from:I.from,to:I.to,weight:N.weight});}}else if(N.id!==m){let p=o.get(h)??0;o.set(h,Math.min(p,b));}}};for(let h of t.nodes)e.has(h)||(r.set(h,null),d(h));let a=Array.from(c.values());return a.sort((h,l)=>{let m=P(h.from,l.from);if(m!==0)return m;let N=P(h.to,l.to);return N!==0?N:h.weight-l.weight}),{articulationPoints:Array.from(s).sort(P),bridges:a}}function rt(u,n,t={}){let e=le(u,n,t),o=$e(u,n),r=Qe(u,n),s=q(u,n),c=[...s].sort(P),i=new Map,d=new Map;try{i=Je(u,n,t);}catch(a){if(!(a instanceof E)||a.code!=="NEGATIVE_WEIGHT")throw a;i=new Map;for(let h of c)i.set(h,{raw:0,normalized:0});}try{d=X(u,n,{directed:t.directed??!0,...t.pageRankOptions??{}}).byNode;}catch(a){if(!(a instanceof E)||a.code!=="NEGATIVE_WEIGHT")throw a;let h=s.length>0?1/s.length:0;d=new Map;for(let l=0;l<c.length;l+=1){let m=c[l];m&&d.set(m,{score:h,normalized:1,rank:l+1});}}return {degree:He(u,n,t),closeness:Xe(u,n,{...t,mode:t.closenessMode??"harmonic",shortestPathAlgorithm:t.shortestPathAlgorithm}),betweenness:i,pageRank:d,stronglyConnectedComponents:e.components,weaklyConnectedComponents:o.components,articulationPoints:r.articulationPoints,bridges:r.bridges}}function j(u,n,t,e,o={}){let r=v(u,n,o);if(!r.neighborsByNode.has(t)||!r.neighborsByNode.has(e))return {source:t,target:e,path:[],distance:Number.POSITIVE_INFINITY,reachable:false,explored:0,algorithm:o.algorithm??"auto",hasNegativeWeights:G(r),negativeCycle:false};let s=z(r,t,o.algorithm??"auto");if(s.result.negativeCycleNodes.has(e)){if(o.failOnNegativeCycle??false)throw new E("NEGATIVE_CYCLE",`Negative cycle reaches target node "${e}".`);return {source:t,target:e,path:[],distance:Number.NEGATIVE_INFINITY,reachable:false,explored:s.result.explored,algorithm:s.algorithm,hasNegativeWeights:s.hasNegativeWeights,negativeCycle:true}}let c=s.result.distanceByNode.get(e)??Number.POSITIVE_INFINITY,i=Number.isFinite(c),d=i?$(t,e,s.result.previousByNode):[];return {source:t,target:e,path:d,distance:c,reachable:i&&d.length>0,explored:s.result.explored,algorithm:s.algorithm,hasNegativeWeights:s.hasNegativeWeights,negativeCycle:s.result.negativeCycleNodes.size>0}}function he(u,n,t={}){let e=v(u,n,{directed:t.directed??false});if(G(e))throw new E("NEGATIVE_WEIGHT","Label propagation requires non-negative graph weights.");let o=t.tieBreaker??((a,h)=>P(a,h)),r=[...e.nodes].sort(o),s=new Map;for(let a=0;a<r.length;a+=1){let h=r[a];h&&s.set(h,a);}let c=Math.max(1,t.maxIterations??100),i=0,d=false;for(let a=0;a<c;a+=1){i=a+1;let h=false;for(let l of r){let m=e.neighborsByNode.get(l)??[];if(m.length===0)continue;let N=new Map;for(let f of m){let I=s.get(f.id);I!==void 0&&N.set(I,(N.get(I)??0)+f.weight);}let b=s.get(l);if(b===void 0||N.size===0)continue;let p=b,g=Number.NEGATIVE_INFINITY;for(let[f,I]of N.entries()){if(I>g+1e-12){g=I,p=f;continue}Math.abs(I-g)<=1e-12&&f<p&&(p=f);}p!==b&&(s.set(l,p),h=true);}if(!h){d=true;break}}return U(e,s,i,d,"label-propagation")}function me(u,n,t={}){let e=v(u,n,{directed:t.directed??false});if(G(e))throw new E("NEGATIVE_WEIGHT","Louvain requires non-negative graph weights.");let o=t.tieBreaker??((N,b)=>P(N,b)),r=[...e.nodes].sort(o),s=Math.max(1,t.maxPasses??32),c=Math.max(0,t.tolerance??1e-9),i=new Map;for(let N of e.nodes)i.set(N,ae(e.neighborsByNode.get(N)??[]));let d=0;for(let N of i.values())d+=N;let a=new Map,h=new Map;for(let N=0;N<r.length;N+=1){let b=r[N];if(!b)continue;a.set(b,N);let p=i.get(b)??0;h.set(N,p);}if(d<=1e-12)return U(e,a,0,true,"louvain");let l=0,m=false;for(let N=0;N<s;N+=1){l=N+1;let b=false;for(let p of r){let g=a.get(p);if(g===void 0)continue;let f=i.get(p)??0;h.set(g,(h.get(g)??0)-f);let I=new Map;for(let w of e.neighborsByNode.get(p)??[]){let y=a.get(w.id);y!==void 0&&I.set(y,(I.get(y)??0)+w.weight);}let x=g,M=0;for(let[w,y]of I.entries()){let R=h.get(w)??0,S=y-R*f/d;if(S>M+c){M=S,x=w;continue}Math.abs(S-M)<=c&&w<x&&(x=w);}x!==g&&M>c?(a.set(p,x),h.set(x,(h.get(x)??0)+f),b=true):h.set(g,(h.get(g)??0)+f);}if(!b){m=true;break}}return U(e,a,l,m,"louvain")}function ge(u,n,t={}){let e=v(u,n,{directed:t.directed??false}),o=t.metric??"jaccard",r=t.minScore??0,s=H(e),c=[...e.nodes].sort(P),i=[];for(let d=0;d<c.length;d+=1){let a=c[d];if(a)for(let h=d+1;h<c.length;h+=1){let l=c[h];if(!l)continue;let m=L(a,l,s,o);m<r-1e-12||i.push({left:a,right:l,score:m,metric:o});}}return i.sort((d,a)=>{let h=a.score-d.score;if(Math.abs(h)>1e-12)return h;let l=P(d.left,a.left);return l!==0?l:P(d.right,a.right)}),{metric:o,pairs:i.map((d,a)=>({...d,rank:a+1}))}}function fe(u,n,t={}){let e=v(u,n,{directed:t.directed??false}),o=t.metric??"jaccard",r=t.minScore??0,s=Math.max(1,Math.floor(t.k??5)),c=H(e),i=[...e.nodes].sort(P),d=new Map;for(let a of i){let h=[];for(let l of i){if(a===l)continue;let m=L(a,l,c,o);m<r-1e-12||h.push({nodeId:l,score:m});}h.sort((l,m)=>{let N=m.score-l.score;return Math.abs(N)>1e-12?N:P(l.nodeId,m.nodeId)}),d.set(a,h.slice(0,s));}return {metric:o,k:s,neighborsByNode:d}}function J(u,n,t={}){let e=t.directed??false,o=v(u,n,{directed:e}),r=t.metric??"jaccard",s=t.minScore??0,c=Math.max(1,Math.floor(t.limit??20)),i=t.allowExistingEdges??false,d=H(o),a=[...o.nodes].sort(P),h=t.sourceFilter?new Set(t.sourceFilter):null,l=t.targetFilter?new Set(t.targetFilter):null,m=new Set;for(let b of o.edges)e?m.add(`${b.from}\0${b.to}`):m.add(F(b.from,b.to));let N=[];if(e){for(let b of a)if(!(h&&!h.has(b)))for(let p of a){if(b===p||l&&!l.has(p)||!i&&m.has(`${b}\0${p}`))continue;let g=L(b,p,d,r);g<s-1e-12||N.push({from:b,to:p,score:g,metric:r});}}else for(let b=0;b<a.length;b+=1){let p=a[b];if(p)for(let g=b+1;g<a.length;g+=1){let f=a[g];if(!f||h&&!h.has(p)&&!h.has(f)||l&&!l.has(p)&&!l.has(f)||!i&&m.has(F(p,f)))continue;let I=L(p,f,d,r);I<s-1e-12||N.push({from:p,to:f,score:I,metric:r});}}return N.sort((b,p)=>{let g=p.score-b.score;if(Math.abs(g)>1e-12)return g;let f=P(b.from,p.from);return f!==0?f:P(b.to,p.to)}),{metric:r,predictions:N.slice(0,c).map((b,p)=>({...b,rank:p+1}))}}function it(u,n,t={}){return J(u,n,t)}function Ie(u,n,t,e,o={}){let r=v(u,n,o);if(G(r))throw new E("NEGATIVE_WEIGHT","A* requires non-negative graph weights.");if(!r.neighborsByNode.has(t)||!r.neighborsByNode.has(e))return {source:t,target:e,path:[],distance:Number.POSITIVE_INFINITY,reachable:false,explored:0,estimatedDistance:Number.POSITIVE_INFINITY};let s=o.heuristic??((p,g)=>0),c=new C,i=new Map,d=new Map,a=new Set;for(let p of r.nodes)i.set(p,Number.POSITIVE_INFINITY);i.set(t,0);let h=s(t,e);if(!Number.isFinite(h))throw new E("INVALID_ARGUMENT","A* heuristic must return finite values.");c.push(t,h);let l=0;for(;c.size>0;){let p=c.pop();if(!p)break;let g=p.value;if(a.has(g))continue;if(a.add(g),l+=1,g===e)break;let f=i.get(g);if(!(f===void 0||!Number.isFinite(f)))for(let I of r.neighborsByNode.get(g)??[]){let x=f+I.weight,M=i.get(I.id)??Number.POSITIVE_INFINITY;if(x>=M-1e-12)continue;let w=s(I.id,e);if(!Number.isFinite(w))throw new E("INVALID_ARGUMENT","A* heuristic must return finite values.");i.set(I.id,x),d.set(I.id,g),c.push(I.id,x+w);}}let m=i.get(e)??Number.POSITIVE_INFINITY,N=Number.isFinite(m),b=N?$(t,e,d):[];return {source:t,target:e,path:b,distance:m,reachable:N&&b.length>0,explored:l,estimatedDistance:m}}function Ne(u,n,t={}){let e=v(u,n,t),o=t.algorithm??"auto",r=ce(o,G(e)),s=new Map,c=new Map,i=false;for(let d of e.nodes){let a=z(e,d,r);if(a.result.negativeCycleNodes.size>0&&(i=true,t.failOnNegativeCycle??false))throw new E("NEGATIVE_CYCLE",`Negative cycle reaches source node "${d}".`);let h=new Map,l=new Map;for(let m of e.nodes){h.set(m,a.result.distanceByNode.get(m)??Number.POSITIVE_INFINITY);let N=a.result.previousByNode.get(m);N&&l.set(m,N);}s.set(d,h),c.set(d,l);}return {nodes:e.nodes,distanceBySource:s,previousBySource:c,algorithm:r,hasNegativeWeights:G(e),negativeCycle:i}}function pe(u,n,t,e,o={}){let r=o.directed??true,s=Math.max(1,Math.floor(o.k??3)),c=o.shortestPathAlgorithm??"auto",i=v(u,n,{directed:r});if(!i.neighborsByNode.has(t)||!i.neighborsByNode.has(e))return {source:t,target:e,paths:[],complete:false};let d=j(i.nodes,i.edges,t,e,{directed:r,algorithm:c});if(!d.reachable||d.path.length===0)return {source:t,target:e,paths:[],complete:false};let a=[{path:d.path,distance:d.distance}],h=new Map;for(let l=1;l<s;l+=1){let m=a[l-1]?.path??[];if(m.length<2)break;for(let b=0;b<m.length-1;b+=1){let p=m[b];if(!p)continue;let g=m.slice(0,b+1),f=new Set(g.slice(0,-1)),I=new Set;for(let S of a)if(S.path.length>b+1&&De(S.path,g)){let A=S.path[b],k=S.path[b+1];A&&k&&I.add(`${A}\0${k}`);}let x=i.edges.filter(S=>!(I.has(`${S.from}\0${S.to}`)||f.has(S.from)||f.has(S.to))),M=j(i.nodes,x,p,e,{directed:r,algorithm:c});if(!M.reachable||M.path.length===0)continue;let w=g.slice(0,-1).concat(M.path),y=Be(w,i);if(!Number.isFinite(y))continue;let R=_(w);h.has(R)||h.set(R,{path:w,distance:y});}if(h.size===0)break;let N=Array.from(h.values()).sort((b,p)=>{let g=b.distance-p.distance;return Math.abs(g)>1e-12?g:P(_(b.path),_(p.path))})[0];if(!N)break;a.push(N),h.delete(_(N.path));}return {source:t,target:e,paths:a,complete:a.length>=s}}function be(u,n,t,e,o={}){let r=v(u,n,o);if(!r.neighborsByNode.has(t)||!r.neighborsByNode.has(e))return {source:t,sink:e,maxFlow:0,augmentations:0,flowByEdge:[],sourcePartition:[],sinkPartition:[],cutEdges:[]};let s=[];for(let I of r.edges){if(I.weight<0)throw new E("NEGATIVE_WEIGHT","Maximum flow requires non-negative capacities.");s.push(I);}let c=new Map;for(let I of r.nodes)c.set(I,[]);let i=(I,x,M,w)=>{let y=c.get(I),R=c.get(x);if(!y||!R)return;let S=y.length,A=R.length;y.push({to:x,reverseIndex:A,capacity:M,originalIndex:w}),R.push({to:I,reverseIndex:S,capacity:0,originalIndex:null});};for(let I=0;I<s.length;I+=1){let x=s[I];x&&i(x.from,x.to,x.weight,I);}let d=0,a=0,h=new Array(s.length).fill(0);for(;;){let I=new Map,x=[t];I.set(t,{from:t,edgeIndex:-1});let M=0;for(;M<x.length&&!I.has(e);){let R=x[M];if(M+=1,!R)continue;let S=c.get(R)??[];for(let A=0;A<S.length;A+=1){let k=S[A];!k||k.capacity<=1e-12||I.has(k.to)||(I.set(k.to,{from:R,edgeIndex:A}),x.push(k.to));}}if(!I.has(e))break;let w=Number.POSITIVE_INFINITY,y=e;for(;y!==t;){let R=I.get(y);if(!R){w=0;break}let S=c.get(R.from)?.[R.edgeIndex];if(!S){w=0;break}w=Math.min(w,S.capacity),y=R.from;}if(!Number.isFinite(w)||w<=1e-12)break;for(y=e;y!==t;){let R=I.get(y);if(!R)break;let S=c.get(R.from)?.[R.edgeIndex],A=S?c.get(S.to)?.[S.reverseIndex]:void 0;if(!S||!A)break;S.capacity-=w,A.capacity+=w,S.originalIndex!==null?h[S.originalIndex]=(h[S.originalIndex]??0)+w:A.originalIndex!==null&&(h[A.originalIndex]=(h[A.originalIndex]??0)-w),y=R.from;}d+=w,a+=1;}let l=new Set,m=[t];l.add(t);let N=0;for(;N<m.length;){let I=m[N];if(N+=1,!!I)for(let x of c.get(I)??[])x.capacity<=1e-12||l.has(x.to)||(l.add(x.to),m.push(x.to));}let b=r.nodes.filter(I=>l.has(I)).sort(P),p=r.nodes.filter(I=>!l.has(I)).sort(P),g=s.filter(I=>l.has(I.from)&&!l.has(I.to)).sort((I,x)=>{let M=P(I.from,x.from);return M!==0?M:P(I.to,x.to)}),f=s.map((I,x)=>({from:I.from,to:I.to,flow:Math.max(0,h[x]??0),capacity:I.weight})).sort((I,x)=>{let M=P(I.from,x.from);return M!==0?M:P(I.to,x.to)});return {source:t,sink:e,maxFlow:d,augmentations:a,flowByEdge:f,sourcePartition:b,sinkPartition:p,cutEdges:g}}function xe(u,n,t,e,o={}){let r=n.map(f=>({from:f.from,to:f.to,weight:f.capacity})),s=q(u,r),c=o.directed??true;if(!s.includes(t)||!s.includes(e))return {source:t,sink:e,flow:0,cost:0,complete:false,augmentations:0,flowByEdge:[]};let i=[];for(let f of n){if(!Number.isFinite(f.capacity)||f.capacity<0)throw new E("INVALID_ARGUMENT",`Flow edge capacity must be non-negative and finite, received ${f.capacity}.`);let I=f.cost??0;if(!Number.isFinite(I))throw new E("INVALID_ARGUMENT",`Flow edge cost must be finite, received ${I}.`);i.push({from:f.from,to:f.to,capacity:f.capacity,cost:I}),c||i.push({from:f.to,to:f.from,capacity:f.capacity,cost:I});}let d=new Map;for(let f of s)d.set(f,[]);let a=(f,I,x,M,w)=>{let y=d.get(f),R=d.get(I);if(!y||!R)return;let S=y.length,A=R.length;y.push({to:I,reverseIndex:A,capacity:x,cost:M,originalIndex:w}),R.push({to:f,reverseIndex:S,capacity:0,cost:-M,originalIndex:null});};for(let f=0;f<i.length;f+=1){let I=i[f];I&&a(I.from,I.to,I.capacity,I.cost,f);}let h=o.targetFlow,l=h===void 0?Number.POSITIVE_INFINITY:h;if(!Number.isFinite(l)&&l!==Number.POSITIVE_INFINITY)throw new E("INVALID_ARGUMENT",`targetFlow must be finite or omitted, received ${l}.`);if(l<0)throw new E("INVALID_ARGUMENT",`targetFlow must be non-negative, received ${l}.`);let m=0,N=0,b=0,p=new Array(i.length).fill(0);for(;m<l-1e-12;){let f=new Map,I=new Map;for(let y of s)f.set(y,Number.POSITIVE_INFINITY);f.set(t,0);for(let y=0;y<s.length-1;y+=1){let R=false;for(let S of s){let A=f.get(S);if(A===void 0||!Number.isFinite(A))continue;let k=d.get(S)??[];for(let D=0;D<k.length;D+=1){let T=k[D];if(!T||T.capacity<=1e-12)continue;let ie=A+T.cost,Ee=f.get(T.to)??Number.POSITIVE_INFINITY;ie<Ee-1e-12&&(f.set(T.to,ie),I.set(T.to,{from:S,edgeIndex:D}),R=true);}}if(!R)break}let x=f.get(e)??Number.POSITIVE_INFINITY;if(!Number.isFinite(x))break;let M=Math.min(l-m,Number.POSITIVE_INFINITY),w=e;for(;w!==t;){let y=I.get(w);if(!y){M=0;break}let R=d.get(y.from)?.[y.edgeIndex];if(!R){M=0;break}M=Math.min(M,R.capacity),w=y.from;}if(!Number.isFinite(M)||M<=1e-12)break;for(w=e;w!==t;){let y=I.get(w);if(!y)break;let R=d.get(y.from)?.[y.edgeIndex],S=R?d.get(R.to)?.[R.reverseIndex]:void 0;if(!R||!S)break;R.capacity-=M,S.capacity+=M,R.originalIndex!==null?p[R.originalIndex]=(p[R.originalIndex]??0)+M:S.originalIndex!==null&&(p[S.originalIndex]=(p[S.originalIndex]??0)-M),w=y.from;}m+=M,N+=M*x,b+=1;}let g=i.map((f,I)=>({from:f.from,to:f.to,flow:Math.max(0,p[I]??0),capacity:f.capacity,cost:f.cost})).sort((f,I)=>{let x=P(f.from,I.from);return x!==0?x:P(f.to,I.to)});return {source:t,sink:e,flow:m,cost:N,complete:l===Number.POSITIVE_INFINITY?true:m>=l-1e-12,augmentations:b,flowByEdge:g}}function Ze(u,n,t={}){if(!Array.isArray(u)||u.length===0)throw new E("INVALID_ARGUMENT","kMeansClustering requires at least one point.");let e=u[0]?.length??0;if(e===0)throw new E("INVALID_ARGUMENT","kMeansClustering requires points with at least one axis.");for(let g of u)if(g.length!==e)throw new E("INVALID_ARGUMENT","kMeansClustering requires all points to share dimensionality.");let o=Math.max(1,Math.min(u.length,Math.floor(n))),r=Math.max(1,t.maxIterations??120),s=Math.max(0,t.tolerance??1e-5),c=Math.max(1,t.nInit??8),i=t.normalization??"zscore",d=t.useKMeansPlusPlus??true,a=t.seed===void 0||!Number.isFinite(t.seed)?Math.floor(Math.random()*4294967295):Math.floor(t.seed),h=je(u,i),l=u.map(g=>h.normalize(g)),m=null,N=a;for(let g=0;g<c;g+=1){let f=a+g*2654435761>>>0,I=ue(f),x=qe(l,o,I,r,s,d);(!m||x.inertia<m.inertia-1e-9)&&(m=x,N=f);}if(!m)throw new E("INVALID_ARGUMENT","kMeansClustering failed to produce a valid run.");let b=[];for(let g=0;g<o;g+=1){let f=[];for(let I=0;I<m.assignments.length;I+=1)m.assignments[I]===g&&f.push(I);b.push({centroid:h.denormalize(m.centroidsNormalized[g]??[]),indices:f});}let p=ze(l,m.assignments,o);return {assignments:m.assignments,clusters:b,iterations:m.iterations,inertia:m.inertia,converged:m.converged,silhouette:p,selectedSeed:N}}function st(u,n={}){if(!Array.isArray(u)||u.length===0)throw new E("INVALID_ARGUMENT","kMeansAuto requires at least one point.");let t=Math.max(2,n.kMin??2),e=Math.max(t,Math.min(u.length,n.kMax??Math.min(10,Math.ceil(Math.sqrt(u.length))+2))),o=null,r=t,s=[];for(let c=t;c<=e;c+=1){let i=Ze(u,c,{...n,seed:n.seed===void 0||!Number.isFinite(n.seed)?void 0:n.seed+c*997});if(s.push({k:c,silhouette:i.silhouette,inertia:i.inertia}),!o){o=i,r=c;continue}let d=i.silhouette??Number.NEGATIVE_INFINITY,a=o.silhouette??Number.NEGATIVE_INFINITY;if(d>a+1e-9){o=i,r=c;continue}Math.abs(d-a)<=1e-9&&i.inertia<o.inertia-1e-9&&(o=i,r=c);}if(!o)throw new E("INVALID_ARGUMENT","kMeansAuto failed to choose a cluster configuration.");return {...o,selectedK:r,candidates:s}}function dt(u,n,t={}){let e=v(u,n,t);if(e.nodes.length===0)return {order:[],distance:0,segments:[],visitedCount:0,complete:true,unreachableNodes:[],lowerBound:0,optimalityGap:0};if(G(e))throw new E("NEGATIVE_WEIGHT","TSP approximation requires non-negative graph weights.");let o=t.returnToStart??true,r=Math.max(0,t.twoOptPasses??3),s=Ye(e.nodes,t),c=new Map,i=new Map;for(let f of e.nodes){let I=z(e,f,t.shortestPathAlgorithm??"auto");if(I.result.negativeCycleNodes.size>0)throw new E("NEGATIVE_CYCLE","TSP approximation cannot run when negative cycles are reachable.");c.set(f,I.result.distanceByNode),i.set(f,I.result.previousByNode);}let d=[],a=Number.POSITIVE_INFINITY;for(let f of s){let x=Ue(f,e.nodes,c,o);x.length>2&&(x=Ke(x,c,r));let M=W(x,c);M<a&&(a=M,d=x);}let h=new Set(d),l=e.nodes.filter(f=>!h.has(f)),m=l.length===0&&Number.isFinite(a),N=[],b=0;for(let f=1;f<d.length;f+=1){let I=d[f-1],x=d[f];if(!I||!x)continue;let M=c.get(I)?.get(x)??Number.POSITIVE_INFINITY,w=i.get(I)??new Map,y=$(I,x,w);!Number.isFinite(M)||y.length===0||(b+=M,N.push({from:I,to:x,distance:M,path:y}));}m||(b=Number.POSITIVE_INFINITY);let p=We(e.nodes,c),g=m&&Number.isFinite(b)&&Number.isFinite(p)&&p>0?(b-p)/p:null;return {order:d,distance:b,segments:N,visitedCount:h.size,complete:m,unreachableNodes:l,lowerBound:p,optimalityGap:g}}var Q=class{projections=new Map;project(n,t,e,o={}){let r=n.trim();if(!r)throw new E("INVALID_ARGUMENT","Projection name must be non-empty.");if(this.projections.has(r)&&!(o.replace??false))throw new E("INVALID_ARGUMENT",`Projection "${r}" already exists.`);let s=o.directed??true,c=v(t,e,{directed:s}),i={name:r,nodes:c.nodes,edges:c.edges,directed:s,createdAt:Date.now(),metadata:o.metadata??{}};return this.projections.set(r,i),i}drop(n){return this.projections.delete(n)}clear(){this.projections.clear();}exists(n){return this.projections.has(n)}get(n){return this.projections.get(n)??null}list(){return Array.from(this.projections.values()).map(n=>({name:n.name,nodeCount:n.nodes.length,edgeCount:n.edges.length,directed:n.directed,createdAt:n.createdAt,metadata:n.metadata})).sort((n,t)=>n.name.localeCompare(t.name))}pageRank(n,t={}){let e=this.requireProjection(n);return X(e.nodes,e.edges,{directed:e.directed,...t})}louvain(n,t={}){let e=this.requireProjection(n);return me(e.nodes,e.edges,{directed:e.directed,...t})}labelPropagation(n,t={}){let e=this.requireProjection(n);return he(e.nodes,e.edges,{directed:e.directed,...t})}similarity(n,t={}){let e=this.requireProjection(n);return ge(e.nodes,e.edges,{directed:e.directed,...t})}knn(n,t={}){let e=this.requireProjection(n);return fe(e.nodes,e.edges,{directed:e.directed,...t})}linkPrediction(n,t={}){let e=this.requireProjection(n);return J(e.nodes,e.edges,{directed:e.directed,...t})}shortestPath(n,t,e,o={}){let r=this.requireProjection(n);return j(r.nodes,r.edges,t,e,{directed:r.directed,...o})}aStar(n,t,e,o={}){let r=this.requireProjection(n);return Ie(r.nodes,r.edges,t,e,{directed:r.directed,...o})}yen(n,t,e,o={}){let r=this.requireProjection(n);return pe(r.nodes,r.edges,t,e,{directed:r.directed,...o})}allPairs(n,t={}){let e=this.requireProjection(n);return Ne(e.nodes,e.edges,{directed:e.directed,...t})}maxFlow(n,t,e,o={}){let r=this.requireProjection(n);return be(r.nodes,r.edges,t,e,{directed:r.directed,...o})}minCostMaxFlow(n,t,e,o=null,r={}){let s=this.requireProjection(n),c=o??s.edges.map(i=>({from:i.from,to:i.to,capacity:i.weight,cost:i.weight}));return xe(s.nodes,c,t,e,{directed:s.directed,...r})}runPipeline(n,t){let e=new Map;for(let o of t){let r=o.id.trim();if(!r)throw new E("INVALID_ARGUMENT","Pipeline step id must be non-empty.");if(e.has(r))throw new E("INVALID_ARGUMENT",`Duplicate pipeline step id "${r}".`);if(o.kind==="page-rank"){e.set(r,this.pageRank(n,o.options));continue}if(o.kind==="louvain"){e.set(r,this.louvain(n,o.options));continue}if(o.kind==="label-propagation"){e.set(r,this.labelPropagation(n,o.options));continue}if(o.kind==="similarity"){e.set(r,this.similarity(n,o.options));continue}if(o.kind==="knn"){e.set(r,this.knn(n,o.options));continue}if(o.kind==="link-prediction"){e.set(r,this.linkPrediction(n,o.options));continue}if(o.kind==="shortest-path"){e.set(r,this.shortestPath(n,o.source,o.target,o.options));continue}if(o.kind==="a-star"){e.set(r,this.aStar(n,o.source,o.target,o.options));continue}if(o.kind==="yen-k-shortest-paths"){e.set(r,this.yen(n,o.source,o.target,o.options));continue}if(o.kind==="max-flow"){e.set(r,this.maxFlow(n,o.source,o.sink,o.options));continue}if(o.kind==="min-cost-max-flow"){e.set(r,this.minCostMaxFlow(n,o.source,o.sink,o.edges??null,o.options));continue}if(o.kind==="all-pairs-shortest-paths"){e.set(r,this.allPairs(n,o.options));continue}let s=o;throw new E("INVALID_ARGUMENT",`Unsupported pipeline step kind "${String(s)}".`)}return e}requireProjection(n){let t=this.projections.get(n);if(!t)throw new E("INVALID_ARGUMENT",`Projection "${n}" does not exist.`);return t}};function et(){return new Q}var ut=et();var B=100,tt=0,re=1e3,Z=1.5,Me=1,ye=2,K=2;function we(u=B){return Math.floor(Math.random()*u)}function Re(u=re,n=B){let t=[];for(let e=0;e<u;e++)t.push(we(n));return t}function Se(u=K,n=B){let t=[];for(let e=0;e<u;e++)t.push(Math.floor(Math.random()*(n/10)%n));return t}function ee(u=re,n=K,t=B){let e=[];for(let o=0;o<u;o++)e.push(Se(n,t));return e}var te=class{data;constructor(n={}){this.data={original:n.data??Re()};}sorted(){return this.data.sorted||(this.data.sorted=this.getSorted(this.data.original)),this.data.sorted}getSorted(n){return [...n].sort((t,e)=>t>e?1:t===e?0:-1)}median(){return this.sorted(),this.data.median===void 0&&(this.data.median=this.getMedian(this.data.sorted)),this.data.medianDepth===void 0&&(this.data.medianDepth=this.getMedianDepth(this.data.sorted)),{datum:this.data.median,depth:this.data.medianDepth}}getMedianDepth(n,t=0){return n.length?t+(n.length+1)/2:NaN}getMedian(n){let t=n.length;if(!t)return NaN;if(t===1)return n[0];let e=Math.floor(t/2);return t%2===0?(n[e-1]+n[e])/2:n[e]}mean(){return this.data.mean===void 0&&(this.data.mean=this.getMean(this.data.original)),this.data.mean}getMean(n){if(!n.length)return NaN;let t=0;for(let e of n)t+=e;return t/n.length}mode(){return this.data.mode||(this.sorted(),this.data.mode=this.getMode(this.data.sorted)),this.data.mode}getMode(n){if(!n.length)return {count:0,data:[]};let t={},e=0;for(let r of n)t[r]=(t[r]||0)+1,t[r]>e&&(e=t[r]);let o=[];for(let[r,s]of Object.entries(t))s===e&&o.push(Number(r));return {count:e,data:o.sort((r,s)=>r-s)}}extremes(){return this.data.extremes||(this.sorted(),this.data.extremes=this.getExtremes(this.data.sorted)),this.data.extremes}getExtremes(n){return n.length?[n[0],n[n.length-1]]:[]}counts(){return this.data.counts||(this.sorted(),this.data.counts=this.getCounts(this.data.sorted)),this.data.counts}getCounts(n){let t=new Map;for(let o of n)t.set(o,(t.get(o)||0)+1);let e=[];for(let[o,r]of t)e.push([o,r]);return e.sort((o,r)=>o[0]-r[0])}hinges(){return this.data.hinges||(this.sorted(),this.data.hinges=this.getHinges(this.data.sorted)),this.data.hinges}getHinges(n,t=2,e=[]){let o=[...n],r=o.length,s=t;if(s%2!==0&&s++,r<=s||s<=0)return e;let c=Math.floor(r/s),i=Math.floor(r/c)-1;for(let d=0;d<=i;d++){let a=o.slice(d*c,d*c+c);e.push({datum:this.getMedian(a),depth:this.getMedianDepth(a,d*c)});}return e}iqr(){return this.data.iqr===void 0&&(this.hinges(),this.data.iqr=this.getIQR(this.data.hinges)),this.data.iqr}getIQR(n){let t=n[0]?.datum,e=n[1]?.datum;return t===void 0||e===void 0?NaN:Math.abs(t-e)}fences(){return this.data.fences||(this.median(),this.iqr(),this.data.fences=this.getFences()),this.data.fences}getFences(n=Z){let t=this.data.median,e=this.data.iqr;if(t===void 0||e===void 0||isNaN(e))return [];let o=e*n;return [t-o,t+o]}outer(){return this.data.outer||(this.median(),this.iqr(),this.data.outer=this.getOuter()),this.data.outer}getOuter(n=Z){let t=this.data.median,e=this.data.iqr;if(t===void 0||e===void 0||isNaN(e))return [];let o=2*e*n;return [t-o,t+o]}outside(){return this.data.outside||(this.outer(),this.data.outside=this.getOutside()),this.data.outside}getOutside(){let n=[],t=this.data.sorted,e=this.data.outer;if(!e||e.length===0)return [];let o=Math.min(...e),r=Math.max(...e);for(let s of t)(s>r||s<o)&&n.push(s);return n}inside(){return this.data.inside||(this.fences(),this.data.inside=this.getInside()),this.data.inside}getInside(){let n=[],t=this.data.sorted,e=this.data.fences;if(!e||e.length===0)return [];let o=Math.min(...e),r=Math.max(...e);for(let s of t)s<r&&s>o&&n.push(s);return n}outliers(){return this.data.outliers||(this.fences(),this.data.outliers=this.getOutliers()),this.data.outliers}getOutliers(){let n=[],t=this.data.sorted,e=this.data.fences;if(e.length===0)return [];let o=Math.min(...e),r=Math.max(...e);for(let s of t)(s>r||s<o)&&n.push(s);return n}ranked(){return this.data.ranked||(this.sorted(),this.data.ranked=this.getRanked(this.data.sorted)),this.data.ranked}getRanked(n,t=true){let e={},o={},r=n.length,s=[],c=NaN,i=[],d=()=>{c=NaN,i=[];};for(let h=0;h<n.length;h++){let l=n[h];if(!t)e[l]={rank:h+1,peers:0},o[l]={rank:r-h,peers:0};else {let m=h+1,N=h-1;l===n[N]?(!isNaN(c)&&i.length===0?(i.push(l),s.push(i),d()):(i.push(l),c=N),l!==n[m]&&(s.push(i),d())):l!==n[m]?i.length>0?(s.push(i),d()):s.push(l):i.push(l);}}let a=0;for(let h=0;h<s.length;h++){let l=s[h];if(typeof l=="number")o[l]={rank:h+1+a,peers:0},e[l]={rank:r-h-a,peers:0};else if(Array.isArray(l)){a+=l.length;let m=l[0];o[m]={rank:h+1+a,peers:l.length},e[m]={rank:r-h-a,peers:l.length};}else a+=1;}return {up:e,down:o,groups:{down:[...s],up:[...s].reverse()}}}adjacent(){return this.data.adjacent||(this.fences(),this.data.adjacent=this.getAdjacent(this.data.sorted,this.data.fences)),this.data.adjacent}getAdjacent(n,t){if(t.length===0)return [];let e=t[0],o=[],r=t[1],s=[];for(let c of n)c>e&&o.push(c),c<r&&s.push(c);return o.sort((c,i)=>c-i),s.sort((c,i)=>c-i),[o[0],s[s.length-1]]}binned(n=NaN){return this.data.binned||(this.sorted(),this.extremes(),this.data.binned=this.getBinned(this.data.sorted,n)),this.data.binned}getBinned(n,t=10,e=NaN,o=true){let r={},s=n.length,c=o?0:1;if(s===0)return {bins:0,width:NaN,binned:{}};let i=this.data.extremes,d=e;if(i&&isNaN(d)&&i.length===2){d=(i[1]-i[0])/(Math.log(n.length)/Math.LN2),d=Math.floor(d);let h=true;for(let l of n)if(l%1!==0){h=false;break}h&&(d=Math.floor(d));}let a=Math.floor(i[1]/d)+1;(!a||a<1)&&(a=1);for(let h of n){let l=Math.floor((h-c)/d);r[l]||(r[l]={from:l*d+c,to:(l+1)*d+c-1,data:[]}),r[l].data.push(h);}return {bins:a,width:d,binned:r}}logs(){return this.data.logs||(this.data.logs=this.getLogs(this.data.original)),this.data.logs}getLogs(n){return n.map(t=>Math.log(t))}roots(){return this.data.roots||(this.data.roots=this.getRoots(this.data.original)),this.data.roots}getRoots(n){return n.map(t=>Math.sqrt(t))}inverse(){return this.data.inverse||(this.data.inverse=this.getInverse(this.data.original)),this.data.inverse}getInverse(n){return n.map(t=>1/t)}hanning(){return this.data.hanning||(this.data.hanning=this.getSkipMeans(this.data.original)),this.data.hanning}getSkipMeans(n){let t=[];for(let e=0;e<n.length;e++)e!==0&&e!==n.length-1&&t.push((n[e]+n[e+1])/2);return t.unshift(n[0]),t.push(n[n.length-1]),t}smooth(){return this.data.smooth||(this.sorted(),this.data.smooth=this.getSmooth(this.data.original)),this.data.rough=this.getRough(this.data.original,this.data.smooth),this.data.smooth}getRough(n,t){let e=[];for(let o=0;o<n.length;o++)e.push(n[o]-t[o]);return e}getSmooth(n,t=3){let e=[...n];return e=this.smoothMedian(e,t),e=this.smoothExtremes(e,-1),e=this.smoothSplit(e,2),e=this.smoothMedian(e,t),e=this.smoothExtremes(e,-1),e=this.smoothMedian(e,t),e}smoothExtremes(n,t=1,e=0,o="both"){let r=n.length;if(r<=2)return [...n];let s=[...n];for(let c=e;c<t||t===-1;c++){let i=false;if(o==="both"||o==="head"){let d=s[0],a=s[1],h=s[2],l=a-2*(h-a),m=d<=a?a<=l?a:d<=l?l:d:d<=l?d:a<=l?l:a;s[0]!==m&&(s[0]=m,i=true);}if(o==="both"||o==="tail"){let d=s[r-3],a=s[r-2],h=s[r-1],l=a-2*(d-a),m=h<=a?a<=l?a:h<=l?l:h:h<=l?h:a<=l?l:a;s[r-1]!==m&&(s[r-1]=m,i=true);}if(t===-1&&!i)break}return s}smoothSplit(n,t=ye,e=0){let o=[...n],r=n.length;for(let s=e;s<t||t===-1;s++){let c=false;for(let i=2;i<r-1;i++){let d=o[i],a=o[i-1],h=o[i-2],l=o[i+1];if(d===a&&(a>h&&d>l||a<h&&d<l)){let m=this.smoothExtremes(o.slice(0,i)),N=this.smoothExtremes(o.slice(i));o=m.concat(N),c=true;}}if(t===-1&&!c)return o}return o}smoothMedian(n,t=1,e=0){let o=n,r=n.length;if(r<=2)return [...n];for(let s=e;s<t||t===-1;s++){let c=new Array(r);c[0]=o[0],c[r-1]=o[r-1];let i=false;for(let d=1;d<r-1;d++){let a=o[d],h=Math.min(Math.max(o[d-1],a),o[d+1]);c[d]=h,h!==a&&(i=true);}if(t===-1&&!i)return o;o=c;}return o}jitter(n,t=1,e=NaN,o=Me,r=NaN,s=0){let c=s+1,i=[...n];if(c<=t){let d=[];for(let a of i){let h=r;!h&&!isNaN(h)&&(h=(1+Math.floor(a/10))*(Math.random()>.5?1:-1));let l=a+Math.floor(Math.random()*o*h);!isNaN(e)&&l<e&&(l=e),d.push(l);}return this.jitter(d,t,e,o,r,c)}return i}trimean(){let n=this.median(),t=this.hinges();return t.length<2?n.datum:(t[0].datum+2*n.datum+t[1].datum)/4}letterValues(){this.sorted();let n=this.data.sorted.length;if(n<2)return [];let t=["M","F","E","D","C","B","A","Z","Y","X","W","V","U","T","S"],e=[],o=(n+1)/2,r=this.median().datum;e.push({letter:"M",depth:o,lower:r,upper:r,mid:r,spread:0});let s=o,c=1;for(;s>1&&c<t.length&&(s=Math.floor((Math.floor(s)+1)/2),!(s<1));){let i=Math.ceil(s)-1,d=n-Math.ceil(s);if(i<0||d>=n||i>=d)break;let a=this.data.sorted[i],h=this.data.sorted[d],l=(a+h)/2,m=h-a;e.push({letter:t[c],depth:s,lower:a,upper:h,mid:l,spread:m}),c++;}return e}rough(){return this.data.rough||this.smooth(),this.data.rough||[]}stemLeaf(n=1){this.sorted();let t=this.data.sorted;if(!t.length)return {stems:[],leaves:{},display:[]};let e=Math.pow(10,n),o=new Map;for(let d of t){let a=Math.floor(d/e),h=Math.abs(Math.round(d%e));o.has(a)||o.set(a,[]),o.get(a).push(h);}let r=Array.from(o.keys()).sort((d,a)=>d-a),s=[],c={},i=[];for(let d of r){let a=String(d);s.push(a);let h=o.get(d).sort((l,m)=>l-m).map(String);c[a]=h,i.push(`${a.padStart(4)} | ${h.join(" ")}`);}return {stems:s,leaves:c,display:i}}midSummaries(){return this.letterValues().map(({depth:t,mid:e,spread:o})=>({depth:t,mid:e,spread:o}))}describe(){return this.data.description={original:this.data.original,summary:{median:this.median(),mean:this.mean(),mode:this.mode(),hinges:this.hinges(),adjacent:this.adjacent(),outliers:this.outliers(),outer:this.outer(),outside:this.outside(),inside:this.inside(),extremes:this.extremes(),iqr:this.iqr(),fences:this.fences()},smooths:{smooth:this.smooth(),hanning:this.hanning()},transforms:{logs:this.logs(),roots:this.roots(),inverse:this.inverse()},counts:this.counts(),sorted:this.sorted(),ranked:this.ranked(),binned:this.binned()},this.data.description}},ne=class{data;dimension;count;constructor(n={}){typeof n=="number"?(this.count=n,this.dimension=K,this.data={original:ee(this.count,this.dimension)}):(this.dimension=n.dimensionality??2,this.count=n.count??100,this.data={original:n.data??ee(this.count,this.dimension)});}describe(){return this.data.description={original:this.data.original},this.data.description}},oe=class{smoothed=false;static DEFAULT_MAX_RANDOM_INTEGER=B;static DEFAULT_MIN_RANDOM_INTEGER=tt;static DEFAULT_RANDOM_SERIES_COUNT=re;static DEFAULT_OUTLIER_MULTIPLE=Z;static DEFAULT_JITTER_MULTIPLIER=Me;static DEFAULT_SPLIT_PASSES=ye;static DEFAULT_MAX_RANDOM_DIMENSIONALITY=K;static Series=te;static Points=ne;static randomInteger=we;static randomSeries=Re;static randomPoint=Se;static randomPoints=ee},ht=oe;export{E as GraphAlgorithmError,Q as GraphCatalog,ne as Points,te as Series,oe as Twokeys,Ie as aStarShortestPath,Ne as allPairsShortestPaths,rt as analyzeGraph,Qe as articulationPointsAndBridges,Je as betweennessCentrality,v as buildGraphAdjacency,Xe as closenessCentrality,et as createGraphCatalog,ht as default,He as degreeCentrality,ut as gds,st as kMeansAuto,Ze as kMeansClustering,fe as kNearestNeighbors,he as labelPropagationCommunities,it as linkPrediction,me as louvainCommunities,be as maximumFlow,xe as minCostMaxFlow,ot as minimumSpanningTree,ge as nodeSimilarity,X as pageRank,J as predictLinks,j as shortestPath,le as stronglyConnectedComponents,nt as topologicalSort,dt as travelingSalesmanApprox,$e as weaklyConnectedComponents,pe as yenKShortestPaths};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map