@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,286 @@
1
+ /**
2
+ * Content checks of the views a wire manifest carries (`includeViews`, design sections 9.1 and 9.5),
3
+ * run at the "structure" level before a carried view is installed on the receiver. Every view is a
4
+ * pure function of the core (design section 7.2), so each check is exact: the index views are
5
+ * compared with what the core says arc by arc in O(n + m) without allocating a second copy, and the
6
+ * four f64 views are compared with the snapshot's own computation. A view that disagrees is
7
+ * E_INVALID_SNAPSHOT with `details.invariant` "I2" (a corrupt index array) or "I17" (a corrupt
8
+ * value array) and `details.view` naming it. At "none" nothing is checked (the manifest is trusted,
9
+ * design section 9.5); at "full" carried views are never installed.
10
+ */
11
+ import { invariantViolation } from "../snapshot/validate.js";
12
+ import { DEGREE_TIER_HIGH, DEGREE_TIER_MID, rowLengths } from "../snapshot/views.js";
13
+ /** The per-arc facts every index-view check reads, computed once per manifest. */
14
+ export class CoreFacts {
15
+ /**
16
+ * Expand the core once.
17
+ * @param snapshot - the snapshot
18
+ */
19
+ constructor(snapshot) {
20
+ const { nodeCount, arcCount, rowPtr, colIdx, directed } = snapshot;
21
+ const arcRow = new Uint32Array(arcCount);
22
+ const loops = new Uint32Array(nodeCount);
23
+ const inDegree = directed ? new Uint32Array(nodeCount) : rowLengths(rowPtr, nodeCount);
24
+ for (let u = 0; u < nodeCount; u++) {
25
+ const end = rowPtr[u + 1];
26
+ for (let a = rowPtr[u]; a < end; a++) {
27
+ arcRow[a] = u;
28
+ const v = colIdx[a];
29
+ if (v === u) {
30
+ loops[u]++;
31
+ }
32
+ if (directed) {
33
+ inDegree[v]++;
34
+ }
35
+ }
36
+ }
37
+ this.arcRow = arcRow;
38
+ this.loops = loops;
39
+ this.inDegree = inDegree;
40
+ }
41
+ /**
42
+ * The exclusive prefix sum of the in-degrees (the reverse rowPtr).
43
+ * @returns nodeCount + 1 offsets
44
+ */
45
+ inDegreePrefix() {
46
+ const n = this.inDegree.length;
47
+ const out = new Uint32Array(n + 1);
48
+ for (let u = 0; u < n; u++) {
49
+ out[u + 1] = out[u] + this.inDegree[u];
50
+ }
51
+ return out;
52
+ }
53
+ }
54
+ /**
55
+ * The error for a carried view that disagrees with the core.
56
+ * @param view - the view name
57
+ * @param member - the member array
58
+ * @param index - the offending index
59
+ * @param invariant - "I2" for an index array, "I17" for a value array
60
+ * @returns the error
61
+ */
62
+ function viewError(view, member, index, invariant) {
63
+ return invariantViolation(invariant, `carried view ${view}.${member} disagrees with the core at ${index}`, {
64
+ view,
65
+ member,
66
+ index,
67
+ reason: "view",
68
+ });
69
+ }
70
+ /**
71
+ * Compare two arrays element by element (NaN equal to NaN).
72
+ * @param view - the view name
73
+ * @param member - the member name
74
+ * @param found - the carried array
75
+ * @param expected - the truth
76
+ * @param invariant - the invariant to report
77
+ */
78
+ function expectSame(view, member, found, expected, invariant) {
79
+ for (let i = 0; i < expected.length; i++) {
80
+ if (!Object.is(found[i], expected[i]) && found[i] !== expected[i]) {
81
+ throw viewError(view, member, i, invariant);
82
+ }
83
+ }
84
+ }
85
+ /**
86
+ * Check that an array is a permutation of 0..length-1.
87
+ * @param view - the view name
88
+ * @param member - the member name
89
+ * @param perm - the array
90
+ */
91
+ function expectPermutation(view, member, perm) {
92
+ const seen = new Uint8Array(perm.length);
93
+ for (let i = 0; i < perm.length; i++) {
94
+ const p = perm[i];
95
+ if (p >= perm.length || seen[p] === 1) {
96
+ throw viewError(view, member, i, "I2");
97
+ }
98
+ seen[p] = 1;
99
+ }
100
+ }
101
+ /**
102
+ * outDegree: the row lengths.
103
+ * @param snapshot - the snapshot
104
+ * @param data - the carried array
105
+ */
106
+ export function checkOutDegree(snapshot, data) {
107
+ expectSame("outDegree", "data", data, rowLengths(snapshot.rowPtr, snapshot.nodeCount), "I2");
108
+ }
109
+ /**
110
+ * inDegree (directed): the in-arc counts.
111
+ * @param facts - the core facts
112
+ * @param data - the carried array
113
+ */
114
+ export function checkInDegree(facts, data) {
115
+ expectSame("inDegree", "data", data, facts.inDegree, "I2");
116
+ }
117
+ /**
118
+ * degree: outDegree + inDegree (directed) or outDegree + loops (undirected), design section 3.4.
119
+ * @param snapshot - the snapshot
120
+ * @param facts - the core facts
121
+ * @param data - the carried array
122
+ */
123
+ export function checkDegree(snapshot, facts, data) {
124
+ const out = rowLengths(snapshot.rowPtr, snapshot.nodeCount);
125
+ const add = snapshot.directed ? facts.inDegree : facts.loops;
126
+ for (let u = 0; u < out.length; u++) {
127
+ if (data[u] !== out[u] + add[u]) {
128
+ throw viewError("degree", "data", u, "I2");
129
+ }
130
+ }
131
+ }
132
+ /**
133
+ * selfLoopsPerNode: the loop arcs per row.
134
+ * @param facts - the core facts
135
+ * @param data - the carried array
136
+ */
137
+ export function checkSelfLoopsPerNode(facts, data) {
138
+ expectSame("selfLoopsPerNode", "data", data, facts.loops, "I2");
139
+ }
140
+ /**
141
+ * selfLoopArcs: ascending arcs, each a loop; with the length fixed to selfLoopCount that is exact.
142
+ * @param snapshot - the snapshot
143
+ * @param facts - the core facts
144
+ * @param data - the carried array
145
+ */
146
+ export function checkSelfLoopArcs(snapshot, facts, data) {
147
+ const { colIdx, arcCount } = snapshot;
148
+ for (let i = 0; i < data.length; i++) {
149
+ const a = data[i];
150
+ if (a >= arcCount || colIdx[a] !== facts.arcRow[a] || (i > 0 && a <= data[i - 1])) {
151
+ throw viewError("selfLoopArcs", "data", i, "I2");
152
+ }
153
+ }
154
+ }
155
+ /**
156
+ * coo.src: the row of every arc.
157
+ * @param facts - the core facts
158
+ * @param src - the carried array
159
+ */
160
+ export function checkCooSrc(facts, src) {
161
+ expectSame("coo", "src", src, facts.arcRow, "I2");
162
+ }
163
+ /**
164
+ * edgeList: `src[e]` is the row of `edgeToArc[e]`, `dst[e]` its target, `weights[e]` its weight.
165
+ * @param snapshot - the snapshot
166
+ * @param facts - the core facts
167
+ * @param src - the carried sources
168
+ * @param dst - the carried targets, or null when colIdx is aliased
169
+ * @param weights - the carried weights, or null when aliased or unweighted
170
+ */
171
+ export function checkEdgeList(snapshot, facts, src, dst, weights) {
172
+ const { edgeCount, edgeToArc, colIdx, arcCount } = snapshot;
173
+ const forward = snapshot.weights;
174
+ for (let e = 0; e < edgeCount; e++) {
175
+ const a = edgeToArc[e];
176
+ if (a >= arcCount || src[e] !== facts.arcRow[a]) {
177
+ throw viewError("edgeList", "src", e, "I2");
178
+ }
179
+ if (dst !== null && dst[e] !== colIdx[a]) {
180
+ throw viewError("edgeList", "dst", e, "I2");
181
+ }
182
+ if (weights !== null && forward !== null && !Object.is(weights[e], forward[a])) {
183
+ throw viewError("edgeList", "weights", e, "I17");
184
+ }
185
+ }
186
+ }
187
+ /**
188
+ * mate (undirected): an involution pairing the two arcs of every non-loop edge (invariant I7) and
189
+ * fixing every loop arc.
190
+ * @param snapshot - the snapshot
191
+ * @param facts - the core facts
192
+ * @param mate - the carried array
193
+ */
194
+ export function checkMate(snapshot, facts, mate) {
195
+ const { arcCount, arcToEdge, colIdx } = snapshot;
196
+ for (let a = 0; a < arcCount; a++) {
197
+ const m = mate[a];
198
+ const loop = colIdx[a] === facts.arcRow[a];
199
+ if (m >= arcCount || mate[m] !== a || arcToEdge[m] !== arcToEdge[a] || (m === a) !== loop) {
200
+ throw viewError("mate", "data", a, "I2");
201
+ }
202
+ }
203
+ }
204
+ /**
205
+ * degreeOrder / reverseDegreeOrder: a permutation ordered by non-increasing degree with ties in
206
+ * ascending node index, and the cuGraph tier offsets of design section 7.2.
207
+ * @param name - the view name
208
+ * @param degree - the degree of every node the order sorts by
209
+ * @param perm - the carried permutation
210
+ * @param segmentOffsets - the carried tier offsets
211
+ */
212
+ export function checkDegreeOrder(name, degree, perm, segmentOffsets) {
213
+ expectPermutation(name, "perm", perm);
214
+ let hi = 0;
215
+ let mid = 0;
216
+ let low = 0;
217
+ for (let i = 0; i < perm.length; i++) {
218
+ const d = degree[perm[i]];
219
+ if (i > 0) {
220
+ const previous = degree[perm[i - 1]];
221
+ if (d > previous || (d === previous && perm[i] < perm[i - 1])) {
222
+ throw viewError(name, "perm", i, "I2");
223
+ }
224
+ }
225
+ if (d >= DEGREE_TIER_HIGH) {
226
+ hi++;
227
+ }
228
+ else if (d >= DEGREE_TIER_MID) {
229
+ mid++;
230
+ }
231
+ else if (d >= 1) {
232
+ low++;
233
+ }
234
+ }
235
+ const expected = [0, hi, hi + mid, hi + mid + low, perm.length];
236
+ expectSame(name, "segmentOffsets", segmentOffsets, expected, "I2");
237
+ }
238
+ /**
239
+ * reverse (directed): the in-adjacency with rows sorted by source and ties by forward arc, `fwdArc`
240
+ * a permutation of the arcs, `colIdx` the sources, `weights` the forward weights gathered.
241
+ * @param snapshot - the snapshot
242
+ * @param facts - the core facts
243
+ * @param reverse - the carried view
244
+ */
245
+ export function checkReverse(snapshot, facts, reverse) {
246
+ const { nodeCount, arcCount, colIdx } = snapshot;
247
+ const forward = snapshot.weights;
248
+ const { rowPtr, fwdArc } = reverse;
249
+ const revIdx = reverse.colIdx;
250
+ const revWeights = reverse.weights;
251
+ if (rowPtr[0] !== 0 || rowPtr[nodeCount] !== arcCount) {
252
+ throw viewError("reverse", "rowPtr", 0, "I2");
253
+ }
254
+ expectSame("reverse", "rowPtr", rowPtr, facts.inDegreePrefix(), "I2");
255
+ expectPermutation("reverse", "fwdArc", fwdArc);
256
+ for (let v = 0; v < nodeCount; v++) {
257
+ const end = rowPtr[v + 1];
258
+ for (let k = rowPtr[v]; k < end; k++) {
259
+ const a = fwdArc[k];
260
+ const source = facts.arcRow[a];
261
+ if (colIdx[a] !== v || revIdx[k] !== source) {
262
+ throw viewError("reverse", "colIdx", k, "I2");
263
+ }
264
+ if (k > rowPtr[v]) {
265
+ const previous = fwdArc[k - 1];
266
+ const previousSource = facts.arcRow[previous];
267
+ if (source < previousSource || (source === previousSource && a <= previous)) {
268
+ throw viewError("reverse", "fwdArc", k, "I2");
269
+ }
270
+ }
271
+ if (revWeights !== null && forward !== null && !Object.is(revWeights[k], forward[a])) {
272
+ throw viewError("reverse", "weights", k, "I17");
273
+ }
274
+ }
275
+ }
276
+ }
277
+ /**
278
+ * An f64 view: compared with the snapshot's own computation.
279
+ * @param name - the view name
280
+ * @param found - the carried array
281
+ * @param expected - the computed truth
282
+ */
283
+ export function checkF64View(name, found, expected) {
284
+ expectSame(name, "data", found, expected, "I17");
285
+ }
286
+ //# sourceMappingURL=carried-views.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carried-views.js","sourceRoot":"","sources":["../../../src/wire/carried-views.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGrF,kFAAkF;A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EAAE,KAAK,CAAC,CAAC;YACpD,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAU,EAAE,QAAa;IAChE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The wire decoder (design sections 4.5, 5.9, 9.1, 9.5 and 11.3): `fromWire()` rebuilds a snapshot
3
+ * from a WireSnapshot, and `decodeManifest()` is the shared reader the GSNP container functions of
4
+ * bytes.ts drive with their own buffer regions.
5
+ *
6
+ * Rules (design section 9.1): a manifest whose `formatVersion` is not the reader's or whose wire
7
+ * major is unknown is refused with E_UNSUPPORTED_VERSION; a newer wire minor is read by ignoring
8
+ * unknown manifest fields; an unknown column dtype is E_UNSUPPORTED unless `unknownColumns: "skip"`
9
+ * drops the column and names it in `meta.extra["graphty.skippedColumns"]`; an unknown id-map kind
10
+ * is always E_UNSUPPORTED; unknown view entries are ignored and recomputed. Every WireBufferRef is
11
+ * checked against its buffer before a typed array is built over it (E_BAD_SERIALIZATION with
12
+ * details.ref), whatever the validation level, because a RangeError from a typed-array constructor
13
+ * is never an acceptable failure mode; the "structure" and "full" levels add the checks of design
14
+ * section 9.5 and then run the snapshot's own validate().
15
+ *
16
+ * Buffers are adopted by reference by default: the arrays are views into the caller's buffers and
17
+ * the arena descriptor is honoured. A SharedArrayBuffer is copied (decision D-SAB), and `copy: true`
18
+ * copies every buffer before adoption.
19
+ */
20
+ import { GraphFormatError } from "../errors.js";
21
+ import { type GraphSnapshot } from "../snapshot/graph-snapshot.js";
22
+ import { type FromWireOptions, type U8, type ValidationLevel, type WireSnapshot } from "../types/index.js";
23
+ /** The meta.extra key naming the columns dropped under unknownColumns: "skip" (design section 9.1). */
24
+ export declare const SKIPPED_COLUMNS_KEY = "graphty.skippedColumns";
25
+ /**
26
+ * The E_BAD_SERIALIZATION error of a malformed manifest member or buffer reference.
27
+ * @param ref - the manifest path, e.g. "nodeColumns[2].data"
28
+ * @param reason - what is wrong
29
+ * @param details - extra context
30
+ * @returns the error
31
+ */
32
+ export declare function badWire(ref: string, reason: string, details?: Readonly<Record<string, unknown>>): GraphFormatError;
33
+ /**
34
+ * Decode a manifest JSON value (design section 5.9): `{ "$num": "Infinity" | "-Infinity" | "NaN" |
35
+ * "-0" }` becomes the number, `{ "$esc": { ... } }` unwraps a user object whose only key collided
36
+ * with a tag (the writer's escape), arrays and plain objects are rebuilt recursively (a key named
37
+ * `__proto__`, `constructor` or `prototype` is refused), everything else is returned as is. Nesting
38
+ * deeper than MAX_JSON_DEPTH is E_BAD_SERIALIZATION rather than a stack overflow.
39
+ * @param value - the value from the manifest
40
+ * @param path - the manifest path for error messages
41
+ * @param depth - the current nesting depth
42
+ * @returns the decoded value
43
+ */
44
+ export declare function decodeJsonValue(value: unknown, path: string, depth?: number): unknown;
45
+ /**
46
+ * Parse JSON text from a container (the manifest or one json column row) with the guarding
47
+ * reviver. A syntax error is E_BAD_SERIALIZATION.
48
+ * @param text - the JSON text
49
+ * @param path - the manifest path for error messages
50
+ * @returns the parsed value
51
+ */
52
+ export declare function parseGuardedJson(text: string, path: string): unknown;
53
+ /** The options of fromWire / fromBytes after defaults were applied. */
54
+ interface ResolvedFromWireOptions {
55
+ /** The validation level. */
56
+ readonly level: ValidationLevel;
57
+ /** Whether buffers are copied before adoption. */
58
+ readonly copy: boolean;
59
+ /** What to do with an unknown column dtype. */
60
+ readonly unknownColumns: "error" | "skip";
61
+ }
62
+ /**
63
+ * Apply defaults to FromWireOptions and reject values outside their documented sets (E_UNSUPPORTED).
64
+ * @param options - the caller's options
65
+ * @param defaultLevel - "structure" for fromWire, "full" for fromBytes
66
+ * @returns the resolved options
67
+ */
68
+ export declare function resolveFromWireOptions(options: FromWireOptions | undefined, defaultLevel: ValidationLevel): ResolvedFromWireOptions;
69
+ /** Where a located byte range lives. */
70
+ export interface LocatedRange {
71
+ /** The plain ArrayBuffer holding the bytes. */
72
+ readonly buffer: ArrayBuffer;
73
+ /** The absolute byte offset of the range inside `buffer`. */
74
+ readonly byteOffset: number;
75
+ }
76
+ /**
77
+ * One buffer index of a manifest as the decoder sees it: a byte length for range checks, a locator
78
+ * that finds a range contiguously in one plain buffer (null when it spans chunks or lives in a
79
+ * SharedArrayBuffer) and a reader that copies a range out.
80
+ */
81
+ export interface WireRegion {
82
+ /** The byte length every reference is checked against. */
83
+ readonly byteLength: number;
84
+ /**
85
+ * Find a byte range in one plain buffer.
86
+ * @param byteOffset - region-relative start
87
+ * @param byteLength - length
88
+ * @returns the buffer and absolute offset, or null when the range cannot be adopted
89
+ */
90
+ locate(byteOffset: number, byteLength: number): LocatedRange | null;
91
+ /**
92
+ * Copy a byte range into a fresh buffer.
93
+ * @param byteOffset - region-relative start
94
+ * @param byteLength - length
95
+ * @returns a Uint8Array at offset 0 of a fresh ArrayBuffer of at least byteLength bytes
96
+ */
97
+ read(byteOffset: number, byteLength: number): U8;
98
+ }
99
+ /**
100
+ * A region over one plain ArrayBuffer.
101
+ * @param buffer - the buffer
102
+ * @param base - the absolute byte offset of the region's start inside the buffer
103
+ * @param byteLength - the region's byte length
104
+ * @returns the region
105
+ */
106
+ export declare function bufferRegion(buffer: ArrayBuffer, base: number, byteLength: number): WireRegion;
107
+ /**
108
+ * Whether a value is a SharedArrayBuffer (never adopted, decision D-SAB).
109
+ * @param value - the value
110
+ * @returns true for a SharedArrayBuffer
111
+ */
112
+ export declare function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer;
113
+ /**
114
+ * Check the manifest's discriminator and versions (design sections 9.1 and 13.5): `format`, the
115
+ * wire major (E_UNSUPPORTED_VERSION kind "wire") and `formatVersion` (kind "format"). A newer wire
116
+ * minor is accepted.
117
+ * @param manifest - the manifest object
118
+ * @returns the wire version pair
119
+ */
120
+ export declare function checkManifestVersions(manifest: Record<string, unknown>): readonly [number, number];
121
+ /**
122
+ * Rebuild a snapshot from a manifest and the regions its references index (design sections 9.1 and
123
+ * 9.5): versions checked, core arrays and arena adopted, id map and tables decoded, then the
124
+ * snapshot validated at the requested level.
125
+ * @param manifestRaw - the manifest (an object; already parsed for a container)
126
+ * @param regions - one region per buffer index
127
+ * @param options - the resolved options
128
+ * @param honourArena - whether the manifest's arena descriptor is adopted (false for chunked input)
129
+ * @returns the snapshot
130
+ */
131
+ export declare function decodeManifest(manifestRaw: unknown, regions: readonly WireRegion[], options: ResolvedFromWireOptions, honourArena: boolean): GraphSnapshot;
132
+ /**
133
+ * Rebuild a snapshot from its wire form (design section 9.1). Defaults: `validate: "structure"`
134
+ * (the manifest is trusted to have come from this package; the cheap checks still run) and `copy:
135
+ * false` (the arrays are views into `wire.buffers`; a SharedArrayBuffer is copied). The reverse id
136
+ * Map and decoded strings are rebuilt lazily; carried views (`includeViews`) are installed on the
137
+ * receiver below "full" and recomputed under "full", where nothing carried is trusted.
138
+ * @param wire - the wire snapshot
139
+ * @param options - validation level, copy and unknown-column policy
140
+ * @returns the snapshot; E_UNSUPPORTED_VERSION, E_UNSUPPORTED, E_BAD_SERIALIZATION or E_INVALID_SNAPSHOT on bad input
141
+ */
142
+ export declare function fromWire(wire: WireSnapshot, options?: FromWireOptions): GraphSnapshot;
143
+ export {};
144
+ //# sourceMappingURL=from-wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-wire.d.ts","sourceRoot":"","sources":["../../../src/wire/from-wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAkB,KAAK,aAAa,EAAY,MAAM,+BAA+B,CAAC;AAE7F,OAAO,EAaH,KAAK,eAAe,EAMpB,KAAK,EAAE,EAEP,KAAK,eAAe,EAGpB,KAAK,YAAY,EACpB,MAAM,mBAAmB,CAAC;AAsE3B,uGAAuG;AACvG,eAAO,MAAM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