@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,85 @@
1
+ /**
2
+ * Core-array allocation for the freeze pipeline (design sections 6.3 step 11 and 10.3): the five core
3
+ * arrays of a snapshot laid out hot to cold (rowPtr, colIdx, weights, arcToEdge, edgeToArc) inside ONE
4
+ * ArrayBuffer at 256-byte-aligned offsets, or -- for the transient pass of a non-"keep" duplicate
5
+ * policy and for `freeze({ arena: false })` -- as separate fresh buffers. Either way every array is
6
+ * 4-byte aligned over a plain ArrayBuffer (invariant I10). A zero-length array, an absent weights
7
+ * array and an identity permutation have a null segment and occupy nothing in the arena.
8
+ *
9
+ * The counting-sort scatter of counting-sort.ts writes straight into the arrays returned here, so a
10
+ * "keep"-policy freeze touches the arena exactly once (design section 6.3 step 6).
11
+ */
12
+ import { type ArenaLayout, type CoreArrayName, type F32, type U32 } from "../types/index.js";
13
+ /** The shape of a core to allocate: the counts and which optional arrays exist. */
14
+ interface CoreShape {
15
+ /** The node count n. */
16
+ readonly nodeCount: number;
17
+ /** The arc count A. */
18
+ readonly arcCount: number;
19
+ /** The logical edge count E. */
20
+ readonly edgeCount: number;
21
+ /** Whether the weights array exists. */
22
+ readonly weighted: boolean;
23
+ /** Whether the permutation is the identity, in which case arcToEdge / edgeToArc are not allocated. */
24
+ readonly identity: boolean;
25
+ }
26
+ /** The five core arrays plus the arena they live in (null for separate buffers). */
27
+ export interface CoreArrays {
28
+ /** nodeCount + 1 row offsets. */
29
+ readonly rowPtr: U32;
30
+ /** arcCount targets. */
31
+ readonly colIdx: U32;
32
+ /** arcCount f32 weights, or null when unweighted. */
33
+ readonly weights: F32 | null;
34
+ /** arcCount entries, or null when the permutation is the identity. */
35
+ readonly arcToEdge: U32 | null;
36
+ /** edgeCount entries, or null when the permutation is the identity. */
37
+ readonly edgeToArc: U32 | null;
38
+ /** The arena, or null when the arrays are separate buffers. */
39
+ readonly arena: ArenaLayout | null;
40
+ }
41
+ /** The order of the core arrays inside the arena: hot to cold (design section 10.3). */
42
+ /** The core arrays in arena order, hot to cold (design section 10.3); the wire and fromCsr use the same order. */
43
+ export declare const CORE_ORDER: readonly CoreArrayName[];
44
+ /**
45
+ * Allocate the core arrays as separate fresh buffers (design section 6.3 step 11 with `arena: false`,
46
+ * and the transient target of a non-"keep" duplicate policy). Every array is a fresh typed array, so
47
+ * I10 holds by the constructor guarantee.
48
+ * @param shape - the core shape
49
+ * @returns the arrays with `arena: null`
50
+ */
51
+ export declare function allocateSeparateCore(shape: CoreShape): CoreArrays;
52
+ /**
53
+ * Allocate the core arrays inside one arena (design section 10.3): one ArrayBuffer of the total padded
54
+ * size, every non-empty segment starting at a multiple of 256 bytes, ordered rowPtr, colIdx, weights,
55
+ * arcToEdge, edgeToArc. `hotByteLength` is the end of the weights segment (or of colIdx when
56
+ * unweighted). For the worked example of section 10.3 (n = 100,000, A = 2,000,000, E = 1,000,000,
57
+ * weighted, permutations materialised) the segments start at 0 / 400,128 / 8,400,128 / 16,400,128 /
58
+ * 24,400,128 and the arena is 28,400,128 bytes.
59
+ * @param shape - the core shape
60
+ * @returns the arrays as views into the arena, plus its layout
61
+ */
62
+ export declare function allocateArenaCore(shape: CoreShape): CoreArrays;
63
+ /**
64
+ * Allocate the core arrays for a shape, in one arena or as separate buffers.
65
+ * @param shape - the core shape
66
+ * @param useArena - true for one 256-aligned arena (the freeze default), false for separate buffers
67
+ * @returns the arrays
68
+ */
69
+ export declare function allocateCoreArrays(shape: CoreShape, useArena: boolean): CoreArrays;
70
+ /**
71
+ * The shape of an already built core.
72
+ * @param core - the core arrays
73
+ * @returns the shape
74
+ */
75
+ export declare function shapeOfCore(core: CoreArrays): CoreShape;
76
+ /**
77
+ * Copy a core built in separate buffers into a fresh arena of the same shape (the non-"keep" duplicate
78
+ * policy path of design section 6.3 step 7 when nothing was merged: the transient arrays are final,
79
+ * only their home changes). The source arrays are not modified.
80
+ * @param core - the core in separate buffers
81
+ * @returns the same contents as views into a new arena
82
+ */
83
+ export declare function copyCoreIntoArena(core: CoreArrays): CoreArrays;
84
+ export {};
85
+ //# sourceMappingURL=arena.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arena.d.ts","sourceRoot":"","sources":["../../../src/builder/arena.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,KAAK,WAAW,EAAqB,KAAK,aAAa,EAAE,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhH,mFAAmF;AACnF,UAAU,SAAS;IACf,wBAAwB;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uBAAuB;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IA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ot to cold (rowPtr, colIdx, weights, arcToEdge, edgeToArc) inside ONE
4
+ * ArrayBuffer at 256-byte-aligned offsets, or -- for the transient pass of a non-"keep" duplicate
5
+ * policy and for `freeze({ arena: false })` -- as separate fresh buffers. Either way every array is
6
+ * 4-byte aligned over a plain ArrayBuffer (invariant I10). A zero-length array, an absent weights
7
+ * array and an identity permutation have a null segment and occupy nothing in the arena.
8
+ *
9
+ * The counting-sort scatter of counting-sort.ts writes straight into the arrays returned here, so a
10
+ * "keep"-policy freeze touches the arena exactly once (design section 6.3 step 6).
11
+ */
12
+ import { ALIGNMENT } from "../constants.js";
13
+ import { layoutSegments } from "../util/typed-array.js";
14
+ /** The order of the core arrays inside the arena: hot to cold (design section 10.3). */
15
+ /** The core arrays in arena order, hot to cold (design section 10.3); the wire and fromCsr use the same order. */
16
+ export const CORE_ORDER = ["rowPtr", "colIdx", "weights", "arcToEdge", "edgeToArc"];
17
+ /**
18
+ * The unpadded byte length of every core array in arena order for a shape.
19
+ * @param shape - the core shape
20
+ * @returns five byte lengths; 0 for an absent array
21
+ */
22
+ function byteLengthsOf(shape) {
23
+ const permArcs = shape.identity ? 0 : shape.arcCount;
24
+ const permEdges = shape.identity ? 0 : shape.edgeCount;
25
+ return [
26
+ 4 * (shape.nodeCount + 1),
27
+ 4 * shape.arcCount,
28
+ shape.weighted ? 4 * shape.arcCount : 0,
29
+ 4 * permArcs,
30
+ 4 * permEdges,
31
+ ];
32
+ }
33
+ /**
34
+ * Allocate the core arrays as separate fresh buffers (design section 6.3 step 11 with `arena: false`,
35
+ * and the transient target of a non-"keep" duplicate policy). Every array is a fresh typed array, so
36
+ * I10 holds by the constructor guarantee.
37
+ * @param shape - the core shape
38
+ * @returns the arrays with `arena: null`
39
+ */
40
+ export function allocateSeparateCore(shape) {
41
+ return {
42
+ rowPtr: new Uint32Array(shape.nodeCount + 1),
43
+ colIdx: new Uint32Array(shape.arcCount),
44
+ weights: shape.weighted ? new Float32Array(shape.arcCount) : null,
45
+ arcToEdge: shape.identity ? null : new Uint32Array(shape.arcCount),
46
+ edgeToArc: shape.identity ? null : new Uint32Array(shape.edgeCount),
47
+ arena: null,
48
+ };
49
+ }
50
+ /**
51
+ * Allocate the core arrays inside one arena (design section 10.3): one ArrayBuffer of the total padded
52
+ * size, every non-empty segment starting at a multiple of 256 bytes, ordered rowPtr, colIdx, weights,
53
+ * arcToEdge, edgeToArc. `hotByteLength` is the end of the weights segment (or of colIdx when
54
+ * unweighted). For the worked example of section 10.3 (n = 100,000, A = 2,000,000, E = 1,000,000,
55
+ * weighted, permutations materialised) the segments start at 0 / 400,128 / 8,400,128 / 16,400,128 /
56
+ * 24,400,128 and the arena is 28,400,128 bytes.
57
+ * @param shape - the core shape
58
+ * @returns the arrays as views into the arena, plus its layout
59
+ */
60
+ export function allocateArenaCore(shape) {
61
+ const byteLengths = byteLengthsOf(shape);
62
+ const layout = layoutSegments(byteLengths, ALIGNMENT);
63
+ const buffer = new ArrayBuffer(layout.byteLength);
64
+ const segments = {
65
+ rowPtr: null,
66
+ colIdx: null,
67
+ weights: null,
68
+ arcToEdge: null,
69
+ edgeToArc: null,
70
+ };
71
+ let hotByteLength = 0;
72
+ for (let i = 0; i < CORE_ORDER.length; i++) {
73
+ const offset = layout.offsets[i];
74
+ if (offset === null) {
75
+ continue;
76
+ }
77
+ const segment = Object.freeze({ byteOffset: offset, byteLength: byteLengths[i] });
78
+ segments[CORE_ORDER[i]] = segment;
79
+ if (i <= 2) {
80
+ hotByteLength = offset + byteLengths[i];
81
+ }
82
+ }
83
+ const u32 = (name, length) => {
84
+ const segment = segments[name];
85
+ return segment === null ? new Uint32Array(0) : new Uint32Array(buffer, segment.byteOffset, length);
86
+ };
87
+ let weights = null;
88
+ if (shape.weighted) {
89
+ const segment = segments.weights;
90
+ weights = segment === null ? new Float32Array(0) : new Float32Array(buffer, segment.byteOffset, shape.arcCount);
91
+ }
92
+ const arena = Object.freeze({
93
+ buffer,
94
+ byteOffset: 0,
95
+ byteLength: layout.byteLength,
96
+ alignment: ALIGNMENT,
97
+ segments: Object.freeze(segments),
98
+ hotByteLength,
99
+ });
100
+ return {
101
+ rowPtr: u32("rowPtr", shape.nodeCount + 1),
102
+ colIdx: u32("colIdx", shape.arcCount),
103
+ weights,
104
+ arcToEdge: shape.identity ? null : u32("arcToEdge", shape.arcCount),
105
+ edgeToArc: shape.identity ? null : u32("edgeToArc", shape.edgeCount),
106
+ arena,
107
+ };
108
+ }
109
+ /**
110
+ * Allocate the core arrays for a shape, in one arena or as separate buffers.
111
+ * @param shape - the core shape
112
+ * @param useArena - true for one 256-aligned arena (the freeze default), false for separate buffers
113
+ * @returns the arrays
114
+ */
115
+ export function allocateCoreArrays(shape, useArena) {
116
+ return useArena ? allocateArenaCore(shape) : allocateSeparateCore(shape);
117
+ }
118
+ /**
119
+ * The shape of an already built core.
120
+ * @param core - the core arrays
121
+ * @returns the shape
122
+ */
123
+ export function shapeOfCore(core) {
124
+ return {
125
+ nodeCount: core.rowPtr.length - 1,
126
+ arcCount: core.colIdx.length,
127
+ edgeCount: core.edgeToArc === null ? core.colIdx.length : core.edgeToArc.length,
128
+ weighted: core.weights !== null,
129
+ identity: core.arcToEdge === null,
130
+ };
131
+ }
132
+ /**
133
+ * Copy a core built in separate buffers into a fresh arena of the same shape (the non-"keep" duplicate
134
+ * policy path of design section 6.3 step 7 when nothing was merged: the transient arrays are final,
135
+ * only their home changes). The source arrays are not modified.
136
+ * @param core - the core in separate buffers
137
+ * @returns the same contents as views into a new arena
138
+ */
139
+ export function copyCoreIntoArena(core) {
140
+ const out = allocateArenaCore(shapeOfCore(core));
141
+ out.rowPtr.set(core.rowPtr);
142
+ out.colIdx.set(core.colIdx);
143
+ if (out.weights !== null && core.weights !== null) {
144
+ out.weights.set(core.weights);
145
+ }
146
+ if (out.arcToEdge !== null && core.arcToEdge !== null) {
147
+ out.arcToEdge.set(core.arcToEdge);
148
+ }
149
+ if (out.edgeToArc !== null && core.edgeToArc !== null) {
150
+ out.edgeToArc.set(core.edgeToArc);
151
+ }
152
+ return out;
153
+ }
154
+ //# sourceMappingURL=arena.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arena.js","sourceRoot":"","sources":["../../../src/builder/arena.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAgCxD,wFAAwF;AACxF,kHAAkH;AAClH,MAAM,CAAC,MAAM,UAAU,GAA6B,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAE9G;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAgB;IACnC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IACrD,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;IACvD,OAAO;QACH,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;QACzB,CAAC,GAAG,KAAK,CAAC,QAAQ;QAClB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,GAAG,QAAQ;QACZ,CAAC,GAAG,SAAS;KAChB,CAAC;AACN,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgB;IACjD,OAAO;QACH,MAAM,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;QAC5C,MAAM,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC;QACvC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,YAA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