effect 4.0.0-beta.98 → 4.0.0-beta.99
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 +1 -3
- package/dist/Array.js +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Graph.d.ts +1187 -196
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +1031 -283
- package/dist/Graph.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +41 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/Schema.js +1 -1
- package/dist/Schema.js.map +1 -1
- package/dist/internal/effect.js +9 -3
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +128 -128
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -13
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliConfig.d.ts +76 -0
- package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
- package/dist/unstable/cli/CliConfig.js +63 -0
- package/dist/unstable/cli/CliConfig.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +3 -0
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +36 -1
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +61 -4
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +23 -2
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +20 -4
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/Param.js +6 -2
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -0
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +11 -2
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.d.ts +13 -0
- package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
- package/dist/unstable/cli/internal/wizard.js +212 -0
- package/dist/unstable/cli/internal/wizard.js.map +1 -0
- package/dist/unstable/cluster/RunnerStorage.js +1 -1
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +3 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +5 -3
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -2
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/package.json +3 -3
- package/src/Array.ts +1 -1
- package/src/Graph.ts +2967 -457
- package/src/Iterable.ts +32 -2
- package/src/Schema.ts +1 -1
- package/src/internal/effect.ts +9 -3
- package/src/unstable/ai/Tool.ts +13 -16
- package/src/unstable/cli/CliConfig.ts +85 -0
- package/src/unstable/cli/CliError.ts +3 -0
- package/src/unstable/cli/Command.ts +83 -7
- package/src/unstable/cli/GlobalFlag.ts +33 -5
- package/src/unstable/cli/Param.ts +15 -3
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/ansi.ts +3 -0
- package/src/unstable/cli/internal/parser.ts +14 -2
- package/src/unstable/cli/internal/wizard.ts +283 -0
- package/src/unstable/cluster/RunnerStorage.ts +1 -1
- package/src/unstable/http/Multipart.ts +3 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +1 -1
- package/src/unstable/persistence/Redis.ts +9 -4
- package/src/unstable/sql/SqlClient.ts +1 -2
package/dist/Graph.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import * as Equal from "./Equal.ts";
|
|
|
13
13
|
import type { Inspectable } from "./Inspectable.ts";
|
|
14
14
|
import * as Option from "./Option.ts";
|
|
15
15
|
import type { Pipeable } from "./Pipeable.ts";
|
|
16
|
+
import type { Covariant, Invariant } from "./Types.ts";
|
|
16
17
|
declare const TypeId = "~effect/collections/Graph";
|
|
17
18
|
/**
|
|
18
19
|
* Node index for node identification using plain numbers.
|
|
@@ -97,25 +98,19 @@ export declare class Edge<E> extends Data.Class<{
|
|
|
97
98
|
*/
|
|
98
99
|
export type Kind = "directed" | "undirected";
|
|
99
100
|
/**
|
|
100
|
-
* Common
|
|
101
|
+
* Common public protocol for graph values.
|
|
101
102
|
*
|
|
102
103
|
* **Details**
|
|
103
104
|
*
|
|
104
|
-
* Contains the
|
|
105
|
-
*
|
|
105
|
+
* Contains only the runtime marker and shared protocols. Graph storage is kept
|
|
106
|
+
* internal; use module functions such as `nodes`, `edges`, `getNode`, and
|
|
107
|
+
* `getEdge` to inspect graph contents.
|
|
106
108
|
*
|
|
107
109
|
* @category models
|
|
108
110
|
* @since 3.18.0
|
|
109
111
|
*/
|
|
110
112
|
export interface Proto<out N, out E> extends Iterable<readonly [NodeIndex, N]>, Equal.Equal, Pipeable, Inspectable {
|
|
111
|
-
readonly [TypeId]:
|
|
112
|
-
readonly nodes: Map<NodeIndex, N>;
|
|
113
|
-
readonly edges: Map<EdgeIndex, Edge<E>>;
|
|
114
|
-
readonly adjacency: Map<NodeIndex, Array<EdgeIndex>>;
|
|
115
|
-
readonly reverseAdjacency: Map<NodeIndex, Array<EdgeIndex>>;
|
|
116
|
-
nextNodeIndex: NodeIndex;
|
|
117
|
-
nextEdgeIndex: EdgeIndex;
|
|
118
|
-
acyclic: Option.Option<boolean>;
|
|
113
|
+
readonly [TypeId]: Graph.Variance<N, E>;
|
|
119
114
|
}
|
|
120
115
|
/**
|
|
121
116
|
* Immutable graph interface.
|
|
@@ -136,6 +131,24 @@ export interface Graph<out N, out E, T extends Kind = "directed"> extends Proto<
|
|
|
136
131
|
readonly type: T;
|
|
137
132
|
readonly mutable: false;
|
|
138
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Companion namespace containing type-level metadata for immutable graphs.
|
|
136
|
+
*
|
|
137
|
+
* @category models
|
|
138
|
+
* @since 4.0.0
|
|
139
|
+
*/
|
|
140
|
+
export declare namespace Graph {
|
|
141
|
+
/**
|
|
142
|
+
* Type-level variance marker for immutable graphs.
|
|
143
|
+
*
|
|
144
|
+
* @category models
|
|
145
|
+
* @since 4.0.0
|
|
146
|
+
*/
|
|
147
|
+
interface Variance<out N, out E> {
|
|
148
|
+
readonly _N: Covariant<N>;
|
|
149
|
+
readonly _E: Covariant<E>;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
139
152
|
/**
|
|
140
153
|
* Mutable graph interface.
|
|
141
154
|
*
|
|
@@ -152,10 +165,29 @@ export interface Graph<out N, out E, T extends Kind = "directed"> extends Proto<
|
|
|
152
165
|
* @category models
|
|
153
166
|
* @since 3.18.0
|
|
154
167
|
*/
|
|
155
|
-
export interface MutableGraph<out N, out E, T extends Kind = "directed"> extends
|
|
168
|
+
export interface MutableGraph<in out N, in out E, T extends Kind = "directed"> extends Iterable<readonly [NodeIndex, N]>, Equal.Equal, Pipeable, Inspectable {
|
|
169
|
+
readonly [TypeId]: MutableGraph.Variance<N, E>;
|
|
156
170
|
readonly type: T;
|
|
157
171
|
readonly mutable: true;
|
|
158
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Companion namespace containing type-level metadata for scoped mutable graphs.
|
|
175
|
+
*
|
|
176
|
+
* @category models
|
|
177
|
+
* @since 4.0.0
|
|
178
|
+
*/
|
|
179
|
+
export declare namespace MutableGraph {
|
|
180
|
+
/**
|
|
181
|
+
* Type-level variance marker for scoped mutable graphs.
|
|
182
|
+
*
|
|
183
|
+
* @category models
|
|
184
|
+
* @since 4.0.0
|
|
185
|
+
*/
|
|
186
|
+
interface Variance<in out N, in out E> {
|
|
187
|
+
readonly _N: Invariant<N>;
|
|
188
|
+
readonly _E: Invariant<E>;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
159
191
|
/**
|
|
160
192
|
* Immutable graph type for source-to-target relationships.
|
|
161
193
|
*
|
|
@@ -251,170 +283,1063 @@ export declare class GraphError extends GraphError_base<{
|
|
|
251
283
|
}> {
|
|
252
284
|
}
|
|
253
285
|
/**
|
|
254
|
-
* Returns `true` if a value has the graph runtime type identifier, narrowing
|
|
255
|
-
* it to
|
|
256
|
-
*
|
|
257
|
-
* **When to use**
|
|
258
|
-
*
|
|
259
|
-
* Use to narrow an unknown value before treating it as a graph value.
|
|
286
|
+
* Returns `true` if a value has the graph runtime type identifier, narrowing
|
|
287
|
+
* it to an immutable or mutable graph.
|
|
288
|
+
*
|
|
289
|
+
* **When to use**
|
|
290
|
+
*
|
|
291
|
+
* Use to narrow an unknown value before treating it as a graph value.
|
|
292
|
+
*
|
|
293
|
+
* **Gotchas**
|
|
294
|
+
*
|
|
295
|
+
* This guard checks the shared graph runtime type identifier and does not
|
|
296
|
+
* distinguish immutable graphs from mutable graphs or directed graphs from
|
|
297
|
+
* undirected graphs.
|
|
298
|
+
*
|
|
299
|
+
* @category guards
|
|
300
|
+
* @since 4.0.0
|
|
301
|
+
*/
|
|
302
|
+
export declare const isGraph: <N = unknown, E = unknown, T extends Kind = Kind, U = never>(u: U | Graph<N, E, T> | MutableGraph<N, E, T>) => u is Graph<N, E, T> | MutableGraph<N, E, T>;
|
|
303
|
+
/**
|
|
304
|
+
* Creates a graph constructor for the specified graph kind.
|
|
305
|
+
*
|
|
306
|
+
* **When to use**
|
|
307
|
+
*
|
|
308
|
+
* Use when the graph kind is selected dynamically. Prefer `directed` or
|
|
309
|
+
* `undirected` when the kind is known statically.
|
|
310
|
+
*
|
|
311
|
+
* **Example** (Constructing by kind)
|
|
312
|
+
*
|
|
313
|
+
* ```ts
|
|
314
|
+
* import { Graph } from "effect"
|
|
315
|
+
*
|
|
316
|
+
* const makeGraph = Graph.make("directed")
|
|
317
|
+
* const graph = makeGraph<string, number>((mutable) => {
|
|
318
|
+
* Graph.addNode(mutable, "A")
|
|
319
|
+
* })
|
|
320
|
+
*
|
|
321
|
+
* console.log(graph.type) // "directed"
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @see {@link directed} for constructing a directed graph directly
|
|
325
|
+
* @see {@link undirected} for constructing an undirected graph directly
|
|
326
|
+
* @category constructors
|
|
327
|
+
* @since 4.0.0
|
|
328
|
+
*/
|
|
329
|
+
export declare const make: <T extends Kind>(type: T) => <N, E>(mutate?: (mutable: MutableGraph<N, E, T>) => undefined) => Graph<N, E, T>;
|
|
330
|
+
/**
|
|
331
|
+
* Creates a directed graph, optionally with initial mutations.
|
|
332
|
+
*
|
|
333
|
+
* **Example** (Creating a directed graph)
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* import { Graph } from "effect"
|
|
337
|
+
*
|
|
338
|
+
* // Directed graph with initial nodes and edges
|
|
339
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
340
|
+
* const a = Graph.addNode(mutable, "A")
|
|
341
|
+
* const b = Graph.addNode(mutable, "B")
|
|
342
|
+
* const c = Graph.addNode(mutable, "C")
|
|
343
|
+
* Graph.addEdge(mutable, a, b, "A->B")
|
|
344
|
+
* Graph.addEdge(mutable, b, c, "B->C")
|
|
345
|
+
* })
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @category constructors
|
|
349
|
+
* @since 3.18.0
|
|
350
|
+
*/
|
|
351
|
+
export declare const directed: <N, E>(mutate?: (mutable: MutableDirectedGraph<N, E>) => undefined) => DirectedGraph<N, E>;
|
|
352
|
+
/**
|
|
353
|
+
* Creates an undirected graph, optionally with initial mutations.
|
|
354
|
+
*
|
|
355
|
+
* **Example** (Creating an undirected graph)
|
|
356
|
+
*
|
|
357
|
+
* ```ts
|
|
358
|
+
* import { Graph } from "effect"
|
|
359
|
+
*
|
|
360
|
+
* // Undirected graph with initial nodes and edges
|
|
361
|
+
* const graph = Graph.undirected<string, string>((mutable) => {
|
|
362
|
+
* const a = Graph.addNode(mutable, "A")
|
|
363
|
+
* const b = Graph.addNode(mutable, "B")
|
|
364
|
+
* const c = Graph.addNode(mutable, "C")
|
|
365
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
366
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
367
|
+
* })
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @category constructors
|
|
371
|
+
* @since 3.18.0
|
|
372
|
+
*/
|
|
373
|
+
export declare const undirected: <N, E>(mutate?: (mutable: MutableUndirectedGraph<N, E>) => undefined) => UndirectedGraph<N, E>;
|
|
374
|
+
/**
|
|
375
|
+
* Creates a mutable scope for safe graph mutations by copying the data structure.
|
|
376
|
+
*
|
|
377
|
+
* **Example** (Beginning a mutation scope)
|
|
378
|
+
*
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { Graph } from "effect"
|
|
381
|
+
*
|
|
382
|
+
* const graph = Graph.directed<string, number>()
|
|
383
|
+
* const mutable = Graph.beginMutation(graph)
|
|
384
|
+
* // Now mutable can be safely modified without affecting original graph
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @category mutations
|
|
388
|
+
* @since 3.18.0
|
|
389
|
+
*/
|
|
390
|
+
export declare const beginMutation: <N, E, T extends Kind = "directed">(graph: Graph<N, E, T>) => MutableGraph<N, E, T>;
|
|
391
|
+
/**
|
|
392
|
+
* Converts a mutable graph back to an immutable graph, ending the mutation scope.
|
|
393
|
+
*
|
|
394
|
+
* **Details**
|
|
395
|
+
*
|
|
396
|
+
* Finalizes the mutable handle. Later public mutation operations on that handle
|
|
397
|
+
* fail with a `GraphError`.
|
|
398
|
+
*
|
|
399
|
+
* **Example** (Ending a mutation scope)
|
|
400
|
+
*
|
|
401
|
+
* ```ts
|
|
402
|
+
* import { Graph } from "effect"
|
|
403
|
+
*
|
|
404
|
+
* const graph = Graph.directed<string, number>()
|
|
405
|
+
* const mutable = Graph.beginMutation(graph)
|
|
406
|
+
* // ... perform mutations on mutable ...
|
|
407
|
+
* const newGraph = Graph.endMutation(mutable)
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @category mutations
|
|
411
|
+
* @since 3.18.0
|
|
412
|
+
*/
|
|
413
|
+
export declare const endMutation: <N, E, T extends Kind = "directed">(mutable: MutableGraph<N, E, T>) => Graph<N, E, T>;
|
|
414
|
+
/**
|
|
415
|
+
* Performs scoped mutations on a graph, automatically managing the mutation lifecycle.
|
|
416
|
+
*
|
|
417
|
+
* **Example** (Applying scoped mutations)
|
|
418
|
+
*
|
|
419
|
+
* ```ts
|
|
420
|
+
* import { Graph } from "effect"
|
|
421
|
+
*
|
|
422
|
+
* const graph = Graph.directed<string, number>()
|
|
423
|
+
* const newGraph = Graph.mutate(graph, (mutable) => {
|
|
424
|
+
* const nodeA = Graph.addNode(mutable, "A")
|
|
425
|
+
* const nodeB = Graph.addNode(mutable, "B")
|
|
426
|
+
* Graph.addEdge(mutable, nodeA, nodeB, 1)
|
|
427
|
+
* })
|
|
428
|
+
*
|
|
429
|
+
* console.log(Graph.nodeCount(newGraph)) // 2
|
|
430
|
+
* console.log(Graph.edgeCount(newGraph)) // 1
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @category mutations
|
|
434
|
+
* @since 3.18.0
|
|
435
|
+
*/
|
|
436
|
+
export declare const mutate: {
|
|
437
|
+
/**
|
|
438
|
+
* Performs scoped mutations on a graph, automatically managing the mutation lifecycle.
|
|
439
|
+
*
|
|
440
|
+
* **Example** (Applying scoped mutations)
|
|
441
|
+
*
|
|
442
|
+
* ```ts
|
|
443
|
+
* import { Graph } from "effect"
|
|
444
|
+
*
|
|
445
|
+
* const graph = Graph.directed<string, number>()
|
|
446
|
+
* const newGraph = Graph.mutate(graph, (mutable) => {
|
|
447
|
+
* const nodeA = Graph.addNode(mutable, "A")
|
|
448
|
+
* const nodeB = Graph.addNode(mutable, "B")
|
|
449
|
+
* Graph.addEdge(mutable, nodeA, nodeB, 1)
|
|
450
|
+
* })
|
|
451
|
+
*
|
|
452
|
+
* console.log(Graph.nodeCount(newGraph)) // 2
|
|
453
|
+
* console.log(Graph.edgeCount(newGraph)) // 1
|
|
454
|
+
* ```
|
|
455
|
+
*
|
|
456
|
+
* @category mutations
|
|
457
|
+
* @since 3.18.0
|
|
458
|
+
*/
|
|
459
|
+
<N, E, T extends Kind = "directed">(f: (mutable: MutableGraph<N, E, T>) => undefined): (graph: Graph<N, E, T>) => Graph<N, E, T>;
|
|
460
|
+
/**
|
|
461
|
+
* Performs scoped mutations on a graph, automatically managing the mutation lifecycle.
|
|
462
|
+
*
|
|
463
|
+
* **Example** (Applying scoped mutations)
|
|
464
|
+
*
|
|
465
|
+
* ```ts
|
|
466
|
+
* import { Graph } from "effect"
|
|
467
|
+
*
|
|
468
|
+
* const graph = Graph.directed<string, number>()
|
|
469
|
+
* const newGraph = Graph.mutate(graph, (mutable) => {
|
|
470
|
+
* const nodeA = Graph.addNode(mutable, "A")
|
|
471
|
+
* const nodeB = Graph.addNode(mutable, "B")
|
|
472
|
+
* Graph.addEdge(mutable, nodeA, nodeB, 1)
|
|
473
|
+
* })
|
|
474
|
+
*
|
|
475
|
+
* console.log(Graph.nodeCount(newGraph)) // 2
|
|
476
|
+
* console.log(Graph.edgeCount(newGraph)) // 1
|
|
477
|
+
* ```
|
|
478
|
+
*
|
|
479
|
+
* @category mutations
|
|
480
|
+
* @since 3.18.0
|
|
481
|
+
*/
|
|
482
|
+
<N, E, T extends Kind = "directed">(graph: Graph<N, E, T>, f: (mutable: MutableGraph<N, E, T>) => undefined): Graph<N, E, T>;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Configures node and edge identity for graph set operations.
|
|
486
|
+
*
|
|
487
|
+
* **Details**
|
|
488
|
+
*
|
|
489
|
+
* Both functions default to using the complete node or edge data. Edge identity
|
|
490
|
+
* also includes the identities of its endpoint nodes and the graph kind.
|
|
491
|
+
*
|
|
492
|
+
* **Gotchas**
|
|
493
|
+
*
|
|
494
|
+
* Edge identity defines set membership, not edge multiplicity. Parallel edges
|
|
495
|
+
* with the same endpoint identities and projected edge identity are treated as
|
|
496
|
+
* the same member by graph set operations.
|
|
497
|
+
*
|
|
498
|
+
* @category models
|
|
499
|
+
* @since 4.0.0
|
|
500
|
+
*/
|
|
501
|
+
export interface IdentityOptions<N, E, NI = N, EI = E> {
|
|
502
|
+
readonly nodeIdentity?: (node: N) => NI;
|
|
503
|
+
readonly edgeIdentity?: (edge: E) => EI;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Composes two graphs, merging nodes by identity.
|
|
507
|
+
*
|
|
508
|
+
* **Details**
|
|
509
|
+
*
|
|
510
|
+
* Nodes and edges present in both graphs use data from `that`. The result has
|
|
511
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
512
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
513
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
514
|
+
*
|
|
515
|
+
* `G1 ∪ G2 = {V1 ∪ V2, E1 ∪ E2}`
|
|
516
|
+
*
|
|
517
|
+
* **Gotchas**
|
|
518
|
+
*
|
|
519
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
520
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
521
|
+
* Parallel edges with equal identities are also coalesced, with the last edge
|
|
522
|
+
* supplying the data.
|
|
523
|
+
*
|
|
524
|
+
* **Example** (Combining graphs)
|
|
525
|
+
*
|
|
526
|
+
* ```ts
|
|
527
|
+
* import { Graph } from "effect"
|
|
528
|
+
*
|
|
529
|
+
* const left = Graph.directed<{ id: string }, string>((mutable) => {
|
|
530
|
+
* const a = Graph.addNode(mutable, { id: "A" })
|
|
531
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
532
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
533
|
+
* })
|
|
534
|
+
*
|
|
535
|
+
* const right = Graph.directed<{ id: string }, string>((mutable) => {
|
|
536
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
537
|
+
* const c = Graph.addNode(mutable, { id: "C" })
|
|
538
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
539
|
+
* })
|
|
540
|
+
*
|
|
541
|
+
* const result = Graph.compose(left, right, {
|
|
542
|
+
* nodeIdentity: (node) => node.id
|
|
543
|
+
* })
|
|
544
|
+
*
|
|
545
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
546
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
547
|
+
* ```
|
|
548
|
+
*
|
|
549
|
+
* @category set operations
|
|
550
|
+
* @since 4.0.0
|
|
551
|
+
*/
|
|
552
|
+
export declare const compose: {
|
|
553
|
+
/**
|
|
554
|
+
* Composes two graphs, merging nodes by identity.
|
|
555
|
+
*
|
|
556
|
+
* **Details**
|
|
557
|
+
*
|
|
558
|
+
* Nodes and edges present in both graphs use data from `that`. The result has
|
|
559
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
560
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
561
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
562
|
+
*
|
|
563
|
+
* `G1 ∪ G2 = {V1 ∪ V2, E1 ∪ E2}`
|
|
564
|
+
*
|
|
565
|
+
* **Gotchas**
|
|
566
|
+
*
|
|
567
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
568
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
569
|
+
* Parallel edges with equal identities are also coalesced, with the last edge
|
|
570
|
+
* supplying the data.
|
|
571
|
+
*
|
|
572
|
+
* **Example** (Combining graphs)
|
|
573
|
+
*
|
|
574
|
+
* ```ts
|
|
575
|
+
* import { Graph } from "effect"
|
|
576
|
+
*
|
|
577
|
+
* const left = Graph.directed<{ id: string }, string>((mutable) => {
|
|
578
|
+
* const a = Graph.addNode(mutable, { id: "A" })
|
|
579
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
580
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
581
|
+
* })
|
|
582
|
+
*
|
|
583
|
+
* const right = Graph.directed<{ id: string }, string>((mutable) => {
|
|
584
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
585
|
+
* const c = Graph.addNode(mutable, { id: "C" })
|
|
586
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
587
|
+
* })
|
|
588
|
+
*
|
|
589
|
+
* const result = Graph.compose(left, right, {
|
|
590
|
+
* nodeIdentity: (node) => node.id
|
|
591
|
+
* })
|
|
592
|
+
*
|
|
593
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
594
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* @category set operations
|
|
598
|
+
* @since 4.0.0
|
|
599
|
+
*/
|
|
600
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(that: Graph<N, E, T>, options?: IdentityOptions<N, E, NI, EI>): (self: Graph<N, E, NoInfer<T>>) => Graph<N, E, T>;
|
|
601
|
+
/**
|
|
602
|
+
* Composes two graphs, merging nodes by identity.
|
|
603
|
+
*
|
|
604
|
+
* **Details**
|
|
605
|
+
*
|
|
606
|
+
* Nodes and edges present in both graphs use data from `that`. The result has
|
|
607
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
608
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
609
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
610
|
+
*
|
|
611
|
+
* `G1 ∪ G2 = {V1 ∪ V2, E1 ∪ E2}`
|
|
612
|
+
*
|
|
613
|
+
* **Gotchas**
|
|
614
|
+
*
|
|
615
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
616
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
617
|
+
* Parallel edges with equal identities are also coalesced, with the last edge
|
|
618
|
+
* supplying the data.
|
|
619
|
+
*
|
|
620
|
+
* **Example** (Combining graphs)
|
|
621
|
+
*
|
|
622
|
+
* ```ts
|
|
623
|
+
* import { Graph } from "effect"
|
|
624
|
+
*
|
|
625
|
+
* const left = Graph.directed<{ id: string }, string>((mutable) => {
|
|
626
|
+
* const a = Graph.addNode(mutable, { id: "A" })
|
|
627
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
628
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
629
|
+
* })
|
|
630
|
+
*
|
|
631
|
+
* const right = Graph.directed<{ id: string }, string>((mutable) => {
|
|
632
|
+
* const b = Graph.addNode(mutable, { id: "B" })
|
|
633
|
+
* const c = Graph.addNode(mutable, { id: "C" })
|
|
634
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
635
|
+
* })
|
|
636
|
+
*
|
|
637
|
+
* const result = Graph.compose(left, right, {
|
|
638
|
+
* nodeIdentity: (node) => node.id
|
|
639
|
+
* })
|
|
640
|
+
*
|
|
641
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
642
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
643
|
+
* ```
|
|
644
|
+
*
|
|
645
|
+
* @category set operations
|
|
646
|
+
* @since 4.0.0
|
|
647
|
+
*/
|
|
648
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(self: Graph<N, E, T>, that: Graph<N, E, NoInfer<T>>, options?: IdentityOptions<N, E, NI, EI>): Graph<N, E, T>;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Returns the intersection of two graphs, matching nodes by identity.
|
|
652
|
+
*
|
|
653
|
+
* **Details**
|
|
654
|
+
*
|
|
655
|
+
* Node data comes from `self`, and edge data comes from `that`. The result has
|
|
656
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
657
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
658
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
659
|
+
*
|
|
660
|
+
* `G1 ∩ G2 = {V1 ∩ V2, E1 ∩ E2}`
|
|
661
|
+
*
|
|
662
|
+
* **Gotchas**
|
|
663
|
+
*
|
|
664
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
665
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
666
|
+
* The result contains at most one edge for each shared edge identity.
|
|
667
|
+
*
|
|
668
|
+
* **Example** (Finding shared structure)
|
|
669
|
+
*
|
|
670
|
+
* ```ts
|
|
671
|
+
* import { Graph } from "effect"
|
|
672
|
+
*
|
|
673
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
674
|
+
* const a = Graph.addNode(mutable, "A")
|
|
675
|
+
* const b = Graph.addNode(mutable, "B")
|
|
676
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
677
|
+
* })
|
|
678
|
+
*
|
|
679
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
680
|
+
* const a = Graph.addNode(mutable, "A")
|
|
681
|
+
* const b = Graph.addNode(mutable, "B")
|
|
682
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
683
|
+
* })
|
|
684
|
+
*
|
|
685
|
+
* const result = Graph.intersection(left, right)
|
|
686
|
+
*
|
|
687
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
688
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
689
|
+
* ```
|
|
690
|
+
*
|
|
691
|
+
* @category set operations
|
|
692
|
+
* @since 4.0.0
|
|
693
|
+
*/
|
|
694
|
+
export declare const intersection: {
|
|
695
|
+
/**
|
|
696
|
+
* Returns the intersection of two graphs, matching nodes by identity.
|
|
697
|
+
*
|
|
698
|
+
* **Details**
|
|
699
|
+
*
|
|
700
|
+
* Node data comes from `self`, and edge data comes from `that`. The result has
|
|
701
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
702
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
703
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
704
|
+
*
|
|
705
|
+
* `G1 ∩ G2 = {V1 ∩ V2, E1 ∩ E2}`
|
|
706
|
+
*
|
|
707
|
+
* **Gotchas**
|
|
708
|
+
*
|
|
709
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
710
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
711
|
+
* The result contains at most one edge for each shared edge identity.
|
|
712
|
+
*
|
|
713
|
+
* **Example** (Finding shared structure)
|
|
714
|
+
*
|
|
715
|
+
* ```ts
|
|
716
|
+
* import { Graph } from "effect"
|
|
717
|
+
*
|
|
718
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
719
|
+
* const a = Graph.addNode(mutable, "A")
|
|
720
|
+
* const b = Graph.addNode(mutable, "B")
|
|
721
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
722
|
+
* })
|
|
723
|
+
*
|
|
724
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
725
|
+
* const a = Graph.addNode(mutable, "A")
|
|
726
|
+
* const b = Graph.addNode(mutable, "B")
|
|
727
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
728
|
+
* })
|
|
729
|
+
*
|
|
730
|
+
* const result = Graph.intersection(left, right)
|
|
731
|
+
*
|
|
732
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
733
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
734
|
+
* ```
|
|
735
|
+
*
|
|
736
|
+
* @category set operations
|
|
737
|
+
* @since 4.0.0
|
|
738
|
+
*/
|
|
739
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(that: Graph<N, E, T>, options?: IdentityOptions<N, E, NI, EI>): (self: Graph<N, E, NoInfer<T>>) => Graph<N, E, T>;
|
|
740
|
+
/**
|
|
741
|
+
* Returns the intersection of two graphs, matching nodes by identity.
|
|
742
|
+
*
|
|
743
|
+
* **Details**
|
|
744
|
+
*
|
|
745
|
+
* Node data comes from `self`, and edge data comes from `that`. The result has
|
|
746
|
+
* the same graph kind as `self`. Throws a `GraphError` when the graph kinds do
|
|
747
|
+
* not match. `nodeIdentity` and `edgeIdentity` default to the complete node and
|
|
748
|
+
* edge data. Edge identity also includes the endpoint identities.
|
|
749
|
+
*
|
|
750
|
+
* `G1 ∩ G2 = {V1 ∩ V2, E1 ∩ E2}`
|
|
751
|
+
*
|
|
752
|
+
* **Gotchas**
|
|
753
|
+
*
|
|
754
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
755
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
756
|
+
* The result contains at most one edge for each shared edge identity.
|
|
757
|
+
*
|
|
758
|
+
* **Example** (Finding shared structure)
|
|
759
|
+
*
|
|
760
|
+
* ```ts
|
|
761
|
+
* import { Graph } from "effect"
|
|
762
|
+
*
|
|
763
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
764
|
+
* const a = Graph.addNode(mutable, "A")
|
|
765
|
+
* const b = Graph.addNode(mutable, "B")
|
|
766
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
767
|
+
* })
|
|
768
|
+
*
|
|
769
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
770
|
+
* const a = Graph.addNode(mutable, "A")
|
|
771
|
+
* const b = Graph.addNode(mutable, "B")
|
|
772
|
+
* Graph.addEdge(mutable, a, b, "shared")
|
|
773
|
+
* })
|
|
774
|
+
*
|
|
775
|
+
* const result = Graph.intersection(left, right)
|
|
776
|
+
*
|
|
777
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
778
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
779
|
+
* ```
|
|
780
|
+
*
|
|
781
|
+
* @category set operations
|
|
782
|
+
* @since 4.0.0
|
|
783
|
+
*/
|
|
784
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(self: Graph<N, E, T>, that: Graph<N, E, NoInfer<T>>, options?: IdentityOptions<N, E, NI, EI>): Graph<N, E, T>;
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* Returns `self` without edges also present in `that`.
|
|
788
|
+
*
|
|
789
|
+
* **Details**
|
|
790
|
+
*
|
|
791
|
+
* All nodes from `self` are preserved. Edges are matched by endpoint and edge
|
|
792
|
+
* identities. The result has the same graph kind as `self`. Throws a
|
|
793
|
+
* `GraphError` when the graph kinds do not match. `nodeIdentity` and
|
|
794
|
+
* `edgeIdentity` default to the complete node and edge data.
|
|
795
|
+
*
|
|
796
|
+
* `G1 \ G2 = {V1, E1 \ E2}`
|
|
797
|
+
*
|
|
798
|
+
* **Gotchas**
|
|
799
|
+
*
|
|
800
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
801
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
802
|
+
* If `that` contains an edge identity, every parallel edge with that identity
|
|
803
|
+
* is removed from `self`.
|
|
804
|
+
*
|
|
805
|
+
* **Example** (Removing shared edges)
|
|
806
|
+
*
|
|
807
|
+
* ```ts
|
|
808
|
+
* import { Graph } from "effect"
|
|
809
|
+
*
|
|
810
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
811
|
+
* const a = Graph.addNode(mutable, "A")
|
|
812
|
+
* const b = Graph.addNode(mutable, "B")
|
|
813
|
+
* const c = Graph.addNode(mutable, "C")
|
|
814
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
815
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
816
|
+
* })
|
|
817
|
+
*
|
|
818
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
819
|
+
* const b = Graph.addNode(mutable, "B")
|
|
820
|
+
* const c = Graph.addNode(mutable, "C")
|
|
821
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
822
|
+
* })
|
|
823
|
+
*
|
|
824
|
+
* const result = Graph.difference(left, right)
|
|
825
|
+
*
|
|
826
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
827
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
828
|
+
* ```
|
|
829
|
+
*
|
|
830
|
+
* @category set operations
|
|
831
|
+
* @since 4.0.0
|
|
832
|
+
*/
|
|
833
|
+
export declare const difference: {
|
|
834
|
+
/**
|
|
835
|
+
* Returns `self` without edges also present in `that`.
|
|
836
|
+
*
|
|
837
|
+
* **Details**
|
|
838
|
+
*
|
|
839
|
+
* All nodes from `self` are preserved. Edges are matched by endpoint and edge
|
|
840
|
+
* identities. The result has the same graph kind as `self`. Throws a
|
|
841
|
+
* `GraphError` when the graph kinds do not match. `nodeIdentity` and
|
|
842
|
+
* `edgeIdentity` default to the complete node and edge data.
|
|
843
|
+
*
|
|
844
|
+
* `G1 \ G2 = {V1, E1 \ E2}`
|
|
845
|
+
*
|
|
846
|
+
* **Gotchas**
|
|
847
|
+
*
|
|
848
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
849
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
850
|
+
* If `that` contains an edge identity, every parallel edge with that identity
|
|
851
|
+
* is removed from `self`.
|
|
852
|
+
*
|
|
853
|
+
* **Example** (Removing shared edges)
|
|
854
|
+
*
|
|
855
|
+
* ```ts
|
|
856
|
+
* import { Graph } from "effect"
|
|
857
|
+
*
|
|
858
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
859
|
+
* const a = Graph.addNode(mutable, "A")
|
|
860
|
+
* const b = Graph.addNode(mutable, "B")
|
|
861
|
+
* const c = Graph.addNode(mutable, "C")
|
|
862
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
863
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
864
|
+
* })
|
|
865
|
+
*
|
|
866
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
867
|
+
* const b = Graph.addNode(mutable, "B")
|
|
868
|
+
* const c = Graph.addNode(mutable, "C")
|
|
869
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
870
|
+
* })
|
|
871
|
+
*
|
|
872
|
+
* const result = Graph.difference(left, right)
|
|
873
|
+
*
|
|
874
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
875
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
876
|
+
* ```
|
|
877
|
+
*
|
|
878
|
+
* @category set operations
|
|
879
|
+
* @since 4.0.0
|
|
880
|
+
*/
|
|
881
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(that: Graph<N, E, T>, options?: IdentityOptions<N, E, NI, EI>): (self: Graph<N, E, NoInfer<T>>) => Graph<N, E, T>;
|
|
882
|
+
/**
|
|
883
|
+
* Returns `self` without edges also present in `that`.
|
|
884
|
+
*
|
|
885
|
+
* **Details**
|
|
886
|
+
*
|
|
887
|
+
* All nodes from `self` are preserved. Edges are matched by endpoint and edge
|
|
888
|
+
* identities. The result has the same graph kind as `self`. Throws a
|
|
889
|
+
* `GraphError` when the graph kinds do not match. `nodeIdentity` and
|
|
890
|
+
* `edgeIdentity` default to the complete node and edge data.
|
|
891
|
+
*
|
|
892
|
+
* `G1 \ G2 = {V1, E1 \ E2}`
|
|
893
|
+
*
|
|
894
|
+
* **Gotchas**
|
|
895
|
+
*
|
|
896
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
897
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
898
|
+
* If `that` contains an edge identity, every parallel edge with that identity
|
|
899
|
+
* is removed from `self`.
|
|
900
|
+
*
|
|
901
|
+
* **Example** (Removing shared edges)
|
|
902
|
+
*
|
|
903
|
+
* ```ts
|
|
904
|
+
* import { Graph } from "effect"
|
|
905
|
+
*
|
|
906
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
907
|
+
* const a = Graph.addNode(mutable, "A")
|
|
908
|
+
* const b = Graph.addNode(mutable, "B")
|
|
909
|
+
* const c = Graph.addNode(mutable, "C")
|
|
910
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
911
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
912
|
+
* })
|
|
913
|
+
*
|
|
914
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
915
|
+
* const b = Graph.addNode(mutable, "B")
|
|
916
|
+
* const c = Graph.addNode(mutable, "C")
|
|
917
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
918
|
+
* })
|
|
919
|
+
*
|
|
920
|
+
* const result = Graph.difference(left, right)
|
|
921
|
+
*
|
|
922
|
+
* console.log(Graph.nodeCount(result)) // 3
|
|
923
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* @category set operations
|
|
927
|
+
* @since 4.0.0
|
|
928
|
+
*/
|
|
929
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(self: Graph<N, E, T>, that: Graph<N, E, NoInfer<T>>, options?: IdentityOptions<N, E, NI, EI>): Graph<N, E, T>;
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* Returns edges present in exactly one of two graphs.
|
|
933
|
+
*
|
|
934
|
+
* **Details**
|
|
935
|
+
*
|
|
936
|
+
* Keeps nodes from both graphs. Overlapping nodes use data from `that`. The
|
|
937
|
+
* result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
938
|
+
* graph kinds do not match. `nodeIdentity` and `edgeIdentity` default to the
|
|
939
|
+
* complete node and edge data. Edge identity also includes the endpoint
|
|
940
|
+
* identities.
|
|
941
|
+
*
|
|
942
|
+
* `G1 Δ G2 = {V1 ∪ V2, (E1 ∪ E2) \ (E1 ∩ E2)}`
|
|
943
|
+
*
|
|
944
|
+
* **Gotchas**
|
|
945
|
+
*
|
|
946
|
+
* Edges with different projected identities are distinct.
|
|
947
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
948
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
949
|
+
* Parallel edges with equal identities are coalesced before the graphs are
|
|
950
|
+
* compared.
|
|
951
|
+
*
|
|
952
|
+
* **Example** (Finding differing edges)
|
|
953
|
+
*
|
|
954
|
+
* ```ts
|
|
955
|
+
* import { Graph } from "effect"
|
|
956
|
+
*
|
|
957
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
958
|
+
* const a = Graph.addNode(mutable, "A")
|
|
959
|
+
* const b = Graph.addNode(mutable, "B")
|
|
960
|
+
* const c = Graph.addNode(mutable, "C")
|
|
961
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
962
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
963
|
+
* })
|
|
964
|
+
*
|
|
965
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
966
|
+
* const b = Graph.addNode(mutable, "B")
|
|
967
|
+
* const c = Graph.addNode(mutable, "C")
|
|
968
|
+
* const d = Graph.addNode(mutable, "D")
|
|
969
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
970
|
+
* Graph.addEdge(mutable, c, d, "C-D")
|
|
971
|
+
* })
|
|
972
|
+
*
|
|
973
|
+
* const result = Graph.symmetricDifference(left, right)
|
|
974
|
+
*
|
|
975
|
+
* console.log(Graph.nodeCount(result)) // 4
|
|
976
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
977
|
+
* ```
|
|
978
|
+
*
|
|
979
|
+
* @category set operations
|
|
980
|
+
* @since 4.0.0
|
|
981
|
+
*/
|
|
982
|
+
export declare const symmetricDifference: {
|
|
983
|
+
/**
|
|
984
|
+
* Returns edges present in exactly one of two graphs.
|
|
985
|
+
*
|
|
986
|
+
* **Details**
|
|
987
|
+
*
|
|
988
|
+
* Keeps nodes from both graphs. Overlapping nodes use data from `that`. The
|
|
989
|
+
* result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
990
|
+
* graph kinds do not match. `nodeIdentity` and `edgeIdentity` default to the
|
|
991
|
+
* complete node and edge data. Edge identity also includes the endpoint
|
|
992
|
+
* identities.
|
|
993
|
+
*
|
|
994
|
+
* `G1 Δ G2 = {V1 ∪ V2, (E1 ∪ E2) \ (E1 ∩ E2)}`
|
|
995
|
+
*
|
|
996
|
+
* **Gotchas**
|
|
997
|
+
*
|
|
998
|
+
* Edges with different projected identities are distinct.
|
|
999
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
1000
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
1001
|
+
* Parallel edges with equal identities are coalesced before the graphs are
|
|
1002
|
+
* compared.
|
|
1003
|
+
*
|
|
1004
|
+
* **Example** (Finding differing edges)
|
|
1005
|
+
*
|
|
1006
|
+
* ```ts
|
|
1007
|
+
* import { Graph } from "effect"
|
|
1008
|
+
*
|
|
1009
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
1010
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1011
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1012
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1013
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1014
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
1015
|
+
* })
|
|
1016
|
+
*
|
|
1017
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
1018
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1019
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1020
|
+
* const d = Graph.addNode(mutable, "D")
|
|
1021
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
1022
|
+
* Graph.addEdge(mutable, c, d, "C-D")
|
|
1023
|
+
* })
|
|
1024
|
+
*
|
|
1025
|
+
* const result = Graph.symmetricDifference(left, right)
|
|
1026
|
+
*
|
|
1027
|
+
* console.log(Graph.nodeCount(result)) // 4
|
|
1028
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* @category set operations
|
|
1032
|
+
* @since 4.0.0
|
|
1033
|
+
*/
|
|
1034
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(that: Graph<N, E, T>, options?: IdentityOptions<N, E, NI, EI>): (self: Graph<N, E, NoInfer<T>>) => Graph<N, E, T>;
|
|
1035
|
+
/**
|
|
1036
|
+
* Returns edges present in exactly one of two graphs.
|
|
1037
|
+
*
|
|
1038
|
+
* **Details**
|
|
1039
|
+
*
|
|
1040
|
+
* Keeps nodes from both graphs. Overlapping nodes use data from `that`. The
|
|
1041
|
+
* result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
1042
|
+
* graph kinds do not match. `nodeIdentity` and `edgeIdentity` default to the
|
|
1043
|
+
* complete node and edge data. Edge identity also includes the endpoint
|
|
1044
|
+
* identities.
|
|
1045
|
+
*
|
|
1046
|
+
* `G1 Δ G2 = {V1 ∪ V2, (E1 ∪ E2) \ (E1 ∩ E2)}`
|
|
1047
|
+
*
|
|
1048
|
+
* **Gotchas**
|
|
1049
|
+
*
|
|
1050
|
+
* Edges with different projected identities are distinct.
|
|
1051
|
+
* Nodes with equal identities in one input graph are coalesced. The last node
|
|
1052
|
+
* supplies the data, and redirected edges can collapse or become self-loops.
|
|
1053
|
+
* Parallel edges with equal identities are coalesced before the graphs are
|
|
1054
|
+
* compared.
|
|
1055
|
+
*
|
|
1056
|
+
* **Example** (Finding differing edges)
|
|
1057
|
+
*
|
|
1058
|
+
* ```ts
|
|
1059
|
+
* import { Graph } from "effect"
|
|
1060
|
+
*
|
|
1061
|
+
* const left = Graph.directed<string, string>((mutable) => {
|
|
1062
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1063
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1064
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1065
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1066
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
1067
|
+
* })
|
|
1068
|
+
*
|
|
1069
|
+
* const right = Graph.directed<string, string>((mutable) => {
|
|
1070
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1071
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1072
|
+
* const d = Graph.addNode(mutable, "D")
|
|
1073
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
1074
|
+
* Graph.addEdge(mutable, c, d, "C-D")
|
|
1075
|
+
* })
|
|
1076
|
+
*
|
|
1077
|
+
* const result = Graph.symmetricDifference(left, right)
|
|
1078
|
+
*
|
|
1079
|
+
* console.log(Graph.nodeCount(result)) // 4
|
|
1080
|
+
* console.log(Graph.edgeCount(result)) // 2
|
|
1081
|
+
* ```
|
|
1082
|
+
*
|
|
1083
|
+
* @category set operations
|
|
1084
|
+
* @since 4.0.0
|
|
1085
|
+
*/
|
|
1086
|
+
<N, E, T extends Kind = "directed", NI = N, EI = E>(self: Graph<N, E, T>, that: Graph<N, E, NoInfer<T>>, options?: IdentityOptions<N, E, NI, EI>): Graph<N, E, T>;
|
|
1087
|
+
};
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns the complement over the existing node set.
|
|
260
1090
|
*
|
|
261
|
-
* **
|
|
1091
|
+
* **Details**
|
|
262
1092
|
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
1093
|
+
* Adds every missing edge between distinct nodes. The `createEdge` function
|
|
1094
|
+
* receives the source and target node data for each added edge. The result has
|
|
1095
|
+
* the same graph kind as `self`.
|
|
265
1096
|
*
|
|
266
|
-
*
|
|
267
|
-
* @since 4.0.0
|
|
268
|
-
*/
|
|
269
|
-
export declare const isGraph: (u: unknown) => u is Graph<unknown, unknown>;
|
|
270
|
-
/**
|
|
271
|
-
* Creates a directed graph, optionally with initial mutations.
|
|
1097
|
+
* `G' = {V, (V x V) \ E}`
|
|
272
1098
|
*
|
|
273
|
-
* **Example** (
|
|
1099
|
+
* **Example** (Finding missing relationships)
|
|
274
1100
|
*
|
|
275
1101
|
* ```ts
|
|
276
1102
|
* import { Graph } from "effect"
|
|
277
1103
|
*
|
|
278
|
-
* // Directed graph with initial nodes and edges
|
|
279
1104
|
* const graph = Graph.directed<string, string>((mutable) => {
|
|
280
1105
|
* const a = Graph.addNode(mutable, "A")
|
|
281
1106
|
* const b = Graph.addNode(mutable, "B")
|
|
282
|
-
*
|
|
283
|
-
* Graph.addEdge(mutable, a, b, "A->B")
|
|
284
|
-
* Graph.addEdge(mutable, b, c, "B->C")
|
|
1107
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
285
1108
|
* })
|
|
286
|
-
* ```
|
|
287
|
-
*
|
|
288
|
-
* @category constructors
|
|
289
|
-
* @since 3.18.0
|
|
290
|
-
*/
|
|
291
|
-
export declare const directed: <N, E>(mutate?: (mutable: MutableDirectedGraph<N, E>) => void) => DirectedGraph<N, E>;
|
|
292
|
-
/**
|
|
293
|
-
* Creates an undirected graph, optionally with initial mutations.
|
|
294
|
-
*
|
|
295
|
-
* **Example** (Creating an undirected graph)
|
|
296
1109
|
*
|
|
297
|
-
*
|
|
298
|
-
* import { Graph } from "effect"
|
|
1110
|
+
* const result = Graph.complement(graph, (source, target) => `${source}-${target}`)
|
|
299
1111
|
*
|
|
300
|
-
* //
|
|
301
|
-
* const graph = Graph.undirected<string, string>((mutable) => {
|
|
302
|
-
* const a = Graph.addNode(mutable, "A")
|
|
303
|
-
* const b = Graph.addNode(mutable, "B")
|
|
304
|
-
* const c = Graph.addNode(mutable, "C")
|
|
305
|
-
* Graph.addEdge(mutable, a, b, "A-B")
|
|
306
|
-
* Graph.addEdge(mutable, b, c, "B-C")
|
|
307
|
-
* })
|
|
1112
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
308
1113
|
* ```
|
|
309
1114
|
*
|
|
310
|
-
* @category
|
|
311
|
-
* @since
|
|
1115
|
+
* @category set operations
|
|
1116
|
+
* @since 4.0.0
|
|
312
1117
|
*/
|
|
313
|
-
export declare const
|
|
1118
|
+
export declare const complement: {
|
|
1119
|
+
/**
|
|
1120
|
+
* Returns the complement over the existing node set.
|
|
1121
|
+
*
|
|
1122
|
+
* **Details**
|
|
1123
|
+
*
|
|
1124
|
+
* Adds every missing edge between distinct nodes. The `createEdge` function
|
|
1125
|
+
* receives the source and target node data for each added edge. The result has
|
|
1126
|
+
* the same graph kind as `self`.
|
|
1127
|
+
*
|
|
1128
|
+
* `G' = {V, (V x V) \ E}`
|
|
1129
|
+
*
|
|
1130
|
+
* **Example** (Finding missing relationships)
|
|
1131
|
+
*
|
|
1132
|
+
* ```ts
|
|
1133
|
+
* import { Graph } from "effect"
|
|
1134
|
+
*
|
|
1135
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
1136
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1137
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1138
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1139
|
+
* })
|
|
1140
|
+
*
|
|
1141
|
+
* const result = Graph.complement(graph, (source, target) => `${source}-${target}`)
|
|
1142
|
+
*
|
|
1143
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
1144
|
+
* ```
|
|
1145
|
+
*
|
|
1146
|
+
* @category set operations
|
|
1147
|
+
* @since 4.0.0
|
|
1148
|
+
*/
|
|
1149
|
+
<N, E>(createEdge: (source: N, target: N) => E): <T extends Kind = "directed">(self: Graph<N, E, T>) => Graph<N, E, T>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Returns the complement over the existing node set.
|
|
1152
|
+
*
|
|
1153
|
+
* **Details**
|
|
1154
|
+
*
|
|
1155
|
+
* Adds every missing edge between distinct nodes. The `createEdge` function
|
|
1156
|
+
* receives the source and target node data for each added edge. The result has
|
|
1157
|
+
* the same graph kind as `self`.
|
|
1158
|
+
*
|
|
1159
|
+
* `G' = {V, (V x V) \ E}`
|
|
1160
|
+
*
|
|
1161
|
+
* **Example** (Finding missing relationships)
|
|
1162
|
+
*
|
|
1163
|
+
* ```ts
|
|
1164
|
+
* import { Graph } from "effect"
|
|
1165
|
+
*
|
|
1166
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
1167
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1168
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1169
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1170
|
+
* })
|
|
1171
|
+
*
|
|
1172
|
+
* const result = Graph.complement(graph, (source, target) => `${source}-${target}`)
|
|
1173
|
+
*
|
|
1174
|
+
* console.log(Graph.edgeCount(result)) // 1
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1177
|
+
* @category set operations
|
|
1178
|
+
* @since 4.0.0
|
|
1179
|
+
*/
|
|
1180
|
+
<N, E, T extends Kind = "directed">(self: Graph<N, E, T>, createEdge: (source: N, target: N) => E): Graph<N, E, T>;
|
|
1181
|
+
};
|
|
314
1182
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* **Example** (Beginning a mutation scope)
|
|
1183
|
+
* Configuration for selecting a graph neighborhood.
|
|
318
1184
|
*
|
|
319
|
-
*
|
|
320
|
-
* import { Graph } from "effect"
|
|
1185
|
+
* **Details**
|
|
321
1186
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* ```
|
|
1187
|
+
* `radius` limits the edge distance from the center node and defaults to `1`.
|
|
1188
|
+
* `direction` controls how directed edges are traversed and defaults to
|
|
1189
|
+
* `"outgoing"`.
|
|
326
1190
|
*
|
|
327
|
-
* @category
|
|
328
|
-
* @since
|
|
1191
|
+
* @category models
|
|
1192
|
+
* @since 4.0.0
|
|
329
1193
|
*/
|
|
330
|
-
export
|
|
1194
|
+
export interface NeighborhoodConfig {
|
|
1195
|
+
readonly radius?: number;
|
|
1196
|
+
readonly direction?: TraversalDirection;
|
|
1197
|
+
}
|
|
331
1198
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* **Example** (Ending a mutation scope)
|
|
335
|
-
*
|
|
336
|
-
* ```ts
|
|
337
|
-
* import { Graph } from "effect"
|
|
1199
|
+
* Returns the induced subgraph containing nodes within a radius of a node.
|
|
338
1200
|
*
|
|
339
|
-
*
|
|
340
|
-
* const mutable = Graph.beginMutation(graph)
|
|
341
|
-
* // ... perform mutations on mutable ...
|
|
342
|
-
* const newGraph = Graph.endMutation(mutable)
|
|
343
|
-
* ```
|
|
1201
|
+
* **Details**
|
|
344
1202
|
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
* Performs scoped mutations on a graph, automatically managing the mutation lifecycle.
|
|
1203
|
+
* The `radius` option is the maximum edge distance from `nodeIndex` and
|
|
1204
|
+
* defaults to `1`. The `direction` option controls directed graph traversal and
|
|
1205
|
+
* defaults to `"outgoing"`. The result has the same graph kind as `self` and
|
|
1206
|
+
* keeps all original edges whose endpoints are both reached. `"undirected"`
|
|
1207
|
+
* ignores edge direction while finding reachable nodes.
|
|
351
1208
|
*
|
|
352
|
-
* **Example** (
|
|
1209
|
+
* **Example** (Getting a local neighborhood)
|
|
353
1210
|
*
|
|
354
1211
|
* ```ts
|
|
355
1212
|
* import { Graph } from "effect"
|
|
356
1213
|
*
|
|
357
|
-
* const graph = Graph.directed<string,
|
|
358
|
-
*
|
|
359
|
-
* const
|
|
360
|
-
* const
|
|
361
|
-
* Graph.addEdge(mutable,
|
|
1214
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
1215
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1216
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1217
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1218
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1219
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
362
1220
|
* })
|
|
363
1221
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
1222
|
+
* const result = Graph.neighborhood(graph, 1, { radius: 1 })
|
|
1223
|
+
*
|
|
1224
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
366
1225
|
* ```
|
|
367
1226
|
*
|
|
368
|
-
* @category
|
|
369
|
-
* @since
|
|
1227
|
+
* @category set operations
|
|
1228
|
+
* @since 4.0.0
|
|
370
1229
|
*/
|
|
371
|
-
export declare const
|
|
1230
|
+
export declare const neighborhood: {
|
|
372
1231
|
/**
|
|
373
|
-
*
|
|
1232
|
+
* Returns the induced subgraph containing nodes within a radius of a node.
|
|
374
1233
|
*
|
|
375
|
-
* **
|
|
1234
|
+
* **Details**
|
|
1235
|
+
*
|
|
1236
|
+
* The `radius` option is the maximum edge distance from `nodeIndex` and
|
|
1237
|
+
* defaults to `1`. The `direction` option controls directed graph traversal and
|
|
1238
|
+
* defaults to `"outgoing"`. The result has the same graph kind as `self` and
|
|
1239
|
+
* keeps all original edges whose endpoints are both reached. `"undirected"`
|
|
1240
|
+
* ignores edge direction while finding reachable nodes.
|
|
1241
|
+
*
|
|
1242
|
+
* **Example** (Getting a local neighborhood)
|
|
376
1243
|
*
|
|
377
1244
|
* ```ts
|
|
378
1245
|
* import { Graph } from "effect"
|
|
379
1246
|
*
|
|
380
|
-
* const graph = Graph.directed<string,
|
|
381
|
-
*
|
|
382
|
-
* const
|
|
383
|
-
* const
|
|
384
|
-
* Graph.addEdge(mutable,
|
|
1247
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
1248
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1249
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1250
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1251
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1252
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
385
1253
|
* })
|
|
386
1254
|
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
1255
|
+
* const result = Graph.neighborhood(graph, 1, { radius: 1 })
|
|
1256
|
+
*
|
|
1257
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
389
1258
|
* ```
|
|
390
1259
|
*
|
|
391
|
-
* @category
|
|
392
|
-
* @since
|
|
1260
|
+
* @category set operations
|
|
1261
|
+
* @since 4.0.0
|
|
393
1262
|
*/
|
|
394
|
-
<N, E, T extends Kind = "directed">(
|
|
1263
|
+
(nodeIndex: NodeIndex, options?: NeighborhoodConfig): <N, E, T extends Kind = "directed">(self: Graph<N, E, T>) => Graph<N, E, T>;
|
|
395
1264
|
/**
|
|
396
|
-
*
|
|
1265
|
+
* Returns the induced subgraph containing nodes within a radius of a node.
|
|
397
1266
|
*
|
|
398
|
-
* **
|
|
1267
|
+
* **Details**
|
|
1268
|
+
*
|
|
1269
|
+
* The `radius` option is the maximum edge distance from `nodeIndex` and
|
|
1270
|
+
* defaults to `1`. The `direction` option controls directed graph traversal and
|
|
1271
|
+
* defaults to `"outgoing"`. The result has the same graph kind as `self` and
|
|
1272
|
+
* keeps all original edges whose endpoints are both reached. `"undirected"`
|
|
1273
|
+
* ignores edge direction while finding reachable nodes.
|
|
1274
|
+
*
|
|
1275
|
+
* **Example** (Getting a local neighborhood)
|
|
399
1276
|
*
|
|
400
1277
|
* ```ts
|
|
401
1278
|
* import { Graph } from "effect"
|
|
402
1279
|
*
|
|
403
|
-
* const graph = Graph.directed<string,
|
|
404
|
-
*
|
|
405
|
-
* const
|
|
406
|
-
* const
|
|
407
|
-
* Graph.addEdge(mutable,
|
|
1280
|
+
* const graph = Graph.directed<string, string>((mutable) => {
|
|
1281
|
+
* const a = Graph.addNode(mutable, "A")
|
|
1282
|
+
* const b = Graph.addNode(mutable, "B")
|
|
1283
|
+
* const c = Graph.addNode(mutable, "C")
|
|
1284
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
1285
|
+
* Graph.addEdge(mutable, b, c, "B-C")
|
|
408
1286
|
* })
|
|
409
1287
|
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
1288
|
+
* const result = Graph.neighborhood(graph, 1, { radius: 1 })
|
|
1289
|
+
*
|
|
1290
|
+
* console.log(Graph.nodeCount(result)) // 2
|
|
412
1291
|
* ```
|
|
413
1292
|
*
|
|
414
|
-
* @category
|
|
415
|
-
* @since
|
|
1293
|
+
* @category set operations
|
|
1294
|
+
* @since 4.0.0
|
|
1295
|
+
*/
|
|
1296
|
+
<N, E, T extends Kind = "directed">(self: Graph<N, E, T>, nodeIndex: NodeIndex, options?: NeighborhoodConfig): Graph<N, E, T>;
|
|
1297
|
+
};
|
|
1298
|
+
/**
|
|
1299
|
+
* Returns the disjoint union of two graphs.
|
|
1300
|
+
*
|
|
1301
|
+
* **Details**
|
|
1302
|
+
*
|
|
1303
|
+
* Copies all nodes and edges from both graphs without merging equal node data.
|
|
1304
|
+
* The result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
1305
|
+
* graph kinds do not match.
|
|
1306
|
+
*
|
|
1307
|
+
* `G1 + G2 = {disjoint V1 + V2, disjoint E1 + E2}`
|
|
1308
|
+
*
|
|
1309
|
+
* @category set operations
|
|
1310
|
+
* @since 4.0.0
|
|
1311
|
+
*/
|
|
1312
|
+
export declare const sum: {
|
|
1313
|
+
/**
|
|
1314
|
+
* Returns the disjoint union of two graphs.
|
|
1315
|
+
*
|
|
1316
|
+
* **Details**
|
|
1317
|
+
*
|
|
1318
|
+
* Copies all nodes and edges from both graphs without merging equal node data.
|
|
1319
|
+
* The result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
1320
|
+
* graph kinds do not match.
|
|
1321
|
+
*
|
|
1322
|
+
* `G1 + G2 = {disjoint V1 + V2, disjoint E1 + E2}`
|
|
1323
|
+
*
|
|
1324
|
+
* @category set operations
|
|
1325
|
+
* @since 4.0.0
|
|
1326
|
+
*/
|
|
1327
|
+
<N, E, T extends Kind>(that: Graph<N, E, T>): (self: Graph<N, E, NoInfer<T>>) => Graph<N, E, T>;
|
|
1328
|
+
/**
|
|
1329
|
+
* Returns the disjoint union of two graphs.
|
|
1330
|
+
*
|
|
1331
|
+
* **Details**
|
|
1332
|
+
*
|
|
1333
|
+
* Copies all nodes and edges from both graphs without merging equal node data.
|
|
1334
|
+
* The result has the same graph kind as `self`. Throws a `GraphError` when the
|
|
1335
|
+
* graph kinds do not match.
|
|
1336
|
+
*
|
|
1337
|
+
* `G1 + G2 = {disjoint V1 + V2, disjoint E1 + E2}`
|
|
1338
|
+
*
|
|
1339
|
+
* @category set operations
|
|
1340
|
+
* @since 4.0.0
|
|
416
1341
|
*/
|
|
417
|
-
<N, E, T extends Kind
|
|
1342
|
+
<N, E, T extends Kind>(self: Graph<N, E, T>, that: Graph<N, E, NoInfer<T>>): Graph<N, E, T>;
|
|
418
1343
|
};
|
|
419
1344
|
/**
|
|
420
1345
|
* Adds a new node to a mutable graph and returns its index.
|
|
@@ -502,7 +1427,7 @@ export declare const getNode: {
|
|
|
502
1427
|
* @category getters
|
|
503
1428
|
* @since 3.18.0
|
|
504
1429
|
*/
|
|
505
|
-
<N, E, T extends Kind = "directed">(
|
|
1430
|
+
(nodeIndex: NodeIndex): <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => Option.Option<N>;
|
|
506
1431
|
/**
|
|
507
1432
|
* Gets the data associated with a node index safely, if it exists.
|
|
508
1433
|
*
|
|
@@ -1327,7 +2252,7 @@ export declare const getEdge: {
|
|
|
1327
2252
|
* @category getters
|
|
1328
2253
|
* @since 3.18.0
|
|
1329
2254
|
*/
|
|
1330
|
-
|
|
2255
|
+
(edgeIndex: EdgeIndex): <N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>) => Option.Option<Edge<E>>;
|
|
1331
2256
|
/**
|
|
1332
2257
|
* Gets the edge data associated with an edge index safely, if it exists.
|
|
1333
2258
|
*
|
|
@@ -1887,7 +2812,7 @@ export interface GraphVizOptions<N, E> {
|
|
|
1887
2812
|
*
|
|
1888
2813
|
* const dot = Graph.toGraphViz(graph)
|
|
1889
2814
|
* console.log(dot)
|
|
1890
|
-
* // digraph G {
|
|
2815
|
+
* // digraph "G" {
|
|
1891
2816
|
* // "0" [label="Node A"];
|
|
1892
2817
|
* // "1" [label="Node B"];
|
|
1893
2818
|
* // "2" [label="Node C"];
|
|
@@ -1920,7 +2845,7 @@ export declare const toGraphViz: {
|
|
|
1920
2845
|
*
|
|
1921
2846
|
* const dot = Graph.toGraphViz(graph)
|
|
1922
2847
|
* console.log(dot)
|
|
1923
|
-
* // digraph G {
|
|
2848
|
+
* // digraph "G" {
|
|
1924
2849
|
* // "0" [label="Node A"];
|
|
1925
2850
|
* // "1" [label="Node B"];
|
|
1926
2851
|
* // "2" [label="Node C"];
|
|
@@ -1953,7 +2878,7 @@ export declare const toGraphViz: {
|
|
|
1953
2878
|
*
|
|
1954
2879
|
* const dot = Graph.toGraphViz(graph)
|
|
1955
2880
|
* console.log(dot)
|
|
1956
|
-
* // digraph G {
|
|
2881
|
+
* // digraph "G" {
|
|
1957
2882
|
* // "0" [label="Node A"];
|
|
1958
2883
|
* // "1" [label="Node B"];
|
|
1959
2884
|
* // "2" [label="Node C"];
|
|
@@ -2274,22 +3199,22 @@ export interface MermaidOptions<N, E> {
|
|
|
2274
3199
|
* name: "MyApp",
|
|
2275
3200
|
* version: "1.0.0",
|
|
2276
3201
|
* type: "library"
|
|
2277
|
-
* })
|
|
3202
|
+
* } satisfies Dependency)
|
|
2278
3203
|
* const react = Graph.addNode(mutable, {
|
|
2279
3204
|
* name: "React",
|
|
2280
3205
|
* version: "18.0.0",
|
|
2281
3206
|
* type: "framework"
|
|
2282
|
-
* })
|
|
3207
|
+
* } satisfies Dependency)
|
|
2283
3208
|
* const lodash = Graph.addNode(mutable, {
|
|
2284
3209
|
* name: "Lodash",
|
|
2285
3210
|
* version: "4.17.0",
|
|
2286
3211
|
* type: "library"
|
|
2287
|
-
* })
|
|
3212
|
+
* } satisfies Dependency)
|
|
2288
3213
|
* const webpack = Graph.addNode(mutable, {
|
|
2289
3214
|
* name: "Webpack",
|
|
2290
3215
|
* version: "5.0.0",
|
|
2291
3216
|
* type: "tool"
|
|
2292
|
-
* })
|
|
3217
|
+
* } satisfies Dependency)
|
|
2293
3218
|
*
|
|
2294
3219
|
* Graph.addEdge(mutable, app, react, "depends on")
|
|
2295
3220
|
* Graph.addEdge(mutable, app, lodash, "depends on")
|
|
@@ -2454,22 +3379,22 @@ export declare const toMermaid: {
|
|
|
2454
3379
|
* name: "MyApp",
|
|
2455
3380
|
* version: "1.0.0",
|
|
2456
3381
|
* type: "library"
|
|
2457
|
-
* })
|
|
3382
|
+
* } satisfies Dependency)
|
|
2458
3383
|
* const react = Graph.addNode(mutable, {
|
|
2459
3384
|
* name: "React",
|
|
2460
3385
|
* version: "18.0.0",
|
|
2461
3386
|
* type: "framework"
|
|
2462
|
-
* })
|
|
3387
|
+
* } satisfies Dependency)
|
|
2463
3388
|
* const lodash = Graph.addNode(mutable, {
|
|
2464
3389
|
* name: "Lodash",
|
|
2465
3390
|
* version: "4.17.0",
|
|
2466
3391
|
* type: "library"
|
|
2467
|
-
* })
|
|
3392
|
+
* } satisfies Dependency)
|
|
2468
3393
|
* const webpack = Graph.addNode(mutable, {
|
|
2469
3394
|
* name: "Webpack",
|
|
2470
3395
|
* version: "5.0.0",
|
|
2471
3396
|
* type: "tool"
|
|
2472
|
-
* })
|
|
3397
|
+
* } satisfies Dependency)
|
|
2473
3398
|
*
|
|
2474
3399
|
* Graph.addEdge(mutable, app, react, "depends on")
|
|
2475
3400
|
* Graph.addEdge(mutable, app, lodash, "depends on")
|
|
@@ -2634,22 +3559,22 @@ export declare const toMermaid: {
|
|
|
2634
3559
|
* name: "MyApp",
|
|
2635
3560
|
* version: "1.0.0",
|
|
2636
3561
|
* type: "library"
|
|
2637
|
-
* })
|
|
3562
|
+
* } satisfies Dependency)
|
|
2638
3563
|
* const react = Graph.addNode(mutable, {
|
|
2639
3564
|
* name: "React",
|
|
2640
3565
|
* version: "18.0.0",
|
|
2641
3566
|
* type: "framework"
|
|
2642
|
-
* })
|
|
3567
|
+
* } satisfies Dependency)
|
|
2643
3568
|
* const lodash = Graph.addNode(mutable, {
|
|
2644
3569
|
* name: "Lodash",
|
|
2645
3570
|
* version: "4.17.0",
|
|
2646
3571
|
* type: "library"
|
|
2647
|
-
* })
|
|
3572
|
+
* } satisfies Dependency)
|
|
2648
3573
|
* const webpack = Graph.addNode(mutable, {
|
|
2649
3574
|
* name: "Webpack",
|
|
2650
3575
|
* version: "5.0.0",
|
|
2651
3576
|
* type: "tool"
|
|
2652
|
-
* })
|
|
3577
|
+
* } satisfies Dependency)
|
|
2653
3578
|
*
|
|
2654
3579
|
* Graph.addEdge(mutable, app, react, "depends on")
|
|
2655
3580
|
* Graph.addEdge(mutable, app, lodash, "depends on")
|
|
@@ -2685,7 +3610,25 @@ export declare const toMermaid: {
|
|
|
2685
3610
|
<N, E, T extends Kind = "directed">(graph: Graph<N, E, T> | MutableGraph<N, E, T>, options?: MermaidOptions<N, E>): string;
|
|
2686
3611
|
};
|
|
2687
3612
|
/**
|
|
2688
|
-
* Direction
|
|
3613
|
+
* Direction of directed edges relative to a node.
|
|
3614
|
+
*
|
|
3615
|
+
* **Details**
|
|
3616
|
+
*
|
|
3617
|
+
* `"outgoing"` selects edges whose source is the node, while `"incoming"`
|
|
3618
|
+
* selects edges whose target is the node.
|
|
3619
|
+
*
|
|
3620
|
+
* @category models
|
|
3621
|
+
* @since 3.18.0
|
|
3622
|
+
*/
|
|
3623
|
+
export type Direction = "outgoing" | "incoming";
|
|
3624
|
+
/**
|
|
3625
|
+
* Controls how traversal follows directed edges.
|
|
3626
|
+
*
|
|
3627
|
+
* **Details**
|
|
3628
|
+
*
|
|
3629
|
+
* `"outgoing"` follows edges from source to target, `"incoming"` follows them
|
|
3630
|
+
* from target to source, and `"undirected"` allows traversal in either
|
|
3631
|
+
* direction.
|
|
2689
3632
|
*
|
|
2690
3633
|
* **Example** (Traversing by direction)
|
|
2691
3634
|
*
|
|
@@ -2695,24 +3638,28 @@ export declare const toMermaid: {
|
|
|
2695
3638
|
* const graph = Graph.directed<string, string>((mutable) => {
|
|
2696
3639
|
* const a = Graph.addNode(mutable, "A")
|
|
2697
3640
|
* const b = Graph.addNode(mutable, "B")
|
|
2698
|
-
* Graph.
|
|
3641
|
+
* const c = Graph.addNode(mutable, "C")
|
|
3642
|
+
* Graph.addEdge(mutable, a, b, "A-B")
|
|
3643
|
+
* Graph.addEdge(mutable, a, c, "A-C")
|
|
2699
3644
|
* })
|
|
2700
3645
|
*
|
|
2701
|
-
*
|
|
2702
|
-
*
|
|
2703
|
-
*
|
|
2704
|
-
* )
|
|
3646
|
+
* const outgoing = Array.from(
|
|
3647
|
+
* Graph.indices(Graph.bfs(graph, { start: [0], direction: "outgoing" }))
|
|
3648
|
+
* ) // [0, 1, 2]
|
|
2705
3649
|
*
|
|
2706
|
-
*
|
|
2707
|
-
*
|
|
2708
|
-
*
|
|
2709
|
-
*
|
|
3650
|
+
* const incoming = Array.from(
|
|
3651
|
+
* Graph.indices(Graph.bfs(graph, { start: [1], direction: "incoming" }))
|
|
3652
|
+
* ) // [1, 0]
|
|
3653
|
+
*
|
|
3654
|
+
* const undirected = Array.from(
|
|
3655
|
+
* Graph.indices(Graph.bfs(graph, { start: [1], direction: "undirected" }))
|
|
3656
|
+
* ) // [1, 0, 2]
|
|
2710
3657
|
* ```
|
|
2711
3658
|
*
|
|
2712
3659
|
* @category models
|
|
2713
|
-
* @since
|
|
3660
|
+
* @since 4.0.0
|
|
2714
3661
|
*/
|
|
2715
|
-
export type
|
|
3662
|
+
export type TraversalDirection = Direction | "undirected";
|
|
2716
3663
|
/**
|
|
2717
3664
|
* Checks whether the graph is acyclic (contains no cycles).
|
|
2718
3665
|
*
|
|
@@ -2720,7 +3667,8 @@ export type Direction = "outgoing" | "incoming";
|
|
|
2720
3667
|
*
|
|
2721
3668
|
* Uses depth-first search to detect back edges, which indicate cycles.
|
|
2722
3669
|
* For directed graphs, any back edge creates a cycle. For undirected graphs,
|
|
2723
|
-
* a back edge that doesn't
|
|
3670
|
+
* a back edge that doesn't use the same edge used to enter the current node
|
|
3671
|
+
* creates a cycle.
|
|
2724
3672
|
*
|
|
2725
3673
|
* **Example** (Checking cycles)
|
|
2726
3674
|
*
|
|
@@ -2892,12 +3840,13 @@ export interface PathResult<E> {
|
|
|
2892
3840
|
* **Details**
|
|
2893
3841
|
*
|
|
2894
3842
|
* Specifies the source and target node indices, plus a cost function that maps
|
|
2895
|
-
* each edge's data to a non-negative numeric weight.
|
|
3843
|
+
* each edge's data to a non-negative numeric weight. `Infinity` is allowed and
|
|
3844
|
+
* behaves like an impassable edge.
|
|
2896
3845
|
*
|
|
2897
3846
|
* **Gotchas**
|
|
2898
3847
|
*
|
|
2899
3848
|
* `dijkstra` throws a `GraphError` when either endpoint does not exist or when
|
|
2900
|
-
* the cost function returns a negative weight
|
|
3849
|
+
* the cost function returns a negative weight or `NaN`.
|
|
2901
3850
|
*
|
|
2902
3851
|
* @see {@link dijkstra} for the algorithm that consumes this configuration
|
|
2903
3852
|
* @see {@link AstarConfig} for heuristic shortest-path search
|
|
@@ -2917,9 +3866,10 @@ export interface DijkstraConfig<E> {
|
|
|
2917
3866
|
*
|
|
2918
3867
|
* **Details**
|
|
2919
3868
|
*
|
|
2920
|
-
* Edge costs must be non-negative
|
|
2921
|
-
*
|
|
2922
|
-
*
|
|
3869
|
+
* Edge costs must be non-negative and not `NaN`. `Infinity` is allowed and
|
|
3870
|
+
* behaves like an impassable edge. Returns `Option.none()` when the target is
|
|
3871
|
+
* not reachable, and throws a `GraphError` when either endpoint is missing or an
|
|
3872
|
+
* edge cost is negative or `NaN`.
|
|
2923
3873
|
*
|
|
2924
3874
|
* **Example** (Finding shortest paths with Dijkstra)
|
|
2925
3875
|
*
|
|
@@ -2957,9 +3907,10 @@ export declare const dijkstra: {
|
|
|
2957
3907
|
*
|
|
2958
3908
|
* **Details**
|
|
2959
3909
|
*
|
|
2960
|
-
* Edge costs must be non-negative
|
|
2961
|
-
*
|
|
2962
|
-
*
|
|
3910
|
+
* Edge costs must be non-negative and not `NaN`. `Infinity` is allowed and
|
|
3911
|
+
* behaves like an impassable edge. Returns `Option.none()` when the target is
|
|
3912
|
+
* not reachable, and throws a `GraphError` when either endpoint is missing or an
|
|
3913
|
+
* edge cost is negative or `NaN`.
|
|
2963
3914
|
*
|
|
2964
3915
|
* **Example** (Finding shortest paths with Dijkstra)
|
|
2965
3916
|
*
|
|
@@ -2997,9 +3948,10 @@ export declare const dijkstra: {
|
|
|
2997
3948
|
*
|
|
2998
3949
|
* **Details**
|
|
2999
3950
|
*
|
|
3000
|
-
* Edge costs must be non-negative
|
|
3001
|
-
*
|
|
3002
|
-
*
|
|
3951
|
+
* Edge costs must be non-negative and not `NaN`. `Infinity` is allowed and
|
|
3952
|
+
* behaves like an impassable edge. Returns `Option.none()` when the target is
|
|
3953
|
+
* not reachable, and throws a `GraphError` when either endpoint is missing or an
|
|
3954
|
+
* edge cost is negative or `NaN`.
|
|
3003
3955
|
*
|
|
3004
3956
|
* **Example** (Finding shortest paths with Dijkstra)
|
|
3005
3957
|
*
|
|
@@ -3064,8 +4016,9 @@ export interface AllPairsResult<E> {
|
|
|
3064
4016
|
* **Details**
|
|
3065
4017
|
*
|
|
3066
4018
|
* Computes distances, reconstructed node paths, and edge-data paths for every
|
|
3067
|
-
* source and target pair in O(V^3) time. Negative edge weights are allowed,
|
|
3068
|
-
*
|
|
4019
|
+
* source and target pair in O(V^3) time. Negative edge weights are allowed, and
|
|
4020
|
+
* `Infinity` behaves like an impassable edge. A `GraphError` is thrown if any
|
|
4021
|
+
* edge weight is `NaN` or `-Infinity`, or if any negative cycle is detected.
|
|
3069
4022
|
*
|
|
3070
4023
|
* **Example** (Finding all-pairs shortest paths)
|
|
3071
4024
|
*
|
|
@@ -3097,8 +4050,9 @@ export declare const floydWarshall: {
|
|
|
3097
4050
|
* **Details**
|
|
3098
4051
|
*
|
|
3099
4052
|
* Computes distances, reconstructed node paths, and edge-data paths for every
|
|
3100
|
-
* source and target pair in O(V^3) time. Negative edge weights are allowed,
|
|
3101
|
-
*
|
|
4053
|
+
* source and target pair in O(V^3) time. Negative edge weights are allowed, and
|
|
4054
|
+
* `Infinity` behaves like an impassable edge. A `GraphError` is thrown if any
|
|
4055
|
+
* edge weight is `NaN` or `-Infinity`, or if any negative cycle is detected.
|
|
3102
4056
|
*
|
|
3103
4057
|
* **Example** (Finding all-pairs shortest paths)
|
|
3104
4058
|
*
|
|
@@ -3130,8 +4084,9 @@ export declare const floydWarshall: {
|
|
|
3130
4084
|
* **Details**
|
|
3131
4085
|
*
|
|
3132
4086
|
* Computes distances, reconstructed node paths, and edge-data paths for every
|
|
3133
|
-
* source and target pair in O(V^3) time. Negative edge weights are allowed,
|
|
3134
|
-
*
|
|
4087
|
+
* source and target pair in O(V^3) time. Negative edge weights are allowed, and
|
|
4088
|
+
* `Infinity` behaves like an impassable edge. A `GraphError` is thrown if any
|
|
4089
|
+
* edge weight is `NaN` or `-Infinity`, or if any negative cycle is detected.
|
|
3135
4090
|
*
|
|
3136
4091
|
* **Example** (Finding all-pairs shortest paths)
|
|
3137
4092
|
*
|
|
@@ -3167,8 +4122,9 @@ export declare const floydWarshall: {
|
|
|
3167
4122
|
*
|
|
3168
4123
|
* **Details**
|
|
3169
4124
|
*
|
|
3170
|
-
* Specifies the source and target node indices, an edge-cost function
|
|
3171
|
-
*
|
|
4125
|
+
* Specifies the source and target node indices, an edge-cost function that maps
|
|
4126
|
+
* edge data to non-negative weights, and a heuristic that estimates the
|
|
4127
|
+
* remaining cost from a node to the target.
|
|
3172
4128
|
*
|
|
3173
4129
|
* @see {@link astar} for the algorithm that consumes this configuration
|
|
3174
4130
|
* @see {@link DijkstraConfig} for shortest paths without a heuristic
|
|
@@ -3189,10 +4145,11 @@ export interface AstarConfig<E, N> {
|
|
|
3189
4145
|
*
|
|
3190
4146
|
* **Details**
|
|
3191
4147
|
*
|
|
3192
|
-
* The edge-cost function must return non-negative weights
|
|
4148
|
+
* The edge-cost function must return non-negative weights and not `NaN`.
|
|
4149
|
+
* `Infinity` is allowed and behaves like an impassable edge. The heuristic
|
|
3193
4150
|
* should be consistent to preserve shortest-path guarantees. Returns
|
|
3194
4151
|
* `Option.none()` when the target is not reachable, and throws a `GraphError`
|
|
3195
|
-
* when either endpoint is missing or
|
|
4152
|
+
* when either endpoint is missing or an edge cost is negative or `NaN`.
|
|
3196
4153
|
*
|
|
3197
4154
|
* **Example** (Finding shortest paths with A-star)
|
|
3198
4155
|
*
|
|
@@ -3236,10 +4193,11 @@ export declare const astar: {
|
|
|
3236
4193
|
*
|
|
3237
4194
|
* **Details**
|
|
3238
4195
|
*
|
|
3239
|
-
* The edge-cost function must return non-negative weights
|
|
4196
|
+
* The edge-cost function must return non-negative weights and not `NaN`.
|
|
4197
|
+
* `Infinity` is allowed and behaves like an impassable edge. The heuristic
|
|
3240
4198
|
* should be consistent to preserve shortest-path guarantees. Returns
|
|
3241
4199
|
* `Option.none()` when the target is not reachable, and throws a `GraphError`
|
|
3242
|
-
* when either endpoint is missing or
|
|
4200
|
+
* when either endpoint is missing or an edge cost is negative or `NaN`.
|
|
3243
4201
|
*
|
|
3244
4202
|
* **Example** (Finding shortest paths with A-star)
|
|
3245
4203
|
*
|
|
@@ -3283,10 +4241,11 @@ export declare const astar: {
|
|
|
3283
4241
|
*
|
|
3284
4242
|
* **Details**
|
|
3285
4243
|
*
|
|
3286
|
-
* The edge-cost function must return non-negative weights
|
|
4244
|
+
* The edge-cost function must return non-negative weights and not `NaN`.
|
|
4245
|
+
* `Infinity` is allowed and behaves like an impassable edge. The heuristic
|
|
3287
4246
|
* should be consistent to preserve shortest-path guarantees. Returns
|
|
3288
4247
|
* `Option.none()` when the target is not reachable, and throws a `GraphError`
|
|
3289
|
-
* when either endpoint is missing or
|
|
4248
|
+
* when either endpoint is missing or an edge cost is negative or `NaN`.
|
|
3290
4249
|
*
|
|
3291
4250
|
* **Example** (Finding shortest paths with A-star)
|
|
3292
4251
|
*
|
|
@@ -3356,9 +4315,10 @@ export interface BellmanFordConfig<E> {
|
|
|
3356
4315
|
*
|
|
3357
4316
|
* **Details**
|
|
3358
4317
|
*
|
|
3359
|
-
* Negative edge weights are allowed
|
|
3360
|
-
*
|
|
3361
|
-
*
|
|
4318
|
+
* Negative edge weights are allowed, and `Infinity` behaves like an impassable
|
|
4319
|
+
* edge. Returns `Option.none()` when the target is unreachable or when a
|
|
4320
|
+
* negative cycle affects the path to the target. Throws a `GraphError` when
|
|
4321
|
+
* either endpoint is missing or an edge weight is `NaN` or `-Infinity`.
|
|
3362
4322
|
*
|
|
3363
4323
|
* **Example** (Finding shortest paths with Bellman-Ford)
|
|
3364
4324
|
*
|
|
@@ -3396,9 +4356,10 @@ export declare const bellmanFord: {
|
|
|
3396
4356
|
*
|
|
3397
4357
|
* **Details**
|
|
3398
4358
|
*
|
|
3399
|
-
* Negative edge weights are allowed
|
|
3400
|
-
*
|
|
3401
|
-
*
|
|
4359
|
+
* Negative edge weights are allowed, and `Infinity` behaves like an impassable
|
|
4360
|
+
* edge. Returns `Option.none()` when the target is unreachable or when a
|
|
4361
|
+
* negative cycle affects the path to the target. Throws a `GraphError` when
|
|
4362
|
+
* either endpoint is missing or an edge weight is `NaN` or `-Infinity`.
|
|
3402
4363
|
*
|
|
3403
4364
|
* **Example** (Finding shortest paths with Bellman-Ford)
|
|
3404
4365
|
*
|
|
@@ -3436,9 +4397,10 @@ export declare const bellmanFord: {
|
|
|
3436
4397
|
*
|
|
3437
4398
|
* **Details**
|
|
3438
4399
|
*
|
|
3439
|
-
* Negative edge weights are allowed
|
|
3440
|
-
*
|
|
3441
|
-
*
|
|
4400
|
+
* Negative edge weights are allowed, and `Infinity` behaves like an impassable
|
|
4401
|
+
* edge. Returns `Option.none()` when the target is unreachable or when a
|
|
4402
|
+
* negative cycle affects the path to the target. Throws a `GraphError` when
|
|
4403
|
+
* either endpoint is missing or an edge weight is `NaN` or `-Infinity`.
|
|
3442
4404
|
*
|
|
3443
4405
|
* **Example** (Finding shortest paths with Bellman-Ford)
|
|
3444
4406
|
*
|
|
@@ -3698,7 +4660,8 @@ export declare const entries: <T, N>(walker: Walker<T, N>) => Iterable<[T, N]>;
|
|
|
3698
4660
|
*
|
|
3699
4661
|
* `start` supplies the node indices where traversal begins. If it is omitted,
|
|
3700
4662
|
* the iterator is empty. `direction` chooses whether traversal follows
|
|
3701
|
-
* outgoing
|
|
4663
|
+
* outgoing edges, incoming edges, or ignores edge direction. `radius` limits
|
|
4664
|
+
* traversal by edge distance from the nearest start node.
|
|
3702
4665
|
*
|
|
3703
4666
|
* **Gotchas**
|
|
3704
4667
|
*
|
|
@@ -3714,7 +4677,8 @@ export declare const entries: <T, N>(walker: Walker<T, N>) => Iterable<[T, N]>;
|
|
|
3714
4677
|
*/
|
|
3715
4678
|
export interface SearchConfig {
|
|
3716
4679
|
readonly start?: Array<NodeIndex>;
|
|
3717
|
-
readonly direction?:
|
|
4680
|
+
readonly direction?: TraversalDirection;
|
|
4681
|
+
readonly radius?: number;
|
|
3718
4682
|
}
|
|
3719
4683
|
/**
|
|
3720
4684
|
* Creates a lazy depth-first traversal iterator from the configured start
|
|
@@ -3723,7 +4687,8 @@ export interface SearchConfig {
|
|
|
3723
4687
|
* **Details**
|
|
3724
4688
|
*
|
|
3725
4689
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3726
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4690
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4691
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3727
4692
|
* if any configured start node does not exist.
|
|
3728
4693
|
*
|
|
3729
4694
|
* **Example** (Traversing depth-first)
|
|
@@ -3761,7 +4726,8 @@ export declare const dfs: {
|
|
|
3761
4726
|
* **Details**
|
|
3762
4727
|
*
|
|
3763
4728
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3764
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4729
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4730
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3765
4731
|
* if any configured start node does not exist.
|
|
3766
4732
|
*
|
|
3767
4733
|
* **Example** (Traversing depth-first)
|
|
@@ -3799,7 +4765,8 @@ export declare const dfs: {
|
|
|
3799
4765
|
* **Details**
|
|
3800
4766
|
*
|
|
3801
4767
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3802
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4768
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4769
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3803
4770
|
* if any configured start node does not exist.
|
|
3804
4771
|
*
|
|
3805
4772
|
* **Example** (Traversing depth-first)
|
|
@@ -3838,7 +4805,8 @@ export declare const dfs: {
|
|
|
3838
4805
|
* **Details**
|
|
3839
4806
|
*
|
|
3840
4807
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3841
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4808
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4809
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3842
4810
|
* if any configured start node does not exist.
|
|
3843
4811
|
*
|
|
3844
4812
|
* **Example** (Traversing breadth-first)
|
|
@@ -3876,7 +4844,8 @@ export declare const bfs: {
|
|
|
3876
4844
|
* **Details**
|
|
3877
4845
|
*
|
|
3878
4846
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3879
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4847
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4848
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3880
4849
|
* if any configured start node does not exist.
|
|
3881
4850
|
*
|
|
3882
4851
|
* **Example** (Traversing breadth-first)
|
|
@@ -3914,7 +4883,8 @@ export declare const bfs: {
|
|
|
3914
4883
|
* **Details**
|
|
3915
4884
|
*
|
|
3916
4885
|
* If no start nodes are supplied, the iterator is empty. The `direction` option
|
|
3917
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
4886
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
4887
|
+
* limits traversal by edge distance from the start nodes. Throws a `GraphError`
|
|
3918
4888
|
* if any configured start node does not exist.
|
|
3919
4889
|
*
|
|
3920
4890
|
* **Example** (Traversing breadth-first)
|
|
@@ -4064,7 +5034,7 @@ export declare const topo: {
|
|
|
4064
5034
|
* @category iterators
|
|
4065
5035
|
* @since 3.18.0
|
|
4066
5036
|
*/
|
|
4067
|
-
(config?: TopoConfig): <N, E
|
|
5037
|
+
(config?: TopoConfig): <N, E>(graph: Graph<N, E, "directed"> | MutableGraph<N, E, "directed">) => NodeWalker<N>;
|
|
4068
5038
|
/**
|
|
4069
5039
|
* Creates a new topological sort iterator with optional configuration.
|
|
4070
5040
|
*
|
|
@@ -4111,7 +5081,7 @@ export declare const topo: {
|
|
|
4111
5081
|
* @category iterators
|
|
4112
5082
|
* @since 3.18.0
|
|
4113
5083
|
*/
|
|
4114
|
-
<N, E
|
|
5084
|
+
<N, E>(graph: Graph<N, E, "directed"> | MutableGraph<N, E, "directed">, config?: TopoConfig): NodeWalker<N>;
|
|
4115
5085
|
};
|
|
4116
5086
|
/**
|
|
4117
5087
|
* Creates a lazy depth-first postorder traversal iterator from the configured
|
|
@@ -4121,7 +5091,14 @@ export declare const topo: {
|
|
|
4121
5091
|
*
|
|
4122
5092
|
* Nodes are emitted after their reachable descendants have been processed. If
|
|
4123
5093
|
* no start nodes are supplied, the iterator is empty. The `direction` option
|
|
4124
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
5094
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
5095
|
+
* limits traversal by edge distance from the start nodes.
|
|
5096
|
+
*
|
|
5097
|
+
* **Gotchas**
|
|
5098
|
+
*
|
|
5099
|
+
* With a finite `radius`, iteration first performs a bounded breadth-first
|
|
5100
|
+
* traversal to determine shortest-distance membership before emitting nodes in
|
|
5101
|
+
* postorder.
|
|
4125
5102
|
*
|
|
4126
5103
|
* **Example** (Traversing in postorder)
|
|
4127
5104
|
*
|
|
@@ -4155,7 +5132,14 @@ export declare const dfsPostOrder: {
|
|
|
4155
5132
|
*
|
|
4156
5133
|
* Nodes are emitted after their reachable descendants have been processed. If
|
|
4157
5134
|
* no start nodes are supplied, the iterator is empty. The `direction` option
|
|
4158
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
5135
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
5136
|
+
* limits traversal by edge distance from the start nodes.
|
|
5137
|
+
*
|
|
5138
|
+
* **Gotchas**
|
|
5139
|
+
*
|
|
5140
|
+
* With a finite `radius`, iteration first performs a bounded breadth-first
|
|
5141
|
+
* traversal to determine shortest-distance membership before emitting nodes in
|
|
5142
|
+
* postorder.
|
|
4159
5143
|
*
|
|
4160
5144
|
* **Example** (Traversing in postorder)
|
|
4161
5145
|
*
|
|
@@ -4189,7 +5173,14 @@ export declare const dfsPostOrder: {
|
|
|
4189
5173
|
*
|
|
4190
5174
|
* Nodes are emitted after their reachable descendants have been processed. If
|
|
4191
5175
|
* no start nodes are supplied, the iterator is empty. The `direction` option
|
|
4192
|
-
* chooses whether to follow outgoing or incoming edges.
|
|
5176
|
+
* chooses whether to follow outgoing or incoming edges. The `radius` option
|
|
5177
|
+
* limits traversal by edge distance from the start nodes.
|
|
5178
|
+
*
|
|
5179
|
+
* **Gotchas**
|
|
5180
|
+
*
|
|
5181
|
+
* With a finite `radius`, iteration first performs a bounded breadth-first
|
|
5182
|
+
* traversal to determine shortest-distance membership before emitting nodes in
|
|
5183
|
+
* postorder.
|
|
4193
5184
|
*
|
|
4194
5185
|
* **Example** (Traversing in postorder)
|
|
4195
5186
|
*
|