@graphty/graph-format 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +216 -43
  3. package/dist/graph-format.d.ts +1 -0
  4. package/dist/graph-format.d.ts.map +1 -0
  5. package/dist/graph-format.js +15798 -0
  6. package/dist/graph-format.js.map +1 -0
  7. package/dist/src/builder/arena.d.ts +85 -0
  8. package/dist/src/builder/arena.d.ts.map +1 -0
  9. package/dist/src/builder/arena.js +154 -0
  10. package/dist/src/builder/arena.js.map +1 -0
  11. package/dist/src/builder/compact.d.ts +515 -0
  12. package/dist/src/builder/compact.d.ts.map +1 -0
  13. package/dist/src/builder/compact.js +1553 -0
  14. package/dist/src/builder/compact.js.map +1 -0
  15. package/dist/src/builder/counting-sort.d.ts +96 -0
  16. package/dist/src/builder/counting-sort.d.ts.map +1 -0
  17. package/dist/src/builder/counting-sort.js +430 -0
  18. package/dist/src/builder/counting-sort.js.map +1 -0
  19. package/dist/src/builder/freeze.d.ts +72 -0
  20. package/dist/src/builder/freeze.d.ts.map +1 -0
  21. package/dist/src/builder/freeze.js +548 -0
  22. package/dist/src/builder/freeze.js.map +1 -0
  23. package/dist/src/builder/graph-builder.d.ts +602 -0
  24. package/dist/src/builder/graph-builder.d.ts.map +1 -0
  25. package/dist/src/builder/graph-builder.js +1940 -0
  26. package/dist/src/builder/graph-builder.js.map +1 -0
  27. package/dist/src/builder/options.d.ts +16 -0
  28. package/dist/src/builder/options.d.ts.map +1 -0
  29. package/dist/src/builder/options.js +21 -0
  30. package/dist/src/builder/options.js.map +1 -0
  31. package/dist/src/columns/bitmap.d.ts +96 -0
  32. package/dist/src/columns/bitmap.d.ts.map +1 -0
  33. package/dist/src/columns/bitmap.js +184 -0
  34. package/dist/src/columns/bitmap.js.map +1 -0
  35. package/dist/src/columns/column.d.ts +220 -0
  36. package/dist/src/columns/column.d.ts.map +1 -0
  37. package/dist/src/columns/column.js +2109 -0
  38. package/dist/src/columns/column.js.map +1 -0
  39. package/dist/src/columns/dictionary.d.ts +60 -0
  40. package/dist/src/columns/dictionary.d.ts.map +1 -0
  41. package/dist/src/columns/dictionary.js +102 -0
  42. package/dist/src/columns/dictionary.js.map +1 -0
  43. package/dist/src/columns/growable.d.ts +198 -0
  44. package/dist/src/columns/growable.d.ts.map +1 -0
  45. package/dist/src/columns/growable.js +296 -0
  46. package/dist/src/columns/growable.js.map +1 -0
  47. package/dist/src/columns/infer.d.ts +121 -0
  48. package/dist/src/columns/infer.d.ts.map +1 -0
  49. package/dist/src/columns/infer.js +268 -0
  50. package/dist/src/columns/infer.js.map +1 -0
  51. package/dist/src/columns/remap.d.ts +143 -0
  52. package/dist/src/columns/remap.d.ts.map +1 -0
  53. package/dist/src/columns/remap.js +588 -0
  54. package/dist/src/columns/remap.js.map +1 -0
  55. package/dist/src/columns/table.d.ts +184 -0
  56. package/dist/src/columns/table.d.ts.map +1 -0
  57. package/dist/src/columns/table.js +485 -0
  58. package/dist/src/columns/table.js.map +1 -0
  59. package/dist/src/constants.d.ts +34 -0
  60. package/dist/src/constants.d.ts.map +1 -0
  61. package/dist/src/constants.js +79 -0
  62. package/dist/src/constants.js.map +1 -0
  63. package/dist/src/errors.d.ts +76 -0
  64. package/dist/src/errors.d.ts.map +1 -0
  65. package/dist/src/errors.js +32 -0
  66. package/dist/src/errors.js.map +1 -0
  67. package/dist/src/ids/edge-id-index.d.ts +77 -0
  68. package/dist/src/ids/edge-id-index.d.ts.map +1 -0
  69. package/dist/src/ids/edge-id-index.js +155 -0
  70. package/dist/src/ids/edge-id-index.js.map +1 -0
  71. package/dist/src/ids/node-id-map.d.ts +280 -0
  72. package/dist/src/ids/node-id-map.d.ts.map +1 -0
  73. package/dist/src/ids/node-id-map.js +1139 -0
  74. package/dist/src/ids/node-id-map.js.map +1 -0
  75. package/dist/src/ids/string-store.d.ts +219 -0
  76. package/dist/src/ids/string-store.d.ts.map +1 -0
  77. package/dist/src/ids/string-store.js +526 -0
  78. package/dist/src/ids/string-store.js.map +1 -0
  79. package/dist/src/index.d.ts +30 -0
  80. package/dist/src/index.d.ts.map +1 -0
  81. package/dist/src/index.js +29 -0
  82. package/dist/src/index.js.map +1 -0
  83. package/dist/src/populate/from-csr.d.ts +61 -0
  84. package/dist/src/populate/from-csr.d.ts.map +1 -0
  85. package/dist/src/populate/from-csr.js +706 -0
  86. package/dist/src/populate/from-csr.js.map +1 -0
  87. package/dist/src/populate/from-edge-arrays.d.ts +51 -0
  88. package/dist/src/populate/from-edge-arrays.d.ts.map +1 -0
  89. package/dist/src/populate/from-edge-arrays.js +217 -0
  90. package/dist/src/populate/from-edge-arrays.js.map +1 -0
  91. package/dist/src/populate/from-records.d.ts +51 -0
  92. package/dist/src/populate/from-records.d.ts.map +1 -0
  93. package/dist/src/populate/from-records.js +447 -0
  94. package/dist/src/populate/from-records.js.map +1 -0
  95. package/dist/src/snapshot/derived.d.ts +211 -0
  96. package/dist/src/snapshot/derived.d.ts.map +1 -0
  97. package/dist/src/snapshot/derived.js +1254 -0
  98. package/dist/src/snapshot/derived.js.map +1 -0
  99. package/dist/src/snapshot/graph-meta.d.ts +23 -0
  100. package/dist/src/snapshot/graph-meta.d.ts.map +1 -0
  101. package/dist/src/snapshot/graph-meta.js +159 -0
  102. package/dist/src/snapshot/graph-meta.js.map +1 -0
  103. package/dist/src/snapshot/graph-snapshot.d.ts +509 -0
  104. package/dist/src/snapshot/graph-snapshot.d.ts.map +1 -0
  105. package/dist/src/snapshot/graph-snapshot.js +1247 -0
  106. package/dist/src/snapshot/graph-snapshot.js.map +1 -0
  107. package/dist/src/snapshot/hash.d.ts +90 -0
  108. package/dist/src/snapshot/hash.d.ts.map +1 -0
  109. package/dist/src/snapshot/hash.js +228 -0
  110. package/dist/src/snapshot/hash.js.map +1 -0
  111. package/dist/src/snapshot/queries.d.ts +74 -0
  112. package/dist/src/snapshot/queries.d.ts.map +1 -0
  113. package/dist/src/snapshot/queries.js +131 -0
  114. package/dist/src/snapshot/queries.js.map +1 -0
  115. package/dist/src/snapshot/validate.d.ts +192 -0
  116. package/dist/src/snapshot/validate.d.ts.map +1 -0
  117. package/dist/src/snapshot/validate.js +990 -0
  118. package/dist/src/snapshot/validate.js.map +1 -0
  119. package/dist/src/snapshot/views.d.ts +274 -0
  120. package/dist/src/snapshot/views.d.ts.map +1 -0
  121. package/dist/src/snapshot/views.js +856 -0
  122. package/dist/src/snapshot/views.js.map +1 -0
  123. package/dist/src/types/builder.d.ts +456 -0
  124. package/dist/src/types/builder.d.ts.map +1 -0
  125. package/dist/src/types/builder.js +11 -0
  126. package/dist/src/types/builder.js.map +1 -0
  127. package/dist/src/types/columns.d.ts +615 -0
  128. package/dist/src/types/columns.d.ts.map +1 -0
  129. package/dist/src/types/columns.js +14 -0
  130. package/dist/src/types/columns.js.map +1 -0
  131. package/dist/src/types/index.d.ts +14 -0
  132. package/dist/src/types/index.d.ts.map +1 -0
  133. package/dist/src/types/index.js +11 -0
  134. package/dist/src/types/index.js.map +1 -0
  135. package/dist/src/types/internal.d.ts +172 -0
  136. package/dist/src/types/internal.d.ts.map +1 -0
  137. package/dist/src/types/internal.js +13 -0
  138. package/dist/src/types/internal.js.map +1 -0
  139. package/dist/src/types/snapshot.d.ts +801 -0
  140. package/dist/src/types/snapshot.d.ts.map +1 -0
  141. package/dist/src/types/snapshot.js +14 -0
  142. package/dist/src/types/snapshot.js.map +1 -0
  143. package/dist/src/types/wire.d.ts +196 -0
  144. package/dist/src/types/wire.d.ts.map +1 -0
  145. package/dist/src/types/wire.js +8 -0
  146. package/dist/src/types/wire.js.map +1 -0
  147. package/dist/src/util/mask.d.ts +55 -0
  148. package/dist/src/util/mask.d.ts.map +1 -0
  149. package/dist/src/util/mask.js +71 -0
  150. package/dist/src/util/mask.js.map +1 -0
  151. package/dist/src/util/options.d.ts +22 -0
  152. package/dist/src/util/options.d.ts.map +1 -0
  153. package/dist/src/util/options.js +49 -0
  154. package/dist/src/util/options.js.map +1 -0
  155. package/dist/src/util/shared-buffers.d.ts +42 -0
  156. package/dist/src/util/shared-buffers.d.ts.map +1 -0
  157. package/dist/src/util/shared-buffers.js +52 -0
  158. package/dist/src/util/shared-buffers.js.map +1 -0
  159. package/dist/src/util/typed-array.d.ts +205 -0
  160. package/dist/src/util/typed-array.d.ts.map +1 -0
  161. package/dist/src/util/typed-array.js +289 -0
  162. package/dist/src/util/typed-array.js.map +1 -0
  163. package/dist/src/wire/bytes.d.ts +69 -0
  164. package/dist/src/wire/bytes.d.ts.map +1 -0
  165. package/dist/src/wire/bytes.js +361 -0
  166. package/dist/src/wire/bytes.js.map +1 -0
  167. package/dist/src/wire/carried-views.d.ts +111 -0
  168. package/dist/src/wire/carried-views.d.ts.map +1 -0
  169. package/dist/src/wire/carried-views.js +286 -0
  170. package/dist/src/wire/carried-views.js.map +1 -0
  171. package/dist/src/wire/from-wire.d.ts +144 -0
  172. package/dist/src/wire/from-wire.d.ts.map +1 -0
  173. package/dist/src/wire/from-wire.js +1425 -0
  174. package/dist/src/wire/from-wire.js.map +1 -0
  175. package/dist/src/wire/to-wire.d.ts +171 -0
  176. package/dist/src/wire/to-wire.d.ts.map +1 -0
  177. package/dist/src/wire/to-wire.js +652 -0
  178. package/dist/src/wire/to-wire.js.map +1 -0
  179. package/dist/tsconfig.build.tsbuildinfo +1 -0
  180. package/package.json +72 -7
  181. package/src/builder/arena.ts +192 -0
  182. package/src/builder/compact.ts +1811 -0
  183. package/src/builder/counting-sort.ts +506 -0
  184. package/src/builder/freeze.ts +689 -0
  185. package/src/builder/graph-builder.ts +2264 -0
  186. package/src/builder/options.ts +29 -0
  187. package/src/columns/bitmap.ts +196 -0
  188. package/src/columns/column.ts +2574 -0
  189. package/src/columns/dictionary.ts +114 -0
  190. package/src/columns/growable.ts +350 -0
  191. package/src/columns/infer.ts +285 -0
  192. package/src/columns/remap.ts +663 -0
  193. package/src/columns/table.ts +568 -0
  194. package/src/constants.ts +89 -0
  195. package/src/errors.ts +115 -0
  196. package/src/ids/edge-id-index.ts +179 -0
  197. package/src/ids/node-id-map.ts +1340 -0
  198. package/src/ids/string-store.ts +589 -0
  199. package/src/index.ts +139 -0
  200. package/src/lib-resizable-array-buffer.d.ts +34 -0
  201. package/src/populate/from-csr.ts +802 -0
  202. package/src/populate/from-edge-arrays.ts +257 -0
  203. package/src/populate/from-records.ts +536 -0
  204. package/src/snapshot/derived.ts +1486 -0
  205. package/src/snapshot/graph-meta.ts +167 -0
  206. package/src/snapshot/graph-snapshot.ts +1503 -0
  207. package/src/snapshot/hash.ts +241 -0
  208. package/src/snapshot/queries.ts +136 -0
  209. package/src/snapshot/validate.ts +1108 -0
  210. package/src/snapshot/views.ts +943 -0
  211. package/src/types/builder.ts +480 -0
  212. package/src/types/columns.ts +727 -0
  213. package/src/types/index.ts +14 -0
  214. package/src/types/internal.ts +195 -0
  215. package/src/types/snapshot.ts +886 -0
  216. package/src/types/wire.ts +207 -0
  217. package/src/util/mask.ts +89 -0
  218. package/src/util/options.ts +57 -0
  219. package/src/util/shared-buffers.ts +56 -0
  220. package/src/util/typed-array.ts +371 -0
  221. package/src/wire/bytes.ts +440 -0
  222. package/src/wire/carried-views.ts +327 -0
  223. package/src/wire/from-wire.ts +1690 -0
  224. package/src/wire/to-wire.ts +755 -0
@@ -0,0 +1,801 @@
1
+ /**
2
+ * The frozen snapshot and its side structures (design sections 3, 4, 7, 8.1, 9, 10 and 12.2): the id
3
+ * map, the flags, the arena layout, the views, the derived graphs, the GraphSnapshot contract itself
4
+ * and the inputs of the snapshot factories.
5
+ *
6
+ * GraphSnapshotContract and NodeIdMapContract are the instance contracts of the GraphSnapshot and
7
+ * NodeIdMap classes implemented in src/snapshot/graph-snapshot.ts and src/ids/node-id-map.ts (design
8
+ * section 12.1 makes them classes so the JSDoc-on-method lint applies). The public names
9
+ * GraphSnapshot and NodeIdMap are the classes themselves, re-exported type-only from here so every
10
+ * type on this surface (DerivedGraph.snapshot, SnapshotParts.ids, ...) names the class the barrel
11
+ * exports. The imports are type-only, so the import graph stays free of runtime cycles.
12
+ */
13
+ import { type SNAPSHOT_BRAND } from "../constants.js";
14
+ import { type NodeIdMap } from "../ids/node-id-map.js";
15
+ import { type GraphSnapshot } from "../snapshot/graph-snapshot.js";
16
+ import { type AttributeTable, type ColumnDecl, type ColumnInput, type ColumnReducer, type EdgeId, type EdgeMask, type F32, type F64, type GraphMeta, type GraphMetaPatch, type IdCoercion, type Loose, type NodeId, type NodeMask, type TypedArrayData, type U8, type U32, type ValidationLevel, type WeightReducer } from "./columns.js";
17
+ import { type ToBytesOptions, type ToWireOptions, type WireSnapshot } from "./wire.js";
18
+ export type { GraphSnapshot, NodeIdMap };
19
+ /**
20
+ * Storage kind of a NodeIdMap, chosen at freeze by inspecting the ids once (design section 4.2):
21
+ * "identity" (id === index + offset, zero bytes), "dense" (distinct integers with maxId + 1 <= 2n),
22
+ * "numeric" (any numbers), "string" (all strings) or "mixed".
23
+ */
24
+ export type NodeIdMapKind = "identity" | "dense" | "numeric" | "string" | "mixed";
25
+ /**
26
+ * Bijection between node ids and node indices for one snapshot, kept outside the CSR (invariant
27
+ * I11: ids.indexOf(ids.idOf(i)) === i for every i, size === nodeCount, SameValueZero equality, no
28
+ * NaN). Immutable. Lookups by id return INVALID_INDEX on a miss rather than -1 or undefined so the
29
+ * sentinel is the same one used in every u32 result vector (decision C9).
30
+ *
31
+ * Instance contract of the NodeIdMap class in src/ids/node-id-map.ts, which implements it; the
32
+ * public barrel exports the class and every public type names the class.
33
+ */
34
+ export interface NodeIdMapContract extends Iterable<NodeId> {
35
+ /** The storage kind (design section 4.2). */
36
+ readonly kind: NodeIdMapKind;
37
+ /** Number of ids; equals nodeCount. */
38
+ readonly size: number;
39
+ /** identity only: id === index + offset (0 or 1 in practice); 0 for every other kind. */
40
+ readonly offset: number;
41
+ /**
42
+ * The id of a node index.
43
+ * @param index - the node index
44
+ * @returns the id; E_INDEX_RANGE when index >= size
45
+ */
46
+ idOf(index: number): NodeId;
47
+ /**
48
+ * Total lookup by id.
49
+ * @param id - the node id
50
+ * @returns the node index, or INVALID_INDEX when absent
51
+ */
52
+ indexOf(id: NodeId): number;
53
+ /**
54
+ * Whether an id is present.
55
+ * @param id - the node id
56
+ * @returns true when present
57
+ */
58
+ has(id: NodeId): boolean;
59
+ /**
60
+ * Checked lookup by id, for algorithms that today throw "node not found".
61
+ * @param id - the node id
62
+ * @returns the node index; E_UNKNOWN_NODE when absent
63
+ */
64
+ requireIndex(id: NodeId): number;
65
+ /**
66
+ * Bulk lookup.
67
+ * @param ids - the ids to resolve
68
+ * @param onMissing - "invalid" (default) writes INVALID_INDEX for a miss; "throw" raises E_UNKNOWN_NODE
69
+ * @returns a fresh U32 of indices in input order
70
+ */
71
+ indicesOf(ids: Iterable<NodeId>, onMissing?: "invalid" | "throw"): U32;
72
+ /**
73
+ * Bulk decode of a range of ids in one pass.
74
+ * @param start - first index (default 0)
75
+ * @param end - one past the last index (default size)
76
+ * @returns the ids in index order
77
+ */
78
+ idsSlice(start?: number, end?: number): NodeId[];
79
+ /**
80
+ * Every id in index order.
81
+ * @returns a fresh array
82
+ */
83
+ toArray(): NodeId[];
84
+ /**
85
+ * Iterate the ids in index order.
86
+ * @returns an iterator over the ids
87
+ */
88
+ [Symbol.iterator](): IterableIterator<NodeId>;
89
+ /**
90
+ * Key an index-aligned result vector by id (boundary helper, decision C11).
91
+ * @param values - one value per node index
92
+ * @returns a Map from id to value
93
+ */
94
+ toMap<T>(values: ArrayLike<T>): Map<NodeId, T>;
95
+ /**
96
+ * Key an index-aligned result vector by String(id), for legacy Map<string, T> result shapes.
97
+ * @param values - one value per node index
98
+ * @returns a Map from String(id) to value
99
+ */
100
+ toStringMap<T>(values: ArrayLike<T>): Map<string, T>;
101
+ /**
102
+ * Key an index-aligned result vector by String(id), for legacy record result shapes only.
103
+ * @param values - one value per node index
104
+ * @returns a record from String(id) to value
105
+ */
106
+ toRecord<T>(values: ArrayLike<T>): Record<string, T>;
107
+ /**
108
+ * Iterate [id, value] pairs of an index-aligned result vector.
109
+ * @param values - one value per node index
110
+ * @returns an iterator over the pairs in index order
111
+ */
112
+ entries<T>(values: ArrayLike<T>): IterableIterator<[NodeId, T]>;
113
+ /**
114
+ * String(idOf(i)) -> i, built lazily once, for legacy string-typed id parameters.
115
+ * @returns the read-only string index
116
+ */
117
+ stringIndex(): ReadonlyMap<string, number>;
118
+ /**
119
+ * Bytes of typed storage; excludes the reverse Map and JS strings.
120
+ * @returns the byte count
121
+ */
122
+ byteLength(): number;
123
+ }
124
+ /**
125
+ * Flags kernels branch on (design section 3.8). Each is defined by a predicate over the arrays,
126
+ * computed at freeze or by validation, never guessed; there is no flag whose value may be "unknown"
127
+ * (invariant I9). The three weight flags describe the f32 ARC ARRAY (`weights`): when an f64
128
+ * role-"weight" shadow column is kept (design section 3.7) its exact values can differ from the
129
+ * rounded arc values (1 + 2^-30 rounds to 1), so a consumer that substitutes the shadow for the arc
130
+ * weights must not branch on these flags.
131
+ */
132
+ export interface SnapshotFlags {
133
+ /** Some row contains two arcs with equal colIdx (parallel edges). */
134
+ readonly multigraph: boolean;
135
+ /** selfLoopCount > 0. */
136
+ readonly hasSelfLoops: boolean;
137
+ /**
138
+ * directed && arcToEdge[a] === a for all a (and edgeToArc is the identity). Always false when !directed, even when
139
+ * arcCount === edgeCount.
140
+ */
141
+ readonly arcToEdgeIsIdentity: boolean;
142
+ /** weights !== null. */
143
+ readonly weighted: boolean;
144
+ /** weights === null, or every value === 1. Lets SSSP degrade to BFS. */
145
+ readonly allWeightsOne: boolean;
146
+ /** weights === null, or every value >= 0. Dijkstra / delta-stepping legal. */
147
+ readonly nonNegativeWeights: boolean;
148
+ /** weights === null, or every value is finite. */
149
+ readonly finiteWeights: boolean;
150
+ }
151
+ /** Flag claims a caller passes to fromCsr(); verified unless validate is "none" (design section 8.1). */
152
+ export type FlagClaims = Loose<SnapshotFlags>;
153
+ /** The five core arrays, in the hot-to-cold order they occupy the arena (design section 10.3). */
154
+ export type CoreArrayName = "rowPtr" | "colIdx" | "weights" | "arcToEdge" | "edgeToArc";
155
+ /** One core array's location inside the arena buffer, in absolute bytes (design section 10.3). */
156
+ export interface ArenaSegment {
157
+ /** Absolute byte offset in ArenaLayout.buffer; a multiple of 256 relative to ArenaLayout.byteOffset. */
158
+ readonly byteOffset: number;
159
+ /** Byte length of the array (unpadded). */
160
+ readonly byteLength: number;
161
+ }
162
+ /**
163
+ * One ArrayBuffer holding the core arrays at 256-byte-aligned offsets, hot to cold: rowPtr, colIdx,
164
+ * weights, arcToEdge, edgeToArc (design section 10.3, invariant I10). A GPU package uploads the first
165
+ * hotByteLength bytes in one writeBuffer call and binds each segment as a storage-buffer window. A
166
+ * zero-length array, an absent weights array and an identity permutation have a null segment and
167
+ * are never in the arena.
168
+ */
169
+ export interface ArenaLayout {
170
+ /** The backing buffer. */
171
+ readonly buffer: ArrayBuffer;
172
+ /** Start of the arena inside buffer: 0 for builder output; bytes.byteOffset + B for a container. */
173
+ readonly byteOffset: number;
174
+ /** Total padded length of the arena. */
175
+ readonly byteLength: number;
176
+ /** Segment alignment in bytes. */
177
+ readonly alignment: 256;
178
+ /** Absolute offsets in buffer per core array; null = absent, zero-length, or identity (never in the arena). */
179
+ readonly segments: Readonly<Record<CoreArrayName, ArenaSegment | null>>;
180
+ /**
181
+ * End of the weights segment (or colIdx when unweighted) relative to byteOffset: the prefix a traversal kernel
182
+ * needs.
183
+ */
184
+ readonly hotByteLength: number;
185
+ }
186
+ /**
187
+ * Names of the lazily computed, cached views (design section 7.2), as accepted by prepare(),
188
+ * cachedViews() and the wire includeViews option. "degreeOrder" and "reverseDegreeOrder" are the two
189
+ * cached results of degreeOrder({ of }); "symmetric" is the result of isSymmetric(). The scalar
190
+ * views "totalWeight" and "symmetric" are ignored by includeViews and always recomputed.
191
+ */
192
+ export type ViewName = "reverse" | "coo" | "edgeList" | "outDegree" | "inDegree" | "degree" | "weightedOutDegree" | "weightedInDegree" | "weightedDegree" | "selfLoopWeight" | "totalWeight" | "selfLoopArcs" | "selfLoopsPerNode" | "mate" | "degreeOrder" | "reverseDegreeOrder" | "symmetric";
193
+ /** Options of degreeOrder(): which adjacency's out-degree orders the nodes (design section 7.2). */
194
+ export interface DegreeOrderOptions {
195
+ /** "forward" (default) orders by rowPtr; "reverse" by reverse().rowPtr, i.e. the in-degree, for pull kernels. */
196
+ readonly of?: "forward" | "reverse" | undefined;
197
+ }
198
+ /**
199
+ * The structural row-walking interface implemented by GraphSnapshot and by ReverseView (design
200
+ * section 7.2), so an algorithm that only walks rows takes either without a wrapper: an
201
+ * in-neighbour BFS is the out-neighbour BFS over reverse(). Rows are sorted by target with ties in
202
+ * ascending arcToEdge order (invariant I4); no INVALID_INDEX appears in any array (I2).
203
+ */
204
+ export interface AdjacencyView {
205
+ /** Whether the graph is directed (design section 3.6). */
206
+ readonly directed: boolean;
207
+ /** Number of nodes n. */
208
+ readonly nodeCount: number;
209
+ /** Number of arcs: colIdx.length === rowPtr[nodeCount] (invariant I1). */
210
+ readonly arcCount: number;
211
+ /** nodeCount + 1 row offsets; rowPtr[0] === 0, non-decreasing (invariant I1). */
212
+ readonly rowPtr: U32;
213
+ /** Target node index of every arc, sorted within each row (invariants I2, I4); length 0 when arcCount === 0. */
214
+ readonly colIdx: U32;
215
+ /** Logical edge of every arc (invariant I5). */
216
+ readonly arcToEdge: U32;
217
+ /** Per-arc f32 weights, or null when every weight is 1 (design section 3.7, invariant I8). */
218
+ readonly weights: F32 | null;
219
+ }
220
+ /**
221
+ * The in-adjacency of a snapshot (design section 7.2): rows sorted by source, weights gathered when
222
+ * weighted. For an undirected snapshot the forward arrays themselves are returned (invariant I7)
223
+ * with an identity fwdArc, and arcToEdge is the very same array as the snapshot's.
224
+ */
225
+ export interface ReverseView extends AdjacencyView {
226
+ /** Reverse arc k -> forward arc index; the identity for undirected snapshots (materialised lazily). */
227
+ readonly fwdArc: U32;
228
+ }
229
+ /** Per-arc COO form: src is the only new array; dst aliases colIdx (design section 7.2). */
230
+ export interface CooView {
231
+ /** Source node index of every arc (the row containing it). */
232
+ readonly src: U32;
233
+ /** Target node index of every arc; aliases colIdx. */
234
+ readonly dst: U32;
235
+ /** Logical edge of every arc; aliases the snapshot's arcToEdge. */
236
+ readonly arcToEdge: U32;
237
+ /** Per-arc weights; aliases the snapshot's weights. */
238
+ readonly weights: F32 | null;
239
+ }
240
+ /**
241
+ * Every logical edge once, in declared orientation (design section 7.2): the binding an
242
+ * each-edge-once edge-parallel kernel uses on directed and undirected snapshots alike.
243
+ */
244
+ export interface EdgeListView {
245
+ /** Declared source of every logical edge. */
246
+ readonly src: U32;
247
+ /** Declared target of every logical edge. */
248
+ readonly dst: U32;
249
+ /** The arc holding the declared orientation; aliases edgeToArc. */
250
+ readonly arc: U32;
251
+ /**
252
+ * Per-edge weights gathered through edgeToArc (aliased when the permutation is the identity); null when unweighted.
253
+ */
254
+ readonly weights: F32 | null;
255
+ }
256
+ /**
257
+ * Nodes permuted by descending out-degree of the chosen adjacency with cuGraph's tier thresholds
258
+ * 1024 / 32 / 1 (design section 7.2): perm is the GPU load-balancing binding, segmentOffsets =
259
+ * [0, hiEnd, midEnd, lowEnd, n] is read on the CPU to size the three dispatches.
260
+ */
261
+ export interface DegreeOrderView {
262
+ /** Node indices in descending degree order; length n. */
263
+ readonly perm: U32;
264
+ /** The five tier boundaries [0, hiEnd, midEnd, lowEnd, n]. */
265
+ readonly segmentOffsets: U32;
266
+ }
267
+ /**
268
+ * A new snapshot produced from an existing one by a structural mapping the caller specifies, plus
269
+ * index maps back to the source (design section 7.3). Never cached by the format. Every map is null
270
+ * when the corresponding index space is unchanged; edgeRemap maps every merged edge to its survivor
271
+ * so a per-edge result of the derived graph writes back onto source edges with
272
+ * `out[e] = vec[edgeRemap[e]]`, and edgeRemap[edgeOrigin[d]] === d for every derived edge d.
273
+ */
274
+ export interface DerivedGraph {
275
+ /** The derived snapshot; `this` for the identity cases (transpose / toUndirected of an undirected snapshot). */
276
+ readonly snapshot: GraphSnapshot;
277
+ /**
278
+ * New node index -> source node index (contract: the LOWEST source index of the block); null when the node space is
279
+ * unchanged.
280
+ */
281
+ readonly nodeOrigin: U32 | null;
282
+ /**
283
+ * New edge index -> source edge index (a merged edge: its SURVIVOR's source index, never INVALID_INDEX); null when
284
+ * unchanged.
285
+ */
286
+ readonly edgeOrigin: U32 | null;
287
+ /** Source node index -> new index (contract: the block) or INVALID_INDEX (dropped); null when unchanged. */
288
+ readonly nodeRemap: U32 | null;
289
+ /**
290
+ * Source edge index -> new index; a merged / collapsed edge maps to its SURVIVOR, a dropped edge to INVALID_INDEX;
291
+ * null when unchanged.
292
+ */
293
+ readonly edgeRemap: U32 | null;
294
+ /** contract only: source nodes per new node; null otherwise. */
295
+ readonly blockSizes: U32 | null;
296
+ /** How many source edges were dropped and how many merged. */
297
+ readonly report: {
298
+ readonly droppedEdges: number;
299
+ readonly mergedEdges: number;
300
+ };
301
+ }
302
+ /** Options of toUndirected() (design section 7.3). */
303
+ export interface ToUndirectedOptions {
304
+ /** Keep only pairs present in both directions (cuGraph symmetrize(reciprocal)). */
305
+ readonly reciprocal?: boolean | undefined;
306
+ /** How the weights of a collapsed reciprocal pair combine; default "first" (the lower index's weight). */
307
+ readonly weights?: WeightReducer | undefined;
308
+ }
309
+ /** Options of simplified() (design section 7.3): one edge per (u, v) group, survivor = lowest index. */
310
+ export interface SimplifyOptions {
311
+ /** How the weights of a parallel group combine; default "first". */
312
+ readonly weights?: WeightReducer | undefined;
313
+ /** Whether self-loops survive; default "keep". */
314
+ readonly selfLoops?: "keep" | "drop" | undefined;
315
+ /** Per-column reducers for the other edge columns; default: the survivor's row. */
316
+ readonly edgeReducers?: Readonly<Record<string, ColumnReducer>> | undefined;
317
+ }
318
+ /**
319
+ * Options of contract(partition) (design section 7.3): the Leiden / Louvain aggregation and
320
+ * condensationGraph primitive. Semantics are at the logical-edge level: an intra-block edge becomes
321
+ * one self-loop with weight w, an inter-block edge one edge between the blocks.
322
+ */
323
+ export interface ContractOptions {
324
+ /** How merged edge weights combine; default "sum" (on an unweighted source "sum" yields multiplicities). */
325
+ readonly weights?: WeightReducer | undefined;
326
+ /** Whether intra-block edges become self-loops; default "keep". */
327
+ readonly selfLoops?: "keep" | "drop" | undefined;
328
+ /** Whether parallel inter-block edges merge; default "merge". */
329
+ readonly parallel?: "merge" | "keep" | undefined;
330
+ /** Node columns to keep and how to reduce them; default: drop node columns. */
331
+ readonly nodeReducers?: Readonly<Record<string, ColumnReducer>> | undefined;
332
+ /** Edge columns to keep and how to reduce them; default: drop edge columns. */
333
+ readonly edgeReducers?: Readonly<Record<string, ColumnReducer>> | undefined;
334
+ }
335
+ /** Options of validate() (design section 11.4). */
336
+ export interface ValidateOptions {
337
+ /** "structure" or "full" per the level table of design section 9.5; default "full". */
338
+ readonly level?: "structure" | "full" | undefined;
339
+ /**
340
+ * Compare the FNV-1a checksums recorded by freeze({ checksum: true }); E_INVALID_SNAPSHOT (details.reason
341
+ * "no-checksum") when none were recorded.
342
+ */
343
+ readonly checksum?: boolean | undefined;
344
+ }
345
+ /** Options of byteLength(): which side structures to include beyond the core (design section 7.2). */
346
+ export interface ByteLengthOptions {
347
+ /** Include cached views. */
348
+ readonly views?: boolean | undefined;
349
+ /** Include attribute columns. */
350
+ readonly columns?: boolean | undefined;
351
+ /** Include the id map's typed storage. */
352
+ readonly ids?: boolean | undefined;
353
+ }
354
+ /**
355
+ * The frozen graph (design section 3): a CSR core over 4-byte typed arrays, the id map, the
356
+ * attribute tables, the flags and a per-instance view cache. Topology, counts, flags, id map and
357
+ * immutable columns never change after freeze() returns (invariant I17); the column SET of nodes /
358
+ * edges / graph and the CONTENTS of columns declared mutable are mutable side tables (design section
359
+ * 5.8). Every view is a pure function of the core, memoised once and SHARED: writing into a view is
360
+ * a contract violation; call .slice() for scratch. Index-taking queries are total for in-range
361
+ * arguments and unchecked otherwise (design section 11.1); every core accessor throws E_DETACHED
362
+ * after a consuming transfer.
363
+ *
364
+ * Instance contract of the GraphSnapshot class in src/snapshot/graph-snapshot.ts, which implements
365
+ * it; the public barrel exports the class and every public type names the class. isGraphSnapshot()
366
+ * recognises instances structurally through SNAPSHOT_BRAND and formatVersion, never instanceof.
367
+ */
368
+ export interface GraphSnapshotContract extends AdjacencyView {
369
+ /** Symbol.for brand read by isGraphSnapshot() (design section 7.5). */
370
+ readonly [SNAPSHOT_BRAND]: true;
371
+ /** Process-unique identity of the CORE; shared by withColumns() snapshots (design section 5.8). */
372
+ readonly serial: number;
373
+ /** Debugging aid supplied at freeze. */
374
+ readonly label: string | null;
375
+ /** The data-model major (design section 13.5). */
376
+ readonly formatVersion: 1;
377
+ /** Whether the graph is directed; no tri-state (decision C3). */
378
+ readonly directed: boolean;
379
+ /** n, <= MAX_COUNT (invariant I3). */
380
+ readonly nodeCount: number;
381
+ /** Number of logical edges; every edge column has edgeCount rows (invariant I13). */
382
+ readonly edgeCount: number;
383
+ /** colIdx.length: edgeCount when directed, 2 * edgeCount - selfLoopCount when undirected (invariants I6, I7). */
384
+ readonly arcCount: number;
385
+ /** Logical edges with source === target. */
386
+ readonly selfLoopCount: number;
387
+ /** nodeCount + 1 row offsets (invariant I1). */
388
+ readonly rowPtr: U32;
389
+ /** Target node index of each arc, sorted within each row (invariants I2, I4); length 0 when arcCount === 0. */
390
+ readonly colIdx: U32;
391
+ /**
392
+ * arcCount f32 weights; null when unweighted (every weight is 1). Both arcs of an undirected edge carry the same
393
+ * value (I7).
394
+ */
395
+ readonly weights: F32 | null;
396
+ /**
397
+ * arcCount entries: logical edge of each arc (invariant I5); materialised on first access when
398
+ * flags.arcToEdgeIsIdentity.
399
+ */
400
+ readonly arcToEdge: U32;
401
+ /**
402
+ * edgeCount entries: the arc holding the declared orientation (invariant I5); materialised on first access when
403
+ * identity.
404
+ */
405
+ readonly edgeToArc: U32;
406
+ /** Flags kernels branch on (design section 3.8, invariant I9). */
407
+ readonly flags: SnapshotFlags;
408
+ /** The id map (design section 4, invariant I11). */
409
+ readonly ids: NodeIdMap;
410
+ /** Node attribute table, rowCount === nodeCount (invariant I12). */
411
+ readonly nodes: AttributeTable;
412
+ /** Edge attribute table, rowCount === edgeCount, indexed by logical edge (invariants I12, I13). */
413
+ readonly edges: AttributeTable;
414
+ /** Graph attribute table, rowCount === 1 (design section 5.9). */
415
+ readonly graph: AttributeTable;
416
+ /** Extension tables such as GEXF temporal tables, keyed by name (design section 5.10). */
417
+ readonly extensions: ReadonlyMap<string, AttributeTable>;
418
+ /** Graph-level metadata (design section 5.9). */
419
+ readonly meta: GraphMeta;
420
+ /**
421
+ * The arena holding the core arrays (design section 10.3); null when the arrays were adopted from separate buffers.
422
+ */
423
+ readonly arena: ArenaLayout | null;
424
+ /** rowPtr.length === 0: the core was transferred away (design section 9.4); derived, never a stored bit. */
425
+ readonly detached: boolean;
426
+ /**
427
+ * The out-arc range of a node: [rowPtr[u], rowPtr[u + 1]]. Allocates a tuple; hot loops read
428
+ * rowPtr directly.
429
+ * @param u - the node index
430
+ * @returns the half-open arc range as [start, end]
431
+ */
432
+ outArcs(u: number): readonly [start: number, end: number];
433
+ /**
434
+ * rowPtr[u + 1] - rowPtr[u]: the out-arc count (a self-loop counted once, design section 3.4).
435
+ * @param u - the node index
436
+ * @returns the out-degree
437
+ */
438
+ outDegreeOf(u: number): number;
439
+ /**
440
+ * Binary search for the first arc u -> v (the lowest logical edge index among parallels).
441
+ * @param u - the source node index
442
+ * @param v - the target node index
443
+ * @returns the arc index, or INVALID_INDEX when absent
444
+ */
445
+ findArc(u: number, v: number): number;
446
+ /**
447
+ * Whether an arc u -> v exists.
448
+ * @param u - the source node index
449
+ * @param v - the target node index
450
+ * @returns findArc(u, v) !== INVALID_INDEX
451
+ */
452
+ hasArc(u: number, v: number): boolean;
453
+ /**
454
+ * The half-open arc range [lo, hi) of every arc u -> v; empty when lo === hi. Allocates a tuple.
455
+ * @param u - the source node index
456
+ * @param v - the target node index
457
+ * @returns the range as [lo, hi]
458
+ */
459
+ arcsBetween(u: number, v: number): readonly [lo: number, hi: number];
460
+ /**
461
+ * Number of parallel arcs u -> v.
462
+ * @param u - the source node index
463
+ * @param v - the target node index
464
+ * @returns hi - lo of arcsBetween(u, v)
465
+ */
466
+ multiplicity(u: number, v: number): number;
467
+ /**
468
+ * The row containing an arc: O(1) after coo(), else a binary search on rowPtr.
469
+ * @param a - the arc index
470
+ * @returns the source node index
471
+ */
472
+ arcSource(a: number): number;
473
+ /**
474
+ * Declared source of a logical edge: arcSource(edgeToArc[e]).
475
+ * @param e - the logical edge index
476
+ * @returns the source node index
477
+ */
478
+ edgeSource(e: number): number;
479
+ /**
480
+ * Declared target of a logical edge: colIdx[edgeToArc[e]].
481
+ * @param e - the logical edge index
482
+ * @returns the target node index
483
+ */
484
+ edgeTarget(e: number): number;
485
+ /**
486
+ * Lookup through the role "id" edge column, backed by a Map built on first call (design section 4.6).
487
+ * @param id - the edge id
488
+ * @returns the logical edge index, or INVALID_INDEX on a miss or when no id column exists
489
+ */
490
+ edgeIndexOf(id: EdgeId): number;
491
+ /**
492
+ * The in-adjacency, rows sorted by source; the forward arrays themselves when undirected. Cached.
493
+ * @returns the reverse view
494
+ */
495
+ reverse(): ReverseView;
496
+ /**
497
+ * Per-arc COO form; src is the only new array. Cached.
498
+ * @returns the COO view
499
+ */
500
+ coo(): CooView;
501
+ /**
502
+ * Every logical edge once in declared orientation. Cached.
503
+ * @returns the edge list view
504
+ */
505
+ edgeList(): EdgeListView;
506
+ /**
507
+ * rowPtr differences materialised; a self-loop counted once. Cached and shared.
508
+ * @returns Uint32Array(n)
509
+ */
510
+ outDegree(): U32;
511
+ /**
512
+ * Arcs targeting each node, via reverse().rowPtr; the same object as outDegree() when undirected. Cached and
513
+ * shared.
514
+ * @returns Uint32Array(n)
515
+ */
516
+ inDegree(): U32;
517
+ /**
518
+ * Graph-theoretic degree (NetworkX convention, design section 3.4): in + out when directed; out plus self-loops
519
+ * when undirected. Cached and shared.
520
+ * @returns Uint32Array(n)
521
+ */
522
+ degree(): U32;
523
+ /**
524
+ * Row sums of weights (a self-loop arc counted once); outDegree widened when unweighted. F64 for CPU precision; may
525
+ * be 0 for a node with out-arcs. Cached and shared.
526
+ * @returns Float64Array(n)
527
+ */
528
+ weightedOutDegree(): F64;
529
+ /**
530
+ * Weight sums over incoming arcs; the same object as weightedOutDegree() when undirected. Cached and shared.
531
+ * @returns Float64Array(n)
532
+ */
533
+ weightedInDegree(): F64;
534
+ /**
535
+ * NetworkX weighted degree: weightedOutDegree + (directed ? weightedInDegree : selfLoopWeight), so sum === 2 *
536
+ * totalWeight() when undirected. Cached and shared.
537
+ * @returns Float64Array(n)
538
+ */
539
+ weightedDegree(): F64;
540
+ /**
541
+ * Sum of weights over each node's self-loop arcs (selfLoopsPerNode widened when unweighted). Cached and shared.
542
+ * @returns Float64Array(n)
543
+ */
544
+ selfLoopWeight(): F64;
545
+ /**
546
+ * Sum of weights over logical edges (each undirected edge once). Cached.
547
+ * @returns the total weight
548
+ */
549
+ totalWeight(): number;
550
+ /**
551
+ * The arcs a with colIdx[a] === row(a), found by binary search per row. Cached and shared.
552
+ * @returns Uint32Array(selfLoopCount)
553
+ */
554
+ selfLoopArcs(): U32;
555
+ /**
556
+ * Self-loop arcs per node. Cached and shared.
557
+ * @returns Uint32Array(n)
558
+ */
559
+ selfLoopsPerNode(): U32;
560
+ /**
561
+ * Point query: self-loop arcs at one node, O(log d).
562
+ * @param u - the node index
563
+ * @returns the count
564
+ */
565
+ selfLoopsAt(u: number): number;
566
+ /**
567
+ * For every arc, the arc storing the opposite orientation of the same edge (a self-loop maps to itself); a lockstep
568
+ * walk (design section 6.4). Undirected only. Cached and shared.
569
+ * @returns Uint32Array(arcCount); E_DIRECTED on a directed snapshot
570
+ */
571
+ mate(): U32;
572
+ /**
573
+ * Nodes ordered by descending out-degree of the forward or reverse adjacency with the cuGraph tier boundaries. Both
574
+ * variants cached.
575
+ * @param options - which adjacency's degree to order by
576
+ * @returns the permutation and its tier offsets
577
+ */
578
+ degreeOrder(options?: DegreeOrderOptions): DegreeOrderView;
579
+ /**
580
+ * Whether the arc set is closed under reversal with equal weights (forward row v equals reverse row v for every v);
581
+ * true without work when undirected. Cached.
582
+ * @returns true when symmetric
583
+ */
584
+ isSymmetric(): boolean;
585
+ /**
586
+ * Compute a set of views eagerly (inside freeze() through FreezeOptions.prepare, or off the critical path).
587
+ * @param views - the views to materialise
588
+ * @returns this snapshot
589
+ */
590
+ prepare(views: readonly ViewName[]): this;
591
+ /** Release every cached view and every cached gpuView copy; they are recomputed on demand. */
592
+ dropCaches(): void;
593
+ /**
594
+ * Which views are resident.
595
+ * @returns the names of the cached views
596
+ */
597
+ cachedViews(): readonly ViewName[];
598
+ /**
599
+ * Every directed edge becomes undirected; reciprocal pairs collapse to one edge keeping the lower index's row
600
+ * (keep-first). Returns `{ snapshot: this, null maps }` on an undirected snapshot.
601
+ * @param options - reciprocal filtering and the weight reducer
602
+ * @returns the derived graph
603
+ */
604
+ toUndirected(options?: ToUndirectedOptions): DerivedGraph;
605
+ /**
606
+ * Orientation of every edge swapped: the reverse view's arrays become the core. Returns this on an undirected
607
+ * snapshot.
608
+ * @returns the derived graph (same node and edge spaces)
609
+ */
610
+ transpose(): DerivedGraph;
611
+ /**
612
+ * One edge per (u, v) group (parallels are adjacent by invariant I4), survivor = lowest index; flags.multigraph is
613
+ * false afterwards.
614
+ * @param options - reducers and self-loop policy
615
+ * @returns the derived graph
616
+ */
617
+ simplified(options?: SimplifyOptions): DerivedGraph;
618
+ /**
619
+ * Every edge with source !== target.
620
+ * @returns the derived graph
621
+ */
622
+ withoutSelfLoops(): DerivedGraph;
623
+ /**
624
+ * Keep the logical edges whose mask bit is set (a rebuild; iterative algorithms keep their own alive bitmap
625
+ * instead).
626
+ * @param keep - packed bitmap over logical edges; E_MASK_LENGTH when shorter than ceil(edgeCount / 32) words
627
+ * @returns the derived graph
628
+ */
629
+ filterEdges(keep: EdgeMask): DerivedGraph;
630
+ /**
631
+ * The subgraph induced by a node selection: an index list (order = new index order; E_INDEX_RANGE for an
632
+ * out-of-range or repeated index) or a packed mask (ascending order; E_MASK_LENGTH when short). Edges with both
633
+ * endpoints kept.
634
+ * @param selection - the node indices or a mask
635
+ * @returns the derived graph (compact new node space)
636
+ */
637
+ inducedSubgraph(selection: U32 | {
638
+ readonly mask: NodeMask;
639
+ }): DerivedGraph;
640
+ /**
641
+ * Contract the nodes of each partition block into one node (design section 7.3): labels already forming 0..k-1 are
642
+ * kept as block indices, any other labelling is renumbered in first-seen order; E_PARTITION for a wrong length or
643
+ * an INVALID_INDEX label.
644
+ * @param partition - one label per node
645
+ * @param options - weight reducer, self-loop and parallel policies, column reducers
646
+ * @returns the derived graph with blockSizes and an identity id map
647
+ */
648
+ contract(partition: U32, options?: ContractOptions): DerivedGraph;
649
+ /**
650
+ * Permute the node space: perm[newIndex] = oldIndex; the id map follows; edge order is preserved. Never implicit
651
+ * (decision C18).
652
+ * @param perm - a permutation of 0..n-1; E_INVALID_PERMUTATION otherwise
653
+ * @returns the derived graph
654
+ */
655
+ relabel(perm: U32): DerivedGraph;
656
+ /**
657
+ * A new snapshot object sharing the core, the id map and the serial with a CLONED column set plus the given columns
658
+ * (the only operation that clones the column set).
659
+ * @param nodes - node columns to add, keyed by name
660
+ * @param edges - edge columns to add, keyed by name
661
+ * @returns the new snapshot
662
+ */
663
+ withColumns(nodes?: Readonly<Record<string, TypedArrayData | ColumnInput>>, edges?: Readonly<Record<string, TypedArrayData | ColumnInput>>): GraphSnapshot;
664
+ /**
665
+ * Resident bytes of the core, plus the side structures selected by the options.
666
+ * @param options - which side structures to include
667
+ * @returns the byte count
668
+ */
669
+ byteLength(options?: ByteLengthOptions): number;
670
+ /**
671
+ * A 64-bit content hash of the core arrays (two 32-bit FNV-1a lanes) as 16 hex characters, computed lazily and
672
+ * cached (design section 9.3).
673
+ * @returns the hash
674
+ */
675
+ contentHash(): string;
676
+ /**
677
+ * The distinct, exclusively owned backing buffers of the core, id map, typed columns, string stores and extensions:
678
+ * the postMessage transfer list (design section 9.1).
679
+ * @returns the buffers
680
+ */
681
+ transferables(): ArrayBuffer[];
682
+ /**
683
+ * The plain-object wire form: a JSON-serialisable manifest plus ArrayBuffers (design section 9.1). Allocates
684
+ * nothing for typed data except lazily kept representations on first use.
685
+ * @param options - transfer mode, views and columns to include
686
+ * @returns the wire snapshot; E_UNSUPPORTED on a big-endian host
687
+ */
688
+ toWire(options?: ToWireOptions): WireSnapshot;
689
+ /**
690
+ * The GSNP byte container as one contiguous buffer (design section 9.2).
691
+ * @param options - views to include
692
+ * @returns the container bytes; E_UNSUPPORTED on a big-endian host
693
+ */
694
+ toBytes(options?: ToBytesOptions): U8;
695
+ /**
696
+ * The GSNP container as a sequence: header plus manifest, then each 256-padded segment in manifest order, for
697
+ * streaming writers.
698
+ * @param options - views to include
699
+ * @returns the chunks
700
+ */
701
+ toByteChunks(options?: ToBytesOptions): Iterable<U8>;
702
+ /**
703
+ * Check the invariants (design section 11.4); throws E_INVALID_SNAPSHOT with details.invariant and the location on
704
+ * the first violation.
705
+ * @param options - level and checksum comparison
706
+ */
707
+ validate(options?: ValidateOptions): void;
708
+ }
709
+ /**
710
+ * COO typed arrays with dense indices: the 20 ms path of fromEdgeArrays() (design section 8.1). No
711
+ * id Map is built unless `ids` is given.
712
+ */
713
+ export interface EdgeArraysInput {
714
+ /** Whether the graph is directed. */
715
+ readonly directed: boolean;
716
+ /** Required unless `ids` is given; isolates are preserved. */
717
+ readonly nodeCount?: number | undefined;
718
+ /** Optional external ids in index order (length = nodeCount). */
719
+ readonly ids?: readonly NodeId[] | F64 | undefined;
720
+ /** Source node index of every edge. */
721
+ readonly src: U32;
722
+ /** Target node index of every edge. */
723
+ readonly dst: U32;
724
+ /** Per-edge weights; F64 is downcast to f32 and an f64 shadow column kept only when not f32-exact. */
725
+ readonly weights?: F32 | F64 | undefined;
726
+ /** Node columns, keyed by name. */
727
+ readonly nodeColumns?: Readonly<Record<string, TypedArrayData | ColumnInput>> | undefined;
728
+ /** Edge columns, keyed by name. */
729
+ readonly edgeColumns?: Readonly<Record<string, TypedArrayData | ColumnInput>> | undefined;
730
+ /** Graph metadata. */
731
+ readonly meta?: GraphMetaPatch | undefined;
732
+ }
733
+ /**
734
+ * Prebuilt CSR arrays adopted by fromCsr() without copying by default (design section 8.1): the
735
+ * caller transfers ownership and must not mutate them afterwards.
736
+ */
737
+ export interface CsrInput {
738
+ /** Whether the graph is directed. */
739
+ readonly directed: boolean;
740
+ /** Number of nodes. */
741
+ readonly nodeCount: number;
742
+ /** nodeCount + 1 row offsets. */
743
+ readonly rowPtr: U32;
744
+ /** Target node index of every arc. */
745
+ readonly colIdx: U32;
746
+ /** Per-arc weights, or null / absent when unweighted. */
747
+ readonly weights?: F32 | null | undefined;
748
+ /** Absent => identity (directed only; undirected input must supply it). */
749
+ readonly arcToEdge?: U32 | undefined;
750
+ /** Absent => derived in one O(m) pass (or identity). */
751
+ readonly edgeToArc?: U32 | undefined;
752
+ /** Defaults to arcCount (directed) or is derived from arcToEdge. */
753
+ readonly edgeCount?: number | undefined;
754
+ /** Optional external ids in index order. */
755
+ readonly ids?: readonly NodeId[] | F64 | undefined;
756
+ /** Node columns, keyed by name. */
757
+ readonly nodeColumns?: Readonly<Record<string, TypedArrayData | ColumnInput>> | undefined;
758
+ /** Edge columns, keyed by name. */
759
+ readonly edgeColumns?: Readonly<Record<string, TypedArrayData | ColumnInput>> | undefined;
760
+ /** Graph metadata. */
761
+ readonly meta?: GraphMetaPatch | undefined;
762
+ /** Flag claims; verified unless validate === "none". */
763
+ readonly flags?: FlagClaims | undefined;
764
+ }
765
+ /** Options of fromCsr() (design section 8.1). */
766
+ export interface FromCsrOptions {
767
+ /** Validation level; default "full" because adopted arrays typically come from a file or the network. */
768
+ readonly validate?: ValidationLevel | undefined;
769
+ /** Copy the arrays instead of adopting them; default false. */
770
+ readonly copy?: boolean | undefined;
771
+ /**
772
+ * Default true: check invariant I4 and rebuild through the freeze pipeline when rows are unsorted; false asserts
773
+ * sorted rows.
774
+ */
775
+ readonly sortRows?: boolean | undefined;
776
+ }
777
+ /**
778
+ * Plain records, the node-link shape every JSON dialect parses into and what graphty-element's data
779
+ * sources emit (design section 8.1).
780
+ */
781
+ export interface RecordsInput {
782
+ /** Whether the graph is directed. */
783
+ readonly directed: boolean;
784
+ /** Node records; optional when every node appears as an edge endpoint. */
785
+ readonly nodes?: Iterable<Readonly<Record<string, unknown>>> | undefined;
786
+ /** Edge records. */
787
+ readonly edges: Iterable<Readonly<Record<string, unknown>>>;
788
+ /** Node id key; default "id"; null = node index is array position and endpoints are indices (d3 v3). */
789
+ readonly nodeId?: string | null | undefined;
790
+ /** Edge source key; default "source", falling back to "src" / "from". */
791
+ readonly edgeSource?: string | undefined;
792
+ /** Edge target key; default "target", falling back to "dst" / "to". */
793
+ readonly edgeTarget?: string | undefined;
794
+ /** Edge weight key; default "weight"; null = unweighted. */
795
+ readonly edgeWeight?: string | null | undefined;
796
+ /** Column handling; default "infer" (design section 5.1 widening). */
797
+ readonly columns?: "infer" | "json" | "none" | readonly ColumnDecl[] | undefined;
798
+ /** Id coercion; default "keep" (values are already typed). */
799
+ readonly ids?: IdCoercion | undefined;
800
+ }
801
+ //# sourceMappingURL=snapshot.d.ts.map