@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.
- package/LICENSE +21 -0
- package/README.md +216 -43
- package/dist/graph-format.d.ts +1 -0
- package/dist/graph-format.d.ts.map +1 -0
- package/dist/graph-format.js +15798 -0
- package/dist/graph-format.js.map +1 -0
- package/dist/src/builder/arena.d.ts +85 -0
- package/dist/src/builder/arena.d.ts.map +1 -0
- package/dist/src/builder/arena.js +154 -0
- package/dist/src/builder/arena.js.map +1 -0
- package/dist/src/builder/compact.d.ts +515 -0
- package/dist/src/builder/compact.d.ts.map +1 -0
- package/dist/src/builder/compact.js +1553 -0
- package/dist/src/builder/compact.js.map +1 -0
- package/dist/src/builder/counting-sort.d.ts +96 -0
- package/dist/src/builder/counting-sort.d.ts.map +1 -0
- package/dist/src/builder/counting-sort.js +430 -0
- package/dist/src/builder/counting-sort.js.map +1 -0
- package/dist/src/builder/freeze.d.ts +72 -0
- package/dist/src/builder/freeze.d.ts.map +1 -0
- package/dist/src/builder/freeze.js +548 -0
- package/dist/src/builder/freeze.js.map +1 -0
- package/dist/src/builder/graph-builder.d.ts +602 -0
- package/dist/src/builder/graph-builder.d.ts.map +1 -0
- package/dist/src/builder/graph-builder.js +1940 -0
- package/dist/src/builder/graph-builder.js.map +1 -0
- package/dist/src/builder/options.d.ts +16 -0
- package/dist/src/builder/options.d.ts.map +1 -0
- package/dist/src/builder/options.js +21 -0
- package/dist/src/builder/options.js.map +1 -0
- package/dist/src/columns/bitmap.d.ts +96 -0
- package/dist/src/columns/bitmap.d.ts.map +1 -0
- package/dist/src/columns/bitmap.js +184 -0
- package/dist/src/columns/bitmap.js.map +1 -0
- package/dist/src/columns/column.d.ts +220 -0
- package/dist/src/columns/column.d.ts.map +1 -0
- package/dist/src/columns/column.js +2109 -0
- package/dist/src/columns/column.js.map +1 -0
- package/dist/src/columns/dictionary.d.ts +60 -0
- package/dist/src/columns/dictionary.d.ts.map +1 -0
- package/dist/src/columns/dictionary.js +102 -0
- package/dist/src/columns/dictionary.js.map +1 -0
- package/dist/src/columns/growable.d.ts +198 -0
- package/dist/src/columns/growable.d.ts.map +1 -0
- package/dist/src/columns/growable.js +296 -0
- package/dist/src/columns/growable.js.map +1 -0
- package/dist/src/columns/infer.d.ts +121 -0
- package/dist/src/columns/infer.d.ts.map +1 -0
- package/dist/src/columns/infer.js +268 -0
- package/dist/src/columns/infer.js.map +1 -0
- package/dist/src/columns/remap.d.ts +143 -0
- package/dist/src/columns/remap.d.ts.map +1 -0
- package/dist/src/columns/remap.js +588 -0
- package/dist/src/columns/remap.js.map +1 -0
- package/dist/src/columns/table.d.ts +184 -0
- package/dist/src/columns/table.d.ts.map +1 -0
- package/dist/src/columns/table.js +485 -0
- package/dist/src/columns/table.js.map +1 -0
- package/dist/src/constants.d.ts +34 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +79 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +76 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +32 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/ids/edge-id-index.d.ts +77 -0
- package/dist/src/ids/edge-id-index.d.ts.map +1 -0
- package/dist/src/ids/edge-id-index.js +155 -0
- package/dist/src/ids/edge-id-index.js.map +1 -0
- package/dist/src/ids/node-id-map.d.ts +280 -0
- package/dist/src/ids/node-id-map.d.ts.map +1 -0
- package/dist/src/ids/node-id-map.js +1139 -0
- package/dist/src/ids/node-id-map.js.map +1 -0
- package/dist/src/ids/string-store.d.ts +219 -0
- package/dist/src/ids/string-store.d.ts.map +1 -0
- package/dist/src/ids/string-store.js +526 -0
- package/dist/src/ids/string-store.js.map +1 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/populate/from-csr.d.ts +61 -0
- package/dist/src/populate/from-csr.d.ts.map +1 -0
- package/dist/src/populate/from-csr.js +706 -0
- package/dist/src/populate/from-csr.js.map +1 -0
- package/dist/src/populate/from-edge-arrays.d.ts +51 -0
- package/dist/src/populate/from-edge-arrays.d.ts.map +1 -0
- package/dist/src/populate/from-edge-arrays.js +217 -0
- package/dist/src/populate/from-edge-arrays.js.map +1 -0
- package/dist/src/populate/from-records.d.ts +51 -0
- package/dist/src/populate/from-records.d.ts.map +1 -0
- package/dist/src/populate/from-records.js +447 -0
- package/dist/src/populate/from-records.js.map +1 -0
- package/dist/src/snapshot/derived.d.ts +211 -0
- package/dist/src/snapshot/derived.d.ts.map +1 -0
- package/dist/src/snapshot/derived.js +1254 -0
- package/dist/src/snapshot/derived.js.map +1 -0
- package/dist/src/snapshot/graph-meta.d.ts +23 -0
- package/dist/src/snapshot/graph-meta.d.ts.map +1 -0
- package/dist/src/snapshot/graph-meta.js +159 -0
- package/dist/src/snapshot/graph-meta.js.map +1 -0
- package/dist/src/snapshot/graph-snapshot.d.ts +509 -0
- package/dist/src/snapshot/graph-snapshot.d.ts.map +1 -0
- package/dist/src/snapshot/graph-snapshot.js +1247 -0
- package/dist/src/snapshot/graph-snapshot.js.map +1 -0
- package/dist/src/snapshot/hash.d.ts +90 -0
- package/dist/src/snapshot/hash.d.ts.map +1 -0
- package/dist/src/snapshot/hash.js +228 -0
- package/dist/src/snapshot/hash.js.map +1 -0
- package/dist/src/snapshot/queries.d.ts +74 -0
- package/dist/src/snapshot/queries.d.ts.map +1 -0
- package/dist/src/snapshot/queries.js +131 -0
- package/dist/src/snapshot/queries.js.map +1 -0
- package/dist/src/snapshot/validate.d.ts +192 -0
- package/dist/src/snapshot/validate.d.ts.map +1 -0
- package/dist/src/snapshot/validate.js +990 -0
- package/dist/src/snapshot/validate.js.map +1 -0
- package/dist/src/snapshot/views.d.ts +274 -0
- package/dist/src/snapshot/views.d.ts.map +1 -0
- package/dist/src/snapshot/views.js +856 -0
- package/dist/src/snapshot/views.js.map +1 -0
- package/dist/src/types/builder.d.ts +456 -0
- package/dist/src/types/builder.d.ts.map +1 -0
- package/dist/src/types/builder.js +11 -0
- package/dist/src/types/builder.js.map +1 -0
- package/dist/src/types/columns.d.ts +615 -0
- package/dist/src/types/columns.d.ts.map +1 -0
- package/dist/src/types/columns.js +14 -0
- package/dist/src/types/columns.js.map +1 -0
- package/dist/src/types/index.d.ts +14 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +11 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/internal.d.ts +172 -0
- package/dist/src/types/internal.d.ts.map +1 -0
- package/dist/src/types/internal.js +13 -0
- package/dist/src/types/internal.js.map +1 -0
- package/dist/src/types/snapshot.d.ts +801 -0
- package/dist/src/types/snapshot.d.ts.map +1 -0
- package/dist/src/types/snapshot.js +14 -0
- package/dist/src/types/snapshot.js.map +1 -0
- package/dist/src/types/wire.d.ts +196 -0
- package/dist/src/types/wire.d.ts.map +1 -0
- package/dist/src/types/wire.js +8 -0
- package/dist/src/types/wire.js.map +1 -0
- package/dist/src/util/mask.d.ts +55 -0
- package/dist/src/util/mask.d.ts.map +1 -0
- package/dist/src/util/mask.js +71 -0
- package/dist/src/util/mask.js.map +1 -0
- package/dist/src/util/options.d.ts +22 -0
- package/dist/src/util/options.d.ts.map +1 -0
- package/dist/src/util/options.js +49 -0
- package/dist/src/util/options.js.map +1 -0
- package/dist/src/util/shared-buffers.d.ts +42 -0
- package/dist/src/util/shared-buffers.d.ts.map +1 -0
- package/dist/src/util/shared-buffers.js +52 -0
- package/dist/src/util/shared-buffers.js.map +1 -0
- package/dist/src/util/typed-array.d.ts +205 -0
- package/dist/src/util/typed-array.d.ts.map +1 -0
- package/dist/src/util/typed-array.js +289 -0
- package/dist/src/util/typed-array.js.map +1 -0
- package/dist/src/wire/bytes.d.ts +69 -0
- package/dist/src/wire/bytes.d.ts.map +1 -0
- package/dist/src/wire/bytes.js +361 -0
- package/dist/src/wire/bytes.js.map +1 -0
- package/dist/src/wire/carried-views.d.ts +111 -0
- package/dist/src/wire/carried-views.d.ts.map +1 -0
- package/dist/src/wire/carried-views.js +286 -0
- package/dist/src/wire/carried-views.js.map +1 -0
- package/dist/src/wire/from-wire.d.ts +144 -0
- package/dist/src/wire/from-wire.d.ts.map +1 -0
- package/dist/src/wire/from-wire.js +1425 -0
- package/dist/src/wire/from-wire.js.map +1 -0
- package/dist/src/wire/to-wire.d.ts +171 -0
- package/dist/src/wire/to-wire.d.ts.map +1 -0
- package/dist/src/wire/to-wire.js +652 -0
- package/dist/src/wire/to-wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +72 -7
- package/src/builder/arena.ts +192 -0
- package/src/builder/compact.ts +1811 -0
- package/src/builder/counting-sort.ts +506 -0
- package/src/builder/freeze.ts +689 -0
- package/src/builder/graph-builder.ts +2264 -0
- package/src/builder/options.ts +29 -0
- package/src/columns/bitmap.ts +196 -0
- package/src/columns/column.ts +2574 -0
- package/src/columns/dictionary.ts +114 -0
- package/src/columns/growable.ts +350 -0
- package/src/columns/infer.ts +285 -0
- package/src/columns/remap.ts +663 -0
- package/src/columns/table.ts +568 -0
- package/src/constants.ts +89 -0
- package/src/errors.ts +115 -0
- package/src/ids/edge-id-index.ts +179 -0
- package/src/ids/node-id-map.ts +1340 -0
- package/src/ids/string-store.ts +589 -0
- package/src/index.ts +139 -0
- package/src/lib-resizable-array-buffer.d.ts +34 -0
- package/src/populate/from-csr.ts +802 -0
- package/src/populate/from-edge-arrays.ts +257 -0
- package/src/populate/from-records.ts +536 -0
- package/src/snapshot/derived.ts +1486 -0
- package/src/snapshot/graph-meta.ts +167 -0
- package/src/snapshot/graph-snapshot.ts +1503 -0
- package/src/snapshot/hash.ts +241 -0
- package/src/snapshot/queries.ts +136 -0
- package/src/snapshot/validate.ts +1108 -0
- package/src/snapshot/views.ts +943 -0
- package/src/types/builder.ts +480 -0
- package/src/types/columns.ts +727 -0
- package/src/types/index.ts +14 -0
- package/src/types/internal.ts +195 -0
- package/src/types/snapshot.ts +886 -0
- package/src/types/wire.ts +207 -0
- package/src/util/mask.ts +89 -0
- package/src/util/options.ts +57 -0
- package/src/util/shared-buffers.ts +56 -0
- package/src/util/typed-array.ts +371 -0
- package/src/wire/bytes.ts +440 -0
- package/src/wire/carried-views.ts +327 -0
- package/src/wire/from-wire.ts +1690 -0
- package/src/wire/to-wire.ts +755 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GSNP byte container (design section 9.2): `toBytes()` writes one contiguous buffer,
|
|
3
|
+
* `toByteChunks()` the same bytes as a sequence (header + manifest, then every 256-padded segment
|
|
4
|
+
* in manifest order), `fromBytes()` adopts a container's buffer region as the arena and
|
|
5
|
+
* `fromByteChunks()` adopts each chunk's buffer per segment. The snapshot's `toBytes` /
|
|
6
|
+
* `toByteChunks` methods call the functions of this module directly.
|
|
7
|
+
*
|
|
8
|
+
* Layout, all integers little-endian:
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* offset size field
|
|
12
|
+
* 0 4 magic "GSNP"
|
|
13
|
+
* 4 2 wire major (u16)
|
|
14
|
+
* 6 2 wire minor (u16)
|
|
15
|
+
* 8 4 endianness probe: 0x01020304 written through a host-order Uint32Array
|
|
16
|
+
* 12 4 manifest byte length L (u32)
|
|
17
|
+
* 16 L manifest: UTF-8 JSON of the WireManifest, every reference into buffer 0 with a
|
|
18
|
+
* region-relative byteOffset
|
|
19
|
+
* 16+L pad zero padding to the next multiple of 256
|
|
20
|
+
* B ... buffer region: each array at a 256-aligned offset in manifest order, core arrays
|
|
21
|
+
* first so the region's prefix is the arena; every segment padded to 256 bytes
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The reader refuses a bad magic, an unexpected probe, a truncated header or manifest, a manifest
|
|
25
|
+
* whose versions disagree with the header (E_BAD_SERIALIZATION), an unknown wire major
|
|
26
|
+
* (E_UNSUPPORTED_VERSION) and everything the manifest reader of from-wire.ts refuses.
|
|
27
|
+
*/
|
|
28
|
+
import { ALIGNMENT, CONTAINER_MAGIC, ENDIAN_PROBE, IS_LITTLE_ENDIAN, WIRE_MAJOR, WIRE_MINOR } from "../constants.js";
|
|
29
|
+
import { GraphFormatError } from "../errors.js";
|
|
30
|
+
import { alignUp, padTo4 } from "../util/typed-array.js";
|
|
31
|
+
import { badWire, bufferRegion, checkManifestVersions, decodeManifest, isSharedArrayBuffer, parseGuardedJson, resolveFromWireOptions, } from "./from-wire.js";
|
|
32
|
+
import { collectWire, encodeManifest, WireLayout } from "./to-wire.js";
|
|
33
|
+
// ============================================================ constants
|
|
34
|
+
/** Bytes before the manifest: magic, major, minor, probe and manifest length. */
|
|
35
|
+
export const CONTAINER_HEADER_BYTES = 16;
|
|
36
|
+
const fatalDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
37
|
+
/**
|
|
38
|
+
* Lay a snapshot out for the container.
|
|
39
|
+
* @param snapshot - the snapshot
|
|
40
|
+
* @param options - the views to carry
|
|
41
|
+
* @returns the plan
|
|
42
|
+
*/
|
|
43
|
+
function planContainer(snapshot, options) {
|
|
44
|
+
const layout = new WireLayout("container");
|
|
45
|
+
const { manifest } = collectWire(snapshot, layout, options.includeViews, true);
|
|
46
|
+
const manifestBytes = encodeManifest(manifest);
|
|
47
|
+
return {
|
|
48
|
+
manifestBytes,
|
|
49
|
+
regionStart: alignUp(CONTAINER_HEADER_BYTES + manifestBytes.byteLength, ALIGNMENT),
|
|
50
|
+
segments: layout.segments,
|
|
51
|
+
regionLength: layout.regionLength,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Write the 16-byte header into a fresh buffer (design section 9.2).
|
|
56
|
+
* @param out - a Uint8Array at offset 0 of its buffer with at least 16 bytes
|
|
57
|
+
* @param manifestLength - L
|
|
58
|
+
*/
|
|
59
|
+
function writeHeader(out, manifestLength) {
|
|
60
|
+
out.set(CONTAINER_MAGIC, 0);
|
|
61
|
+
const view = new DataView(out.buffer, out.byteOffset, out.byteLength);
|
|
62
|
+
view.setUint16(4, WIRE_MAJOR, true);
|
|
63
|
+
view.setUint16(6, WIRE_MINOR, true);
|
|
64
|
+
new Uint32Array(out.buffer, out.byteOffset + 8, 1)[0] = ENDIAN_PROBE;
|
|
65
|
+
view.setUint32(12, manifestLength, true);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The bytes of a typed array as a Uint8Array view.
|
|
69
|
+
* @param view - the array
|
|
70
|
+
* @returns the byte view
|
|
71
|
+
*/
|
|
72
|
+
function bytesOf(view) {
|
|
73
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The GSNP container of a snapshot as one contiguous buffer (design section 9.2).
|
|
77
|
+
* @param snapshot - the snapshot
|
|
78
|
+
* @param options - the cached views to carry
|
|
79
|
+
* @returns the container bytes at offset 0 of a fresh ArrayBuffer; E_UNSUPPORTED on a big-endian host
|
|
80
|
+
*/
|
|
81
|
+
export function toBytes(snapshot, options = {}) {
|
|
82
|
+
const plan = planContainer(snapshot, options);
|
|
83
|
+
const out = new Uint8Array(plan.regionStart + plan.regionLength);
|
|
84
|
+
writeHeader(out, plan.manifestBytes.byteLength);
|
|
85
|
+
out.set(plan.manifestBytes, CONTAINER_HEADER_BYTES);
|
|
86
|
+
for (const segment of plan.segments) {
|
|
87
|
+
out.set(bytesOf(segment.view), plan.regionStart + segment.ref.byteOffset);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Yield the chunks of a plan: the padded header + manifest, then every non-empty segment padded to
|
|
93
|
+
* 256 bytes.
|
|
94
|
+
* @param plan - the plan
|
|
95
|
+
* @yields the chunks in order
|
|
96
|
+
*/
|
|
97
|
+
function* chunksOf(plan) {
|
|
98
|
+
const head = new Uint8Array(plan.regionStart);
|
|
99
|
+
writeHeader(head, plan.manifestBytes.byteLength);
|
|
100
|
+
head.set(plan.manifestBytes, CONTAINER_HEADER_BYTES);
|
|
101
|
+
yield head;
|
|
102
|
+
for (const segment of plan.segments) {
|
|
103
|
+
if (segment.ref.byteLength === 0) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const chunk = new Uint8Array(alignUp(segment.ref.byteLength, ALIGNMENT));
|
|
107
|
+
chunk.set(bytesOf(segment.view));
|
|
108
|
+
yield chunk;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The GSNP container as a sequence of chunks whose concatenation equals `toBytes()` (design section
|
|
113
|
+
* 9.2): the header + manifest padded to 256, then each non-empty segment padded to 256, in manifest
|
|
114
|
+
* order. The layout is computed when this function is called; the chunk copies are made lazily.
|
|
115
|
+
* @param snapshot - the snapshot
|
|
116
|
+
* @param options - the cached views to carry
|
|
117
|
+
* @returns the chunks; E_UNSUPPORTED on a big-endian host
|
|
118
|
+
*/
|
|
119
|
+
export function toByteChunks(snapshot, options = {}) {
|
|
120
|
+
return chunksOf(planContainer(snapshot, options));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check and read the 16-byte header (design section 9.2).
|
|
124
|
+
* @param head - at least the first 16 bytes of the container
|
|
125
|
+
* @param totalLength - the container's total byte length
|
|
126
|
+
* @returns the header fields
|
|
127
|
+
*/
|
|
128
|
+
function readHeader(head, totalLength) {
|
|
129
|
+
if (totalLength < CONTAINER_HEADER_BYTES) {
|
|
130
|
+
throw badWire("header", `truncated: ${totalLength} bytes, expected at least ${CONTAINER_HEADER_BYTES}`, {
|
|
131
|
+
byteLength: totalLength,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
for (let i = 0; i < CONTAINER_MAGIC.length; i++) {
|
|
135
|
+
if (head[i] !== CONTAINER_MAGIC[i]) {
|
|
136
|
+
throw badWire("magic", "not a GSNP container", { found: Array.from(head.subarray(0, 4)) });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const view = new DataView(head.buffer, head.byteOffset, head.byteLength);
|
|
140
|
+
const major = view.getUint16(4, true);
|
|
141
|
+
const minor = view.getUint16(6, true);
|
|
142
|
+
if (major !== WIRE_MAJOR) {
|
|
143
|
+
throw new GraphFormatError("E_UNSUPPORTED_VERSION", `wire major ${major} is not supported (reader: ${WIRE_MAJOR})`, {
|
|
144
|
+
kind: "wire",
|
|
145
|
+
found: major,
|
|
146
|
+
supported: WIRE_MAJOR,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const probe = view.getUint32(8, IS_LITTLE_ENDIAN);
|
|
150
|
+
if (probe !== ENDIAN_PROBE) {
|
|
151
|
+
throw badWire("endianness", `probe reads 0x${probe.toString(16)}; the container was written on another endianness`, {
|
|
152
|
+
found: probe,
|
|
153
|
+
expected: ENDIAN_PROBE,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const manifestLength = view.getUint32(12, true);
|
|
157
|
+
if (CONTAINER_HEADER_BYTES + manifestLength > totalLength) {
|
|
158
|
+
throw badWire("manifest", `truncated: ${manifestLength} manifest bytes declared, ${totalLength} bytes in total`, {
|
|
159
|
+
manifestLength,
|
|
160
|
+
byteLength: totalLength,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return { major, minor, manifestLength };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Parse the manifest bytes: a fatal UTF-8 decode, the guarding JSON reviver, then the version check
|
|
167
|
+
* against the header.
|
|
168
|
+
* @param bytes - the manifest bytes
|
|
169
|
+
* @param header - the header the manifest must agree with
|
|
170
|
+
* @returns the manifest object
|
|
171
|
+
*/
|
|
172
|
+
function readManifest(bytes, header) {
|
|
173
|
+
let text;
|
|
174
|
+
try {
|
|
175
|
+
text = fatalDecoder.decode(bytes);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
throw badWire("manifest", "not valid UTF-8");
|
|
179
|
+
}
|
|
180
|
+
const manifest = parseGuardedJson(text, "manifest");
|
|
181
|
+
if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
|
|
182
|
+
throw badWire("manifest", "expected an object");
|
|
183
|
+
}
|
|
184
|
+
const record = manifest;
|
|
185
|
+
const [major, minor] = checkManifestVersions(record);
|
|
186
|
+
if (major !== header.major || minor !== header.minor) {
|
|
187
|
+
throw badWire("wire", `manifest says [${major}, ${minor}], the header says [${header.major}, ${header.minor}]`, {
|
|
188
|
+
found: [major, minor],
|
|
189
|
+
header: [header.major, header.minor],
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return record;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Rebuild a snapshot from a GSNP container (design section 9.2). Defaults: `validate: "full"` and
|
|
196
|
+
* `copy: false`. The buffer region is adopted as the arena when the container is a plain
|
|
197
|
+
* ArrayBuffer viewed at a byteOffset that is a multiple of 8 (so f64 segments align); a
|
|
198
|
+
* SharedArrayBuffer, an odd offset or `copy: true` take the copy path into a fresh 256-aligned
|
|
199
|
+
* buffer.
|
|
200
|
+
* @param bytes - the container: a Uint8Array, an ArrayBuffer or a SharedArrayBuffer
|
|
201
|
+
* @param options - validation level, copy and unknown-column policy
|
|
202
|
+
* @returns the snapshot; E_BAD_SERIALIZATION / E_UNSUPPORTED_VERSION / E_UNSUPPORTED / E_INVALID_SNAPSHOT on bad input
|
|
203
|
+
*/
|
|
204
|
+
export function fromBytes(bytes, options) {
|
|
205
|
+
const resolved = resolveFromWireOptions(options, "full");
|
|
206
|
+
const view = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
207
|
+
const header = readHeader(view, view.byteLength);
|
|
208
|
+
const manifest = readManifest(view.subarray(CONTAINER_HEADER_BYTES, CONTAINER_HEADER_BYTES + header.manifestLength), header);
|
|
209
|
+
const regionStart = alignUp(CONTAINER_HEADER_BYTES + header.manifestLength, ALIGNMENT);
|
|
210
|
+
const regionLength = Math.max(0, view.byteLength - regionStart);
|
|
211
|
+
const { buffer } = view;
|
|
212
|
+
let region;
|
|
213
|
+
if (!resolved.copy && !isSharedArrayBuffer(buffer) && view.byteOffset % 8 === 0) {
|
|
214
|
+
region = bufferRegion(buffer, view.byteOffset + regionStart, regionLength);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const copy = new Uint8Array(alignUp(regionLength, ALIGNMENT));
|
|
218
|
+
if (regionLength > 0) {
|
|
219
|
+
copy.set(view.subarray(regionStart));
|
|
220
|
+
}
|
|
221
|
+
region = bufferRegion(copy.buffer, 0, regionLength);
|
|
222
|
+
}
|
|
223
|
+
return decodeManifest(manifest, [region], resolved, true);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* A byte stream made of chunks, addressed by absolute offset: ranges inside one chunk are located
|
|
227
|
+
* for adoption, ranges spanning chunks are copied.
|
|
228
|
+
*/
|
|
229
|
+
class ChunkedBytes {
|
|
230
|
+
/**
|
|
231
|
+
* Wrap the chunks.
|
|
232
|
+
* @param chunks - the chunks in order
|
|
233
|
+
*/
|
|
234
|
+
constructor(chunks) {
|
|
235
|
+
this.chunks = chunks;
|
|
236
|
+
this.starts = [];
|
|
237
|
+
let total = 0;
|
|
238
|
+
for (const chunk of chunks) {
|
|
239
|
+
this.starts.push(total);
|
|
240
|
+
total += chunk.byteLength;
|
|
241
|
+
}
|
|
242
|
+
this.byteLength = total;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The chunk index holding an absolute offset (the last chunk starting at or before it).
|
|
246
|
+
* @param offset - the absolute offset
|
|
247
|
+
* @returns the index, or -1 when there is no chunk
|
|
248
|
+
*/
|
|
249
|
+
chunkAt(offset) {
|
|
250
|
+
let lo = 0;
|
|
251
|
+
let hi = this.starts.length - 1;
|
|
252
|
+
let found = -1;
|
|
253
|
+
while (lo <= hi) {
|
|
254
|
+
const mid = (lo + hi) >>> 1;
|
|
255
|
+
if (this.starts[mid] <= offset) {
|
|
256
|
+
found = mid;
|
|
257
|
+
lo = mid + 1;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
hi = mid - 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return found;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Find a range inside one chunk over a plain ArrayBuffer.
|
|
267
|
+
* @param offset - the absolute start
|
|
268
|
+
* @param length - the byte length
|
|
269
|
+
* @returns the buffer and absolute offset, or null when the range spans chunks or a SharedArrayBuffer
|
|
270
|
+
*/
|
|
271
|
+
locate(offset, length) {
|
|
272
|
+
const i = this.chunkAt(offset);
|
|
273
|
+
if (i < 0) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const chunk = this.chunks[i];
|
|
277
|
+
const start = this.starts[i];
|
|
278
|
+
if (offset + length > start + chunk.byteLength || isSharedArrayBuffer(chunk.buffer)) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
return { buffer: chunk.buffer, byteOffset: chunk.byteOffset + (offset - start) };
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Copy a range out of the stream.
|
|
285
|
+
* @param offset - the absolute start
|
|
286
|
+
* @param length - the byte length
|
|
287
|
+
* @returns a fresh Uint8Array of `length` bytes at offset 0 of a padded buffer
|
|
288
|
+
*/
|
|
289
|
+
read(offset, length) {
|
|
290
|
+
if (offset + length > this.byteLength) {
|
|
291
|
+
throw badWire("chunks", `range [${offset}, ${offset + length}) exceeds the ${this.byteLength} bytes given`);
|
|
292
|
+
}
|
|
293
|
+
const out = new Uint8Array(new ArrayBuffer(padTo4(length)), 0, length);
|
|
294
|
+
let written = 0;
|
|
295
|
+
let i = this.chunkAt(offset);
|
|
296
|
+
while (written < length && i < this.chunks.length) {
|
|
297
|
+
const chunk = this.chunks[i];
|
|
298
|
+
const start = this.starts[i];
|
|
299
|
+
const from = offset + written - start;
|
|
300
|
+
const take = Math.min(length - written, chunk.byteLength - from);
|
|
301
|
+
out.set(chunk.subarray(from, from + take), written);
|
|
302
|
+
written += take;
|
|
303
|
+
i++;
|
|
304
|
+
}
|
|
305
|
+
return out;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A view when the range lies inside one chunk, a copy otherwise.
|
|
309
|
+
* @param offset - the absolute start
|
|
310
|
+
* @param length - the byte length
|
|
311
|
+
* @returns the bytes
|
|
312
|
+
*/
|
|
313
|
+
span(offset, length) {
|
|
314
|
+
const i = this.chunkAt(offset);
|
|
315
|
+
if (i >= 0) {
|
|
316
|
+
const chunk = this.chunks[i];
|
|
317
|
+
const start = this.starts[i];
|
|
318
|
+
if (offset + length <= start + chunk.byteLength) {
|
|
319
|
+
return chunk.subarray(offset - start, offset - start + length);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return this.read(offset, length);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The stream from `base` onward as a decoder region.
|
|
326
|
+
* @param base - the absolute offset of the region's start
|
|
327
|
+
* @returns the region
|
|
328
|
+
*/
|
|
329
|
+
region(base) {
|
|
330
|
+
return {
|
|
331
|
+
byteLength: Math.max(0, this.byteLength - base),
|
|
332
|
+
locate: (byteOffset, byteLength) => this.locate(base + byteOffset, byteLength),
|
|
333
|
+
read: (byteOffset, byteLength) => this.read(base + byteOffset, byteLength),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Rebuild a snapshot from the chunks `toByteChunks()` produced (or any split of a container's
|
|
339
|
+
* bytes): each segment is adopted as a view into the chunk that holds it (a segment spanning two
|
|
340
|
+
* chunks, or one in a SharedArrayBuffer, is copied) and the snapshot has `arena === null` (design
|
|
341
|
+
* section 9.2). Defaults: `validate: "full"`, `copy: false`.
|
|
342
|
+
* @param chunks - the chunks in order
|
|
343
|
+
* @param options - validation level, copy and unknown-column policy
|
|
344
|
+
* @returns the snapshot
|
|
345
|
+
*/
|
|
346
|
+
export function fromByteChunks(chunks, options) {
|
|
347
|
+
const resolved = resolveFromWireOptions(options, "full");
|
|
348
|
+
const list = [];
|
|
349
|
+
for (const chunk of chunks) {
|
|
350
|
+
if (!(chunk instanceof Uint8Array)) {
|
|
351
|
+
throw badWire(`chunks[${list.length}]`, "expected a Uint8Array");
|
|
352
|
+
}
|
|
353
|
+
list.push(resolved.copy ? chunk.slice() : chunk);
|
|
354
|
+
}
|
|
355
|
+
const bytes = new ChunkedBytes(list);
|
|
356
|
+
const header = readHeader(bytes.span(0, Math.min(CONTAINER_HEADER_BYTES, bytes.byteLength)), bytes.byteLength);
|
|
357
|
+
const manifest = readManifest(bytes.span(CONTAINER_HEADER_BYTES, header.manifestLength), header);
|
|
358
|
+
const regionStart = alignUp(CONTAINER_HEADER_BYTES + header.manifestLength, ALIGNMENT);
|
|
359
|
+
return decodeManifest(manifest, [bytes.region(regionStart)], resolved, false);
|
|
360
|
+
}
|
|
361
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src/wire/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EACH,OAAO,EACP,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EAEnB,gBAAgB,EAChB,sBAAsB,GAEzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAyB,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE9F,yEAAyE;AAEzE,iFAAiF;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC,MAAM,YAAY,GAAG,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CAAC;QACD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/G,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;IACjG,MAAM,WAAW,GAAG,OAAO,CAAC,sBAAsB,GAAG,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IACvF,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 { type GraphSnapshot } from "../snapshot/graph-snapshot.js";
|
|
12
|
+
import { type F32, type F64, type ReverseView, type U32 } from "../types/index.js";
|
|
13
|
+
/** The per-arc facts every index-view check reads, computed once per manifest. */
|
|
14
|
+
export declare class CoreFacts {
|
|
15
|
+
/** The row (source) of every arc. */
|
|
16
|
+
readonly arcRow: U32;
|
|
17
|
+
/** Loop arcs per node. */
|
|
18
|
+
readonly loops: U32;
|
|
19
|
+
/** In-arcs per node (directed only; the out-degree when undirected). */
|
|
20
|
+
readonly inDegree: U32;
|
|
21
|
+
/**
|
|
22
|
+
* Expand the core once.
|
|
23
|
+
* @param snapshot - the snapshot
|
|
24
|
+
*/
|
|
25
|
+
constructor(snapshot: GraphSnapshot);
|
|
26
|
+
/**
|
|
27
|
+
* The exclusive prefix sum of the in-degrees (the reverse rowPtr).
|
|
28
|
+
* @returns nodeCount + 1 offsets
|
|
29
|
+
*/
|
|
30
|
+
inDegreePrefix(): U32;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* outDegree: the row lengths.
|
|
34
|
+
* @param snapshot - the snapshot
|
|
35
|
+
* @param data - the carried array
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkOutDegree(snapshot: GraphSnapshot, data: U32): void;
|
|
38
|
+
/**
|
|
39
|
+
* inDegree (directed): the in-arc counts.
|
|
40
|
+
* @param facts - the core facts
|
|
41
|
+
* @param data - the carried array
|
|
42
|
+
*/
|
|
43
|
+
export declare function checkInDegree(facts: CoreFacts, data: U32): void;
|
|
44
|
+
/**
|
|
45
|
+
* degree: outDegree + inDegree (directed) or outDegree + loops (undirected), design section 3.4.
|
|
46
|
+
* @param snapshot - the snapshot
|
|
47
|
+
* @param facts - the core facts
|
|
48
|
+
* @param data - the carried array
|
|
49
|
+
*/
|
|
50
|
+
export declare function checkDegree(snapshot: GraphSnapshot, facts: CoreFacts, data: U32): void;
|
|
51
|
+
/**
|
|
52
|
+
* selfLoopsPerNode: the loop arcs per row.
|
|
53
|
+
* @param facts - the core facts
|
|
54
|
+
* @param data - the carried array
|
|
55
|
+
*/
|
|
56
|
+
export declare function checkSelfLoopsPerNode(facts: CoreFacts, data: U32): void;
|
|
57
|
+
/**
|
|
58
|
+
* selfLoopArcs: ascending arcs, each a loop; with the length fixed to selfLoopCount that is exact.
|
|
59
|
+
* @param snapshot - the snapshot
|
|
60
|
+
* @param facts - the core facts
|
|
61
|
+
* @param data - the carried array
|
|
62
|
+
*/
|
|
63
|
+
export declare function checkSelfLoopArcs(snapshot: GraphSnapshot, facts: CoreFacts, data: U32): void;
|
|
64
|
+
/**
|
|
65
|
+
* coo.src: the row of every arc.
|
|
66
|
+
* @param facts - the core facts
|
|
67
|
+
* @param src - the carried array
|
|
68
|
+
*/
|
|
69
|
+
export declare function checkCooSrc(facts: CoreFacts, src: U32): void;
|
|
70
|
+
/**
|
|
71
|
+
* edgeList: `src[e]` is the row of `edgeToArc[e]`, `dst[e]` its target, `weights[e]` its weight.
|
|
72
|
+
* @param snapshot - the snapshot
|
|
73
|
+
* @param facts - the core facts
|
|
74
|
+
* @param src - the carried sources
|
|
75
|
+
* @param dst - the carried targets, or null when colIdx is aliased
|
|
76
|
+
* @param weights - the carried weights, or null when aliased or unweighted
|
|
77
|
+
*/
|
|
78
|
+
export declare function checkEdgeList(snapshot: GraphSnapshot, facts: CoreFacts, src: U32, dst: U32 | null, weights: F32 | null): void;
|
|
79
|
+
/**
|
|
80
|
+
* mate (undirected): an involution pairing the two arcs of every non-loop edge (invariant I7) and
|
|
81
|
+
* fixing every loop arc.
|
|
82
|
+
* @param snapshot - the snapshot
|
|
83
|
+
* @param facts - the core facts
|
|
84
|
+
* @param mate - the carried array
|
|
85
|
+
*/
|
|
86
|
+
export declare function checkMate(snapshot: GraphSnapshot, facts: CoreFacts, mate: U32): void;
|
|
87
|
+
/**
|
|
88
|
+
* degreeOrder / reverseDegreeOrder: a permutation ordered by non-increasing degree with ties in
|
|
89
|
+
* ascending node index, and the cuGraph tier offsets of design section 7.2.
|
|
90
|
+
* @param name - the view name
|
|
91
|
+
* @param degree - the degree of every node the order sorts by
|
|
92
|
+
* @param perm - the carried permutation
|
|
93
|
+
* @param segmentOffsets - the carried tier offsets
|
|
94
|
+
*/
|
|
95
|
+
export declare function checkDegreeOrder(name: "degreeOrder" | "reverseDegreeOrder", degree: U32, perm: U32, segmentOffsets: U32): void;
|
|
96
|
+
/**
|
|
97
|
+
* reverse (directed): the in-adjacency with rows sorted by source and ties by forward arc, `fwdArc`
|
|
98
|
+
* a permutation of the arcs, `colIdx` the sources, `weights` the forward weights gathered.
|
|
99
|
+
* @param snapshot - the snapshot
|
|
100
|
+
* @param facts - the core facts
|
|
101
|
+
* @param reverse - the carried view
|
|
102
|
+
*/
|
|
103
|
+
export declare function checkReverse(snapshot: GraphSnapshot, facts: CoreFacts, reverse: ReverseView): void;
|
|
104
|
+
/**
|
|
105
|
+
* An f64 view: compared with the snapshot's own computation.
|
|
106
|
+
* @param name - the view name
|
|
107
|
+
* @param found - the carried array
|
|
108
|
+
* @param expected - the computed truth
|
|
109
|
+
*/
|
|
110
|
+
export declare function checkF64View(name: string, found: F64, expected: F64): void;
|
|
111
|
+
//# sourceMappingURL=carried-views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carried-views.d.ts","sourceRoot":"","sources":["../../../src/wire/carried-views.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEnF,kFAAkF;AAClF,qBAAa,SAAS;IAClB,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC;IACpB,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,GAAG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