@graphty/graphty-element 2.5.2 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/dist/ai.js +3 -3
  2. package/dist/catalog.d.ts +16 -0
  3. package/dist/catalog.js +34 -32
  4. package/dist/chunks/{AiManager-CrbvKdEK.js → AiManager-4iQpsJW1.js} +4 -4
  5. package/dist/chunks/{DataSource-qU-nLhXN.js → DataSource-BL2UzPff.js} +2 -2
  6. package/dist/chunks/GraphSession-BhuHSXIo.js +12819 -0
  7. package/dist/chunks/{GraphtyLogger-DOTwCiMR.js → GraphtyLogger-B_O67a6c.js} +1 -1
  8. package/dist/chunks/{VoiceInputAdapter-D4NrRL_1.js → VoiceInputAdapter-Cc6mHXTI.js} +1 -1
  9. package/dist/chunks/{XRPivotCameraController-Uqa47vmo.js → XRPivotCameraController-BLa89LXn.js} +2 -2
  10. package/dist/chunks/{algorithms-D-ab-Auu.js → algorithms-BJ6DQMOe.js} +931 -781
  11. package/dist/chunks/{capability-check-Vw3IcqiE.js → capability-check-Am2zliFj.js} +1 -1
  12. package/dist/chunks/{detect-B4Qrw976.js → detect-fyuVnlCT.js} +1 -1
  13. package/dist/chunks/{format-detection-r2IfNFXO.js → format-detection-BHwrAVzW.js} +1 -1
  14. package/dist/chunks/{index-J9MgLio9.js → index-BkBLbvui.js} +2691 -2434
  15. package/dist/chunks/optionsFromZod-CKMYSwTz.js +3636 -0
  16. package/dist/chunks/{paletteRegistry-Kt-6CeoN.js → paletteRegistry-BCFSwJGK.js} +224 -189
  17. package/dist/chunks/parse-BMTqt4SS.js +3658 -0
  18. package/dist/chunks/{types-C_c53VgR.js → types-DFchv4Ny.js} +4 -1
  19. package/dist/custom-elements.json +1 -1
  20. package/dist/extend.d.ts +10 -8
  21. package/dist/extend.js +6 -6
  22. package/dist/graphty-catalog.json +75 -38
  23. package/dist/graphty.bundle.js +55368 -48970
  24. package/dist/graphty.js +19 -19
  25. package/dist/index.d.ts +1 -1
  26. package/dist/logging.js +2 -2
  27. package/dist/schema.d.ts +15 -1
  28. package/dist/schema.js +1 -1
  29. package/dist/session.d.ts +30 -7
  30. package/dist/session.js +40 -37
  31. package/dist/src/Graph.d.ts +35 -7
  32. package/dist/src/acceleration/types.d.ts +79 -43
  33. package/dist/src/algorithms/Algorithm.d.ts +52 -4
  34. package/dist/src/algorithms/BFSAlgorithm.d.ts +3 -0
  35. package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +3 -0
  36. package/dist/src/algorithms/BetweennessCentralityAlgorithm.d.ts +3 -0
  37. package/dist/src/algorithms/BipartiteMatchingAlgorithm.d.ts +3 -0
  38. package/dist/src/algorithms/ClosenessCentralityAlgorithm.d.ts +3 -0
  39. package/dist/src/algorithms/ConnectedComponentsAlgorithm.d.ts +4 -1
  40. package/dist/src/algorithms/DFSAlgorithm.d.ts +3 -0
  41. package/dist/src/algorithms/DegreeAlgorithm.d.ts +3 -0
  42. package/dist/src/algorithms/DijkstraAlgorithm.d.ts +6 -0
  43. package/dist/src/algorithms/EigenvectorCentralityAlgorithm.d.ts +2 -0
  44. package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +3 -0
  45. package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +3 -0
  46. package/dist/src/algorithms/HITSAlgorithm.d.ts +3 -0
  47. package/dist/src/algorithms/KCoreAlgorithm.d.ts +3 -0
  48. package/dist/src/algorithms/KatzCentralityAlgorithm.d.ts +3 -0
  49. package/dist/src/algorithms/KruskalAlgorithm.d.ts +4 -1
  50. package/dist/src/algorithms/LabelPropagationAlgorithm.d.ts +3 -0
  51. package/dist/src/algorithms/LeidenAlgorithm.d.ts +3 -0
  52. package/dist/src/algorithms/LinkPredictionAlgorithm.d.ts +4 -1
  53. package/dist/src/algorithms/LouvainAlgorithm.d.ts +3 -0
  54. package/dist/src/algorithms/MaxFlowAlgorithm.d.ts +3 -0
  55. package/dist/src/algorithms/MinCutAlgorithm.d.ts +3 -0
  56. package/dist/src/algorithms/PageRankAlgorithm.d.ts +3 -0
  57. package/dist/src/algorithms/PrimAlgorithm.d.ts +3 -0
  58. package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +3 -0
  59. package/dist/src/algorithms/input/ScopedInput.d.ts +185 -0
  60. package/dist/src/algorithms/input/derivedInputs.d.ts +199 -0
  61. package/dist/src/algorithms/input/maskBack.d.ts +37 -0
  62. package/dist/src/algorithms/metrics/MetricAlgorithm.d.ts +3 -3
  63. package/dist/src/algorithms/results/DeclaredAlgorithm.d.ts +4 -3
  64. package/dist/src/algorithms/results/types.d.ts +28 -6
  65. package/dist/src/algorithms/utils/communityUtils.d.ts +0 -48
  66. package/dist/src/algorithms/utils/graphUtils.d.ts +2 -68
  67. package/dist/src/algorithms/utils/snapshotGraph.d.ts +3 -1
  68. package/dist/src/catalog/algorithms.d.ts +3 -0
  69. package/dist/src/catalog/layouts.d.ts +2 -0
  70. package/dist/src/catalog/sets/canonical.d.ts +68 -0
  71. package/dist/src/catalog/sets/hash.d.ts +126 -0
  72. package/dist/src/catalog/sets/parse.d.ts +115 -0
  73. package/dist/src/catalog/types.d.ts +329 -8
  74. package/dist/src/data/GraphStore.d.ts +73 -1
  75. package/dist/src/data/edgeIdentity.d.ts +202 -1
  76. package/dist/src/data/ingest.d.ts +3 -1
  77. package/dist/src/data/report.d.ts +20 -0
  78. package/dist/src/graphty-element.d.ts +42 -6
  79. package/dist/src/layout/D3GraphLayoutEngine.d.ts +11 -0
  80. package/dist/src/layout/LayoutEngine.d.ts +56 -0
  81. package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -0
  82. package/dist/src/layout/SimulationLayoutEngine.d.ts +11 -0
  83. package/dist/src/managers/AlgorithmManager.d.ts +8 -0
  84. package/dist/src/managers/DataManager.d.ts +11 -0
  85. package/dist/src/managers/LayoutManager.d.ts +126 -2
  86. package/dist/src/managers/StatsManager.d.ts +1 -0
  87. package/dist/src/session/GraphSession.d.ts +48 -0
  88. package/dist/src/session/attributes.d.ts +121 -1
  89. package/dist/src/session/cost/estimate.d.ts +20 -0
  90. package/dist/src/session/cost/index.d.ts +1 -1
  91. package/dist/src/session/planning.d.ts +32 -2
  92. package/dist/src/session/query.d.ts +7 -0
  93. package/dist/src/session/results/ResultsApi.d.ts +14 -1
  94. package/dist/src/session/runs/Run.d.ts +65 -4
  95. package/dist/src/session/runs/RunsApi.d.ts +58 -2
  96. package/dist/src/session/runs/runId.d.ts +55 -6
  97. package/dist/src/session/runs/types.d.ts +36 -8
  98. package/dist/src/session/scope/ElementMask.d.ts +14 -1
  99. package/dist/src/session/scope/ScopeApi.d.ts +160 -31
  100. package/dist/src/session/scope/index.d.ts +1 -1
  101. package/dist/src/session/selection/SelectionApi.d.ts +15 -10
  102. package/dist/src/session/selection/index.d.ts +1 -1
  103. package/dist/src/session/selection/targets.d.ts +6 -7
  104. package/dist/src/session/sets/SetsApi.d.ts +110 -0
  105. package/dist/src/session/sets/algebra.d.ts +124 -0
  106. package/dist/src/session/sets/cache.d.ts +197 -0
  107. package/dist/src/session/sets/captures.d.ts +83 -0
  108. package/dist/src/session/sets/dependencies.d.ts +167 -0
  109. package/dist/src/session/sets/layers.d.ts +101 -0
  110. package/dist/src/session/sets/notify.d.ts +122 -0
  111. package/dist/src/session/sets/offers.d.ts +103 -0
  112. package/dist/src/session/sets/path.d.ts +37 -0
  113. package/dist/src/session/sets/prepare.d.ts +209 -0
  114. package/dist/src/session/sets/resolve.d.ts +311 -0
  115. package/dist/src/session/sets/signature.d.ts +77 -0
  116. package/dist/src/session/sets/status.d.ts +98 -0
  117. package/dist/src/session/sets/store.d.ts +196 -0
  118. package/dist/src/session/sets/types.d.ts +386 -0
  119. package/dist/src/session/styles/Layer.d.ts +9 -2
  120. package/dist/src/session/styles/StylesApi.d.ts +5 -2
  121. package/dist/src/session/styles/explain.d.ts +5 -2
  122. package/dist/src/session/styles/predicate.d.ts +41 -2
  123. package/dist/src/session/styles/repaint.d.ts +19 -0
  124. package/dist/src/session/styles/selector.d.ts +16 -5
  125. package/dist/src/session/types.d.ts +18 -0
  126. package/dist/src/session/visibility/VisibilityApi.d.ts +47 -3
  127. package/dist/src/session/visibility/filter.d.ts +86 -51
  128. package/dist/src/session/visibility/index.d.ts +1 -1
  129. package/dist/src/testing/fakeAccelerator.d.ts +5 -0
  130. package/dist/src/utils/queue-migration.d.ts +17 -0
  131. package/package.json +15 -9
  132. package/dist/chunks/GraphSession-DuAhRgCd.js +0 -8622
  133. package/dist/chunks/optionsFromZod-B9RncoTX.js +0 -2578
  134. package/dist/chunks/scales-CJCRwi2J.js +0 -3220
  135. package/dist/src/algorithms/utils/index.d.ts +0 -6
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @file The one input accessor a run reads its graph through (design/sets/sets-design.md section
3
+ * 10.1), and the binding that tells it which scope the run is over.
4
+ *
5
+ * Derivation is SCOPE FIRST: the declared snapshot, then `inducedSubgraph(node bitmap)`, then
6
+ * `filterEdges(edge bitmap)` only when the scope's edges are not all the edges its nodes induce,
7
+ * then `toUndirected` when asked, then `simplified` by the asked merge policy. The scope is applied
8
+ * in declared space before undirecting because `toUndirected` collapses a reciprocal pair into one
9
+ * edge that keeps the lower index's row: undirecting first would hand a thresholded run the weight
10
+ * of a hidden edge. The input is never built by inducing on edge endpoints, so a scope with
11
+ * isolated nodes keeps them.
12
+ *
13
+ * WHOLE-GRAPH SHORTCUT: a scope covering every node and every edge -- or no scope at all -- takes
14
+ * exactly the route the element took before scopes existed: the snapshot unchanged, the store's
15
+ * per-snapshot undirected cache for the undirected view, and the merge of parallel edges.
16
+ *
17
+ * WHO GETS A SCOPED INPUT is decided per algorithm class: only a class declaring
18
+ * `static scopeInput = "subgraph"` is handed its run's scope. Every other class reads the whole
19
+ * graph through the same accessor, because an algorithm that enumerates its nodes from the data
20
+ * manager would otherwise compute over a scoped topology while listing every node.
21
+ *
22
+ * Nothing here reaches Babylon.js, Lit or the DOM.
23
+ */
24
+ import { type DerivedGraph, type EdgeMask, type GraphSnapshot, type NodeMask } from "@graphty/graph-format";
25
+ import type { AlgorithmDescriptor, EdgeId, EdgeReading, NodeId } from "../../catalog/types";
26
+ import type { Resolution } from "../../session/sets/resolve";
27
+ import { type DerivedInput, DerivedInputs, type InputOrientation } from "./derivedInputs";
28
+ /** Counts the input tests read: `derivations` is one per graph-format derivation, each a CSR pass. */
29
+ export declare const scopedInputCounters: {
30
+ derivations: number;
31
+ };
32
+ /** How a run wants its input built. OPEN: may gain members. */
33
+ export interface ScopedInputOptions {
34
+ /**
35
+ * How parallel edges merge in `subgraph()`. OPEN UNION. Default "sum", the element's reading
36
+ * of a repeated edge as more connection; shortest paths want "min".
37
+ */
38
+ readonly simplify?: "sum" | "min" | "max" | "none";
39
+ }
40
+ /** What a scoped run computes over (design 10.2). OPEN: may gain members. */
41
+ export interface ScopedInput {
42
+ /** The full graph, declared orientation. */
43
+ readonly graph: GraphSnapshot;
44
+ /** The scope's nodes; valid in both orientations (undirecting keeps node rows). */
45
+ readonly nodes: NodeMask;
46
+ /** The scope's edges over the declared `graph` only, whatever orientation was asked. */
47
+ readonly edges: EdgeMask;
48
+ /** True when the scope is the whole graph; `subgraph()` then returns `graph` (or its undirected view). */
49
+ readonly whole: boolean;
50
+ /** How many nodes the scope holds: the set bits of `nodes`. */
51
+ readonly nodeCount: number;
52
+ /** How many edges the scope holds: the set bits of `edges`. */
53
+ readonly edgeCount: number;
54
+ /** The derived compact snapshot in the asked orientation. Lazy, cached, shared. */
55
+ subgraph(): GraphSnapshot;
56
+ }
57
+ /**
58
+ * The element's own input, which also carries the maps back to the declared graph.
59
+ * @internal
60
+ */
61
+ export interface ElementScopedInput extends ScopedInput {
62
+ /**
63
+ * The derived snapshot with its maps.
64
+ * @returns The input.
65
+ */
66
+ derived(): DerivedInput;
67
+ }
68
+ /** The two data-manager members the accessor reads. */
69
+ interface SnapshotSource {
70
+ getSnapshot(): GraphSnapshot;
71
+ undirected(snapshot: GraphSnapshot): DerivedGraph;
72
+ }
73
+ /** A scope resolved against the snapshot it covers. */
74
+ export interface ResolvedInputScope {
75
+ readonly resolution: Resolution;
76
+ readonly graph: GraphSnapshot;
77
+ /** How the scope reads its edges, when the resolver knows; the run's caveat is worded from it. */
78
+ readonly reading?: EdgeReading;
79
+ }
80
+ /** What one run hands its algorithm: the scope, the cache it derives into, and its holder identity. */
81
+ export interface RunInput {
82
+ readonly inputs: DerivedInputs;
83
+ /** The run, as the cache's holder. */
84
+ readonly holder: object;
85
+ /**
86
+ * The run's scope over the current snapshot, or null for the whole graph.
87
+ * @returns The scope.
88
+ */
89
+ scope(): ResolvedInputScope | null;
90
+ }
91
+ /** Which classes declare that they compute over their run's scope. OPEN UNION; "mask" is later. */
92
+ export type ScopeInputDeclaration = NonNullable<AlgorithmDescriptor["scopeInput"]>;
93
+ /**
94
+ * Whether an algorithm's class declares `static scopeInput = "subgraph"`.
95
+ * @param algorithm - The instance.
96
+ * @returns True when it computes over its scope.
97
+ */
98
+ export declare function declaresScopedInput(algorithm: object): boolean;
99
+ /**
100
+ * The run input an algorithm reads through, when its class declares a scoped input.
101
+ * @param algorithm - The instance.
102
+ * @returns The binding, or undefined for the whole graph.
103
+ */
104
+ export declare function runInputOf(algorithm: object): RunInput | undefined;
105
+ /**
106
+ * The scope of the run an algorithm is publishing for, whatever its class declares: what mask-back
107
+ * masks against.
108
+ * @param algorithm - The instance.
109
+ * @returns The scope over the current snapshot, or null outside a run or for the whole graph.
110
+ */
111
+ export declare function runScopeOf(algorithm: object): ResolvedInputScope | null;
112
+ /**
113
+ * The orientation an algorithm-graph mode reads.
114
+ * @param mode - `"directed"` or `"undirected"`.
115
+ * @returns The orientation.
116
+ */
117
+ export declare function orientationOf(mode: "directed" | "undirected"): InputOrientation;
118
+ /**
119
+ * The input one algorithm reads, in one orientation.
120
+ * @param data - The data manager.
121
+ * @param orientation - The orientation.
122
+ * @param options - The merge policy.
123
+ * @param run - The run's binding, when the algorithm declares a scoped input and runs as a run.
124
+ * @returns The input.
125
+ * @throws An Error when the run's scope was resolved against another snapshot than the current one.
126
+ */
127
+ export declare function createScopedInput(data: SnapshotSource, orientation: InputOrientation, options?: ScopedInputOptions, run?: RunInput): ElementScopedInput;
128
+ /**
129
+ * The nodes an input covers, in declared row order: the order of the compact snapshot's rows, and
130
+ * the order an adapter lists what it publishes in.
131
+ * @param input - The input.
132
+ * @returns The node ids.
133
+ */
134
+ export declare function scopeNodeIds(input: ScopedInput): NodeId[];
135
+ /** One declared edge an input covers: its session id, its row in the declared graph, and its ends. */
136
+ interface ScopeEdge {
137
+ readonly id: EdgeId;
138
+ /** The row in `ScopedInput.graph`, which is what an edge remap is indexed by. */
139
+ readonly row: number;
140
+ /** The source node, in the declared orientation. */
141
+ readonly source: NodeId;
142
+ /** The target node, in the declared orientation. */
143
+ readonly target: NodeId;
144
+ }
145
+ /**
146
+ * The declared edges an input covers, in row order.
147
+ * @param input - The input.
148
+ * @returns The edges.
149
+ * @throws An Error when the graph carries no edge id column, which every store declares.
150
+ */
151
+ export declare function scopeEdges(input: ScopedInput): ScopeEdge[];
152
+ /** What owns a graph's derived inputs: the graph, and the accelerator its release goes to. */
153
+ interface InputOwner {
154
+ readonly acceleration: {
155
+ readonly accelerator: Readonly<Record<string, unknown>> | null;
156
+ };
157
+ }
158
+ /**
159
+ * A graph's derived inputs, built on first use. Released snapshots go to the attached
160
+ * accelerator's `release`, when it has one.
161
+ * @param owner - The graph.
162
+ * @returns Its cache.
163
+ */
164
+ export declare function derivedInputsOf(owner: InputOwner): DerivedInputs;
165
+ /**
166
+ * A graph's derived inputs, if any were ever built. For the freeze and dispose hooks.
167
+ * @param owner - The graph.
168
+ * @returns Its cache, or undefined.
169
+ */
170
+ export declare function peekDerivedInputs(owner: object): DerivedInputs | undefined;
171
+ /**
172
+ * Run one algorithm's work with its run's scope bound: a class declaring a scoped input reads the
173
+ * scope through `Algorithm.input`, and every input it derives is held until the work settles --
174
+ * published or aborted -- and only then may be released.
175
+ * @param algorithm - The instance.
176
+ * @param owner - The graph it runs on.
177
+ * @param scope - The run's scope over the current snapshot, or null for the whole graph.
178
+ * @param signal - Aborts a wait for room.
179
+ * @param work - The work.
180
+ * @returns What the work returned.
181
+ */
182
+ export declare function withRunInput<T>(algorithm: object, owner: InputOwner & {
183
+ getDataManager(): SnapshotSource;
184
+ }, scope: () => ResolvedInputScope | null, signal: AbortSignal | undefined, work: () => Promise<T>): Promise<T>;
185
+ export {};
@@ -0,0 +1,199 @@
1
+ /**
2
+ * @file The derived-input cache (design/sets/sets-design.md sections 10.3 and 10.4): the compact
3
+ * snapshots a scoped run computes over, kept so a repeated scoped run hands an accelerator the
4
+ * SAME snapshot object and hits its upload cache instead of uploading the graph again.
5
+ *
6
+ * An entry is keyed by (store, snapshot serial, resolution signature, orientation,
7
+ * simplification). The resolution signature is a hash of the node and edge bitmaps, and a hit is
8
+ * confirmed word for word against the bitmaps the entry was derived for, so two scopes spelled
9
+ * differently that cover the same elements share one input, and a hash collision can never hand a
10
+ * run somebody else's graph.
11
+ *
12
+ * ENTRIES ARE REFERENCE-COUNTED. A run holds every entry it derived or looked up from the moment
13
+ * it asks until its result is published or it is aborted. GPU memory is not garbage collected and
14
+ * an accelerator's `release` destroys device buffers at once, so an entry is only ever MARKED
15
+ * while held -- by byte pressure, a freeze or dispose -- and the release runs when the last holder
16
+ * lets go. Nothing runs on memory that has gone, the guarantee `Graph.ts` gives a layout.
17
+ *
18
+ * BYTES are the typed arrays reachable from the live entries, each counted once however many
19
+ * entries reach it: the derived snapshots with their columns, id maps and whatever views an
20
+ * algorithm built on them since, the composed maps, and the bitmaps a hit is checked against. The
21
+ * bound is max(256 MB, 1.5 x the full snapshot's bytes), so one ordinary scoped run always fits.
22
+ * Held entries count against it and are never evicted; a run that cannot fit waits for a DIFFERENT
23
+ * run to let go, or is refused `E_TOO_LARGE` when no other run holds anything. A run never waits
24
+ * on itself: once it holds an input, whatever else it derives is admitted over the bound.
25
+ *
26
+ * Device bytes are the accelerator's to count; they are not in this bound.
27
+ *
28
+ * Nothing here reaches Babylon.js, Lit or the DOM.
29
+ */
30
+ import type { GraphSnapshot, U32 } from "@graphty/graph-format";
31
+ /** How a run wants its input's parallel edges merged. OPEN UNION (design 10.2). */
32
+ export type SimplifyPolicy = "sum" | "min" | "max" | "none";
33
+ /** Which orientation a run reads. */
34
+ export type InputOrientation = "declared" | "undirected";
35
+ /** Counts the cache tests read. */
36
+ export declare const derivedInputCounters: {
37
+ hits: number;
38
+ misses: number;
39
+ released: number;
40
+ };
41
+ /** One derived input: the snapshot a run computes over and the maps back to the declared graph. */
42
+ export interface DerivedInput {
43
+ /** The compact snapshot, in the asked orientation and simplified by the asked policy. */
44
+ readonly snapshot: GraphSnapshot;
45
+ /** Declared edge index -> edge index in {@link snapshot}, INVALID_INDEX when dropped; null when unchanged. */
46
+ readonly edgeRemap: U32 | null;
47
+ /** Node index in {@link snapshot} -> declared node index; null when unchanged. */
48
+ readonly nodeOrigin: U32 | null;
49
+ }
50
+ /** The membership an input is derived for: a resolution's bitmaps, over one snapshot of one store. */
51
+ export interface InputMembership {
52
+ readonly nodes: U32;
53
+ readonly edges: U32;
54
+ readonly serial: number;
55
+ readonly store: object | null;
56
+ }
57
+ /** A read-only view of one entry, for the accounting test. */
58
+ interface DerivedInputEntry extends DerivedInput {
59
+ readonly key: string;
60
+ readonly held: boolean;
61
+ readonly marked: boolean;
62
+ /** The bitmaps the entry was derived for. */
63
+ readonly nodes: U32;
64
+ readonly edges: U32;
65
+ }
66
+ /** One session graph's derived inputs. */
67
+ export declare class DerivedInputs {
68
+ private readonly options;
69
+ /** Entries, least recently used first. */
70
+ private readonly entries;
71
+ /** Entries kept only until their holders let go: marked, and no longer reachable by key. */
72
+ private readonly draining;
73
+ /** Bytes each waiting-or-running run reserved before deriving. */
74
+ private readonly reservations;
75
+ /** Runs waiting for another run to let go. */
76
+ private waiters;
77
+ /** The full snapshot's bytes, as last seen. */
78
+ private fullBytes;
79
+ private disposed;
80
+ /**
81
+ * An empty cache.
82
+ * @param options - The release hook and, for tests, the byte bound.
83
+ * @param options.release - Frees an accelerator's device buffers for a snapshot nothing uses.
84
+ * @param options.limit - A fixed byte bound instead of max(256 MB, 1.5 x the full snapshot).
85
+ */
86
+ constructor(options?: {
87
+ readonly release?: (snapshot: GraphSnapshot) => void;
88
+ readonly limit?: number;
89
+ });
90
+ /**
91
+ * The byte bound now.
92
+ * @returns The bound.
93
+ */
94
+ get bound(): number;
95
+ /**
96
+ * The bytes the live entries hold, draining ones included.
97
+ * @returns The byte count.
98
+ */
99
+ get bytes(): number;
100
+ /**
101
+ * Every live entry, draining ones included, least recently used first. For the accounting test.
102
+ * @returns The entries.
103
+ */
104
+ list(): DerivedInputEntry[];
105
+ /**
106
+ * A cached input, held for a run on a hit.
107
+ * @param holder - The run.
108
+ * @param membership - What it is derived for.
109
+ * @param orientation - The orientation.
110
+ * @param simplify - The merge policy.
111
+ * @returns The input, or undefined on a miss.
112
+ */
113
+ get(holder: object, membership: InputMembership, orientation: InputOrientation, simplify: SimplifyPolicy): DerivedInput | undefined;
114
+ /**
115
+ * Cache an input a run derived, held for it, then evict unheld entries past the bound.
116
+ * @param holder - The run.
117
+ * @param membership - What it was derived for.
118
+ * @param orientation - The orientation.
119
+ * @param simplify - The merge policy.
120
+ * @param input - The derived input.
121
+ * @param full - The full snapshot it was derived from, whose bytes set the bound.
122
+ * @returns The input.
123
+ */
124
+ put(holder: object, membership: InputMembership, orientation: InputOrientation, simplify: SimplifyPolicy, input: DerivedInput, full: GraphSnapshot): DerivedInput;
125
+ /**
126
+ * Reserve room for a run's derivation before it starts. Evicts unheld entries to make room;
127
+ * waits while a DIFFERENT run holds or reserves what would free it; refuses `E_TOO_LARGE`
128
+ * when nothing else holds anything and it still does not fit. A run that already holds an
129
+ * input is admitted at once: it never waits on itself.
130
+ * @param holder - The run.
131
+ * @param estimate - The bytes its derivation is expected to take.
132
+ * @param full - The full snapshot, whose bytes set the bound.
133
+ * @param signal - Aborts the wait.
134
+ * @returns Resolves once the run may derive.
135
+ */
136
+ reserve(holder: object, estimate: number, full: GraphSnapshot, signal?: AbortSignal): Promise<void>;
137
+ /**
138
+ * A run published or aborted: it lets go of every input it held and its reservation. A marked
139
+ * input with no holder left is released; waiting runs try again.
140
+ * @param holder - The run.
141
+ */
142
+ releaseHolder(holder: object): void;
143
+ /** The graph froze: every entry is over a snapshot that has gone. */
144
+ freeze(): void;
145
+ /** The graph is being torn down: release what nothing holds, mark the rest, cache nothing more. */
146
+ dispose(): void;
147
+ /**
148
+ * Mark every entry over another snapshot or store than this membership's.
149
+ * @param membership - The membership now being asked for.
150
+ */
151
+ private sync;
152
+ /**
153
+ * Evict unheld entries, least recently used first, until the bytes fit.
154
+ * @param budget - The bytes to fit in; the bound by default.
155
+ */
156
+ private shrink;
157
+ /**
158
+ * Take an entry out of the cache: released at once when unheld, else marked and drained.
159
+ * @param entry - It.
160
+ */
161
+ private evictEntry;
162
+ /**
163
+ * Release an entry's snapshot, unless another live entry still reaches the same one.
164
+ * @param entry - It.
165
+ */
166
+ private free;
167
+ /**
168
+ * Every live entry: cached and draining.
169
+ * @yields Each entry.
170
+ */
171
+ private live;
172
+ /**
173
+ * Whether a run holds anything.
174
+ * @param holder - The run.
175
+ * @returns True when it does.
176
+ */
177
+ private holds;
178
+ /**
179
+ * Whether a run other than this one holds an input or a reservation.
180
+ * @param holder - The run asking.
181
+ * @returns True when another does.
182
+ */
183
+ private othersHold;
184
+ /**
185
+ * The bytes other runs reserved and have not yet derived.
186
+ * @param holder - The run asking, left out.
187
+ * @returns The byte count.
188
+ */
189
+ private pending;
190
+ /**
191
+ * Resolves the next time a run lets go or the graph freezes.
192
+ * @param signal - Rejects the wait when aborted.
193
+ * @returns The wait.
194
+ */
195
+ private nextRelease;
196
+ /** Let every waiting run try again. */
197
+ private wake;
198
+ }
199
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @file Central mask-back of a scoped run's published values, the caveat that says what the run
3
+ * computed on, and the check of node options against the scope (design/sets/sets-design.md
4
+ * section 10.1).
5
+ *
6
+ * MASK-BACK IS CENTRAL so that it holds whatever path computed a value: an algorithm that fills a
7
+ * default for every element it did not index (Dijkstra's `Infinity` and `onPath: false`), an edge
8
+ * remap that writes every declared edge of a merged group, and an algorithm that computed on the
9
+ * whole graph because it does not declare a scoped input. Every node value outside the scope's
10
+ * node bitmap and every edge value outside its edge bitmap is dropped before the result is built,
11
+ * so it reads missing and is left out of every ranking, histogram and summary.
12
+ *
13
+ * Nothing here reaches Babylon.js, Lit or the DOM.
14
+ */
15
+ import type { OptionDescriptor } from "../../catalog/types";
16
+ import type { RunResultInit } from "../../session/results/RunResult";
17
+ import { type ResolvedInputScope } from "./ScopedInput";
18
+ /** The note a run carries when its algorithm computed on the whole graph and was masked back. */
19
+ export declare const WHOLE_GRAPH_CAVEAT = "Computed on the whole graph; values kept for the scope only.";
20
+ /**
21
+ * A result's inputs with every value outside the run's scope dropped and the scope caveat added.
22
+ * A run over the whole graph, or no run at all, passes unchanged.
23
+ * @param algorithm - The algorithm instance publishing the result.
24
+ * @param init - What it would build the result from.
25
+ * @returns What to build the result from.
26
+ */
27
+ export declare function maskBack(algorithm: object, init: RunResultInit): RunResultInit;
28
+ /**
29
+ * Refuse a node option that names a node of the graph outside the run's scope, before any work
30
+ * starts. An id the graph does not hold at all is left to the algorithm, which says so in its own
31
+ * words.
32
+ * @param options - The algorithm's declared options.
33
+ * @param params - The values the run starts with.
34
+ * @param scope - The run's scope, or null for the whole graph.
35
+ * @throws A `GraphtyError` with `E_OPTION_RANGE` and `details.reason: "outside-scope"`.
36
+ */
37
+ export declare function checkNodeOptions(options: readonly OptionDescriptor[], params: Readonly<Record<string, unknown>>, scope: ResolvedInputScope | null): void;
@@ -17,7 +17,7 @@
17
17
  import type { FieldDescriptor, NodeId } from "../../catalog/types";
18
18
  import { type RunResult } from "../../session/results";
19
19
  import { Algorithm } from "../Algorithm";
20
- import type { AlgorithmRunContext } from "../results/types";
20
+ import type { RunControls } from "../results/types";
21
21
  import type { MetricMeasurement, MetricRunContext } from "./types";
22
22
  /**
23
23
  * A metric: an algorithm that measures one number for every node.
@@ -53,7 +53,7 @@ export declare abstract class MetricAlgorithm<TOptions extends Record<string, un
53
53
  * @returns The result, or undefined when there was nothing to measure.
54
54
  * @throws Whatever the context's signal throws once the run has been cancelled.
55
55
  */
56
- publishResult(context: AlgorithmRunContext, runId: string): Promise<RunResult | undefined>;
56
+ publishResult(context: RunControls, runId: string): Promise<RunResult | undefined>;
57
57
  /**
58
58
  * Measure the graph, publish the result, and project the 1.10 view from it.
59
59
  * @param context - Where progress goes, where cancellation arrives, and which run id to
@@ -71,7 +71,7 @@ export declare abstract class MetricAlgorithm<TOptions extends Record<string, un
71
71
  /**
72
72
  * Measure every node.
73
73
  * @param context - Where progress goes and where cancellation arrives.
74
- * @param nodeIds - The nodes to measure, in the graph's own order.
74
+ * @param nodeIds - The nodes to measure, in the input's row order.
75
75
  * @returns One value per node, how they were scaled, and what qualifies them.
76
76
  */
77
77
  protected abstract measure(context: MetricRunContext, nodeIds: readonly NodeId[]): Promise<MetricMeasurement>;
@@ -9,7 +9,7 @@
9
9
  import type { AlgorithmDescriptor, FieldDescriptor, RunId } from "../../catalog/types";
10
10
  import { type RunResult } from "../../session/results";
11
11
  import { Algorithm } from "../Algorithm";
12
- import { type AlgorithmOutput, type AlgorithmRunContext } from "./types";
12
+ import { type AlgorithmOutput, type AlgorithmRunContext, type RunControls } from "./types";
13
13
  /**
14
14
  * An algorithm whose result is a value it returns.
15
15
  * @template TOptions - The options type this algorithm resolves from its schema.
@@ -92,7 +92,7 @@ export declare abstract class DeclaredAlgorithm<TOptions extends Record<string,
92
92
  * @returns The result, or undefined when there was nothing to compute.
93
93
  * @throws Whatever the context's signal throws once the run has been cancelled.
94
94
  */
95
- publishResult(context: AlgorithmRunContext, runId: RunId, fields?: readonly FieldDescriptor[]): Promise<RunResult | undefined>;
95
+ publishResult(context: RunControls, runId: RunId, fields?: readonly FieldDescriptor[]): Promise<RunResult | undefined>;
96
96
  /**
97
97
  * Compute this algorithm's result, publish it under a run id, and project the 1.x view of it.
98
98
  *
@@ -100,6 +100,7 @@ export declare abstract class DeclaredAlgorithm<TOptions extends Record<string,
100
100
  * because the catalogue states what a reader sees a field called and cannot be imported here
101
101
  * without a cycle -- it reads these classes to publish their options.
102
102
  * @param context - What the element gave the run: a signal, a progress channel and a yield.
103
+ * The graph the run computes over is bound here, as the context's `input`.
103
104
  * @param runId - The id the result is published under, which is the `<runId>` in
104
105
  * `results.<runId>`.
105
106
  * @param declared - The catalogue's descriptors for this algorithm's fields, when the caller
@@ -108,5 +109,5 @@ export declare abstract class DeclaredAlgorithm<TOptions extends Record<string,
108
109
  * @throws Whatever the context's signal throws once the run has been cancelled, which is a
109
110
  * `DOMException` named `AbortError`.
110
111
  */
111
- computeRun(context: AlgorithmRunContext, runId: RunId, declared?: readonly FieldDescriptor[]): Promise<RunResult | undefined>;
112
+ computeRun(context: RunControls, runId: RunId, declared?: readonly FieldDescriptor[]): Promise<RunResult | undefined>;
112
113
  }
@@ -18,6 +18,7 @@
18
18
  import type { EdgeId, FieldDescriptor, ResultShape } from "../../catalog/types";
19
19
  import type { ResultElementValues } from "../../session/results";
20
20
  import type { Caveats, RunDirection, RunProgressReport } from "../../session/runs";
21
+ import type { ScopedInput, ScopedInputOptions } from "../input/ScopedInput";
21
22
  /**
22
23
  * One field a run actually published.
23
24
  *
@@ -81,12 +82,33 @@ export declare function declaredCaveats(init: CaveatsInit): Caveats;
81
82
  /**
82
83
  * What the element gives an algorithm while it runs.
83
84
  *
84
- * The three members are the whole of it: a signal that says stop, a way to say how far along the
85
- * work is, and a way to hand the frame back so a long computation does not lock the screen. An
86
- * algorithm that reports nothing and never yields is indistinguishable, to a reader watching a
87
- * large graph, from one that has hung.
85
+ * Four members: a signal that says stop, a way to say how far along the work is, a way to hand
86
+ * the frame back so a long computation does not lock the screen, and the graph the run computes
87
+ * over. An algorithm that reports nothing and never yields is indistinguishable, to a reader
88
+ * watching a large graph, from one that has hung.
88
89
  */
89
- export interface AlgorithmRunContext {
90
+ export interface AlgorithmRunContext extends RunControls {
91
+ /**
92
+ * The graph this run computes over, in one orientation.
93
+ *
94
+ * A class declaring `static scopeInput = "subgraph"` is handed its run's scope: `subgraph()`
95
+ * is the compact snapshot of the scope's nodes and edges, and `nodes`/`edges` are its masks
96
+ * over the full `graph`. Every other class is handed the whole graph, and the element keeps
97
+ * only the scope's values of what it publishes, with the caveat "Computed on the whole graph;
98
+ * values kept for the scope only." Publish by element id either way; row numbers of a
99
+ * subgraph are not the graph's.
100
+ * @param orientation - `"declared"`, the graph as loaded, or `"undirected"`, with a
101
+ * reciprocal pair collapsed into one edge.
102
+ * @param options - How parallel edges merge in `subgraph()`: `"sum"` by default.
103
+ * @returns The input.
104
+ */
105
+ input(orientation: "declared" | "undirected", options?: ScopedInputOptions): ScopedInput;
106
+ }
107
+ /**
108
+ * The half of a run context that does not depend on which algorithm runs: what a run hands
109
+ * `publishResult`, which binds `input` to the algorithm it is publishing for.
110
+ */
111
+ export interface RunControls {
90
112
  /** Aborted when the run is cancelled. Throw from it; never swallow it. */
91
113
  readonly signal: AbortSignal;
92
114
  /**
@@ -144,5 +166,5 @@ export declare function detachedRunContext(): AlgorithmRunContext;
144
166
  * @param step - What to do with one element.
145
167
  * @returns A promise that settles when every element has been walked.
146
168
  */
147
- export declare function forEachChunked<T>(context: AlgorithmRunContext, phase: string, items: readonly T[], step: (item: T, index: number) => void): Promise<void>;
169
+ export declare function forEachChunked<T>(context: RunControls, phase: string, items: readonly T[], step: (item: T, index: number) => void): Promise<void>;
148
170
  export {};
@@ -1,23 +1,6 @@
1
1
  /**
2
2
  * @file Shared utilities for community detection algorithms
3
3
  */
4
- import type { GraphLike } from "./graphUtils";
5
- /**
6
- * Options for community utilities
7
- */
8
- interface CommunityOptions {
9
- /** Weight attribute name on edges (default: "value") */
10
- weightAttribute?: string;
11
- }
12
- /**
13
- * Options for degree calculation
14
- */
15
- interface DegreeOptions {
16
- /** Whether to treat the graph as directed (default: false for undirected) */
17
- directed?: boolean;
18
- /** For directed graphs, count "in", "out", or "both" edges (default: "both") */
19
- countType?: "in" | "out" | "both";
20
- }
21
4
  /**
22
5
  * Convert a community assignment map to an array of arrays.
23
6
  *
@@ -33,36 +16,6 @@ interface DegreeOptions {
33
16
  * ```
34
17
  */
35
18
  export declare function extractCommunities(communities: Map<number | string, number>): (number | string)[][];
36
- /**
37
- * Get the total weight of all edges in the graph.
38
- * @param graph - The graphty-element Graph instance
39
- * @param options - Configuration options
40
- * @returns Total edge weight
41
- * @example
42
- * ```typescript
43
- * const totalWeight = getTotalEdgeWeight(graph);
44
- * ```
45
- */
46
- export declare function getTotalEdgeWeight(graph: GraphLike, options?: CommunityOptions): number;
47
- /**
48
- * Get the degree of a specific node.
49
- *
50
- * In undirected mode (default), counts all edges incident to the node.
51
- * In directed mode, can count incoming, outgoing, or both edges.
52
- * @param graph - The graphty-element Graph instance
53
- * @param nodeId - The ID of the node
54
- * @param options - Configuration options
55
- * @returns The degree of the node
56
- * @example
57
- * ```typescript
58
- * // Undirected degree
59
- * const degree = getNodeDegree(graph, "A");
60
- *
61
- * // Directed out-degree
62
- * const outDegree = getNodeDegree(graph, "A", { directed: true, countType: "out" });
63
- * ```
64
- */
65
- export declare function getNodeDegree(graph: GraphLike, nodeId: number | string, options?: DegreeOptions): number;
66
19
  /**
67
20
  * Count the number of unique communities in a community assignment map.
68
21
  * @param communities - Map of node ID to community ID
@@ -75,4 +28,3 @@ export declare function getNodeDegree(graph: GraphLike, nodeId: number | string,
75
28
  * ```
76
29
  */
77
30
  export declare function countUniqueCommunities(communities: Map<number | string, number>): number;
78
- export {};