@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,480 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The builder surface (design sections 6, 8.3 and 12.2): options, freeze options and report, the
|
|
3
|
+
* branded handles, the GraphSink contract importers program against, and the GraphBuilder contract.
|
|
4
|
+
*
|
|
5
|
+
* GraphBuilderContract is the instance contract of the GraphBuilder class implemented in
|
|
6
|
+
* src/builder/graph-builder.ts, which adds `constructor(options)` and `static from(snapshot,
|
|
7
|
+
* options?)` (design section 12.2). The public name GraphBuilder is the class itself, exported by
|
|
8
|
+
* the barrel; nothing on this surface needs to name it (the factories return GraphSnapshot).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
type ColumnDecl,
|
|
13
|
+
type ColumnDeclPatch,
|
|
14
|
+
type ColumnDomain,
|
|
15
|
+
type Dtype,
|
|
16
|
+
type DuplicatePolicy,
|
|
17
|
+
type F32,
|
|
18
|
+
type F64,
|
|
19
|
+
type GraphMetaPatch,
|
|
20
|
+
type Loose,
|
|
21
|
+
type NodeId,
|
|
22
|
+
type TypedArrayData,
|
|
23
|
+
type U32,
|
|
24
|
+
} from "./columns.js";
|
|
25
|
+
import { type GraphSnapshot, type ViewName } from "./snapshot.js";
|
|
26
|
+
|
|
27
|
+
/** Constructor options of GraphBuilder (design sections 3.6, 3.7, 6.5 and 12.2). */
|
|
28
|
+
export interface GraphBuilderOptions {
|
|
29
|
+
/** REQUIRED; no default; changeable later via setDirected() (design section 6.6). */
|
|
30
|
+
directed: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Default "auto": weighted if any addEdge supplied a weight; true allocates the array even when every value is 1.
|
|
33
|
+
*/
|
|
34
|
+
weighted?: boolean | "auto" | undefined;
|
|
35
|
+
/** Staging precision; default "f32" (design section 3.7); importers pass "f64". */
|
|
36
|
+
weightDtype?: "f32" | "f64" | undefined;
|
|
37
|
+
/** Default "keep". */
|
|
38
|
+
duplicateEdges?: DuplicatePolicy | undefined;
|
|
39
|
+
/** Default "keep". */
|
|
40
|
+
selfLoops?: "keep" | "drop" | "error" | undefined;
|
|
41
|
+
/** Default true: addEdge creates unknown endpoints; false throws E_UNKNOWN_NODE. */
|
|
42
|
+
addMissingNodes?: boolean | undefined;
|
|
43
|
+
/** Staging capacity hint. */
|
|
44
|
+
expectedNodes?: number | undefined;
|
|
45
|
+
/** Staging capacity hint. */
|
|
46
|
+
expectedEdges?: number | undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Patch form of GraphBuilderOptions, accepted by the factories and by GraphBuilder.from(). */
|
|
50
|
+
export type BuilderOptionsPatch = Loose<GraphBuilderOptions>;
|
|
51
|
+
|
|
52
|
+
/** The builder's options after defaults were applied; the same shape under every compiler flag. */
|
|
53
|
+
export interface ResolvedBuilderOptions {
|
|
54
|
+
/** The CURRENT value (setDirected() updates it). */
|
|
55
|
+
readonly directed: boolean;
|
|
56
|
+
/** The weighted policy. */
|
|
57
|
+
readonly weighted: boolean | "auto";
|
|
58
|
+
/** The staging weight precision. */
|
|
59
|
+
readonly weightDtype: "f32" | "f64";
|
|
60
|
+
/** The default duplicate policy of freeze(). */
|
|
61
|
+
readonly duplicateEdges: DuplicatePolicy;
|
|
62
|
+
/** The self-loop policy. */
|
|
63
|
+
readonly selfLoops: "keep" | "drop" | "error";
|
|
64
|
+
/** Whether addEdge creates unknown endpoints. */
|
|
65
|
+
readonly addMissingNodes: boolean;
|
|
66
|
+
/** Capacity hint, or null. */
|
|
67
|
+
readonly expectedNodes: number | null;
|
|
68
|
+
/** Capacity hint, or null. */
|
|
69
|
+
readonly expectedEdges: number | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Options of freeze() and freezeWithReport() (design section 6.7). */
|
|
73
|
+
export interface FreezeOptions {
|
|
74
|
+
/** Debugging label carried by the snapshot. */
|
|
75
|
+
label?: string | undefined;
|
|
76
|
+
/** Views computed eagerly inside freeze. */
|
|
77
|
+
prepare?: readonly ViewName[] | undefined;
|
|
78
|
+
/** Default true: core arrays share one 256-aligned arena (design section 10.3). */
|
|
79
|
+
arena?: boolean | undefined;
|
|
80
|
+
/** Default false; true empties staging after freezing (Arrow flush semantics). */
|
|
81
|
+
release?: boolean | undefined;
|
|
82
|
+
/** Overrides the builder default for this freeze; a merge policy REWRITES THE BUILDER (design section 6.5). */
|
|
83
|
+
duplicateEdges?: DuplicatePolicy | undefined;
|
|
84
|
+
/** Fills FreezeReport.timings. */
|
|
85
|
+
profile?: boolean | undefined;
|
|
86
|
+
/** Records FNV-1a checksums for validate({ checksum: true }) (design section 5.8). */
|
|
87
|
+
checksum?: boolean | undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* What freezeWithReport() returns next to the snapshot (design sections 4.4 and 6.6). The remaps
|
|
92
|
+
* are relative to the previous freeze of the same builder, or to the builder's own index space on
|
|
93
|
+
* the first freeze (invariant I16); each is null exactly when nothing was renumbered, and the two
|
|
94
|
+
* are independent.
|
|
95
|
+
*/
|
|
96
|
+
export interface FreezeReport {
|
|
97
|
+
/** Previous freeze's node index space -> new index or INVALID_INDEX; null when nodes were not renumbered (I16). */
|
|
98
|
+
readonly nodeRemap: U32 | null;
|
|
99
|
+
/** Same for edges (a merged edge: its survivor); null when edges were not renumbered; independent of nodeRemap. */
|
|
100
|
+
readonly edgeRemap: U32 | null;
|
|
101
|
+
/** Whether step 1 of the freeze pipeline compacted tombstones. */
|
|
102
|
+
readonly compacted: boolean;
|
|
103
|
+
/** Self-loops removed under selfLoops "drop". */
|
|
104
|
+
readonly droppedSelfLoops: number;
|
|
105
|
+
/** Parallel edges collapsed by duplicateEdges. */
|
|
106
|
+
readonly mergedEdges: number;
|
|
107
|
+
/** Tombstoned + dropped loops + merged. */
|
|
108
|
+
readonly droppedEdges: number;
|
|
109
|
+
/** Columns whose inferred dtype widened during staging (design section 5.1), so importers can fix headers. */
|
|
110
|
+
readonly widened: readonly {
|
|
111
|
+
readonly column: string;
|
|
112
|
+
readonly domain: ColumnDomain;
|
|
113
|
+
readonly from: Dtype;
|
|
114
|
+
readonly to: Dtype;
|
|
115
|
+
}[];
|
|
116
|
+
/** ms per phase; empty unless profile. */
|
|
117
|
+
readonly timings: Readonly<Record<string, number>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Branded index into the builder's column list for its domain; INVALID_INDEX when absent (design
|
|
122
|
+
* section 12.1). Handles never come out of a typed array, and the brand stops
|
|
123
|
+
* setNodeValue(index, handle, v) with the arguments swapped from type-checking.
|
|
124
|
+
*/
|
|
125
|
+
export type ColumnHandle = number & { readonly __brand: "ColumnHandle" };
|
|
126
|
+
|
|
127
|
+
/** Branded index of an extension table in the builder (design section 5.10). */
|
|
128
|
+
export type ExtensionHandle = number & { readonly __brand: "ExtensionHandle" };
|
|
129
|
+
|
|
130
|
+
/** Options of setDirected() (design section 6.6). */
|
|
131
|
+
export interface SetDirectedOptions {
|
|
132
|
+
/**
|
|
133
|
+
* Convert a non-empty undirected builder to directed by appending a mirror edge per existing edge and writing the
|
|
134
|
+
* graphty.directed / graphty.pair columns (design section 3.6).
|
|
135
|
+
*/
|
|
136
|
+
readonly expand?: boolean | undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The subset of GraphBuilder that importers may call (design section 8.3). Importers push scalars,
|
|
141
|
+
* never objects; the record methods exist for the transitional element path and JSON. GraphBuilder
|
|
142
|
+
* implements it, and tests can pass a recording sink.
|
|
143
|
+
*/
|
|
144
|
+
export interface GraphSink {
|
|
145
|
+
/** The resolved options; `directed` is the current value. */
|
|
146
|
+
readonly options: ResolvedBuilderOptions;
|
|
147
|
+
/** The current direction. */
|
|
148
|
+
readonly directed: boolean;
|
|
149
|
+
/** Whether lockDirected() was called. */
|
|
150
|
+
readonly directedLocked: boolean;
|
|
151
|
+
/** Live edge count. */
|
|
152
|
+
readonly edgeCount: number;
|
|
153
|
+
/**
|
|
154
|
+
* Change the direction (design section 6.6): free while the builder holds no edges; with edges,
|
|
155
|
+
* only undirected -> directed with expand. E_DIRECTED when refused or locked.
|
|
156
|
+
* @param directed - the new value
|
|
157
|
+
* @param options - expansion of an undirected builder
|
|
158
|
+
*/
|
|
159
|
+
setDirected(directed: boolean, options?: SetDirectedOptions): void;
|
|
160
|
+
/**
|
|
161
|
+
* Grow staging capacity ahead of a bulk push.
|
|
162
|
+
* @param nodes - expected node count
|
|
163
|
+
* @param edges - expected edge count
|
|
164
|
+
*/
|
|
165
|
+
reserve(nodes?: number, edges?: number): void;
|
|
166
|
+
/**
|
|
167
|
+
* Add a node or return the index of an existing live one (idempotent); revives a tombstoned id before the next
|
|
168
|
+
* freeze.
|
|
169
|
+
* @param id - the node id; E_INVALID_ID when not a legal id
|
|
170
|
+
* @returns the node index
|
|
171
|
+
*/
|
|
172
|
+
addNode(id: NodeId): number;
|
|
173
|
+
/**
|
|
174
|
+
* Add many nodes.
|
|
175
|
+
* @param ids - the node ids
|
|
176
|
+
* @param out - receives the index of every id (allocated when omitted)
|
|
177
|
+
* @returns `out`
|
|
178
|
+
*/
|
|
179
|
+
addNodes(ids: Iterable<NodeId>, out?: U32): U32;
|
|
180
|
+
/**
|
|
181
|
+
* Add a logical edge; unknown endpoints are created when addMissingNodes is true, else E_UNKNOWN_NODE. NaN weight
|
|
182
|
+
* is E_INVALID_WEIGHT.
|
|
183
|
+
* @param source - source node id
|
|
184
|
+
* @param target - target node id
|
|
185
|
+
* @param weight - the weight; 1 when omitted
|
|
186
|
+
* @returns the logical edge index
|
|
187
|
+
*/
|
|
188
|
+
addEdge(source: NodeId, target: NodeId, weight?: number): number;
|
|
189
|
+
/**
|
|
190
|
+
* Bulk add edges by node index (the index-space path used with addAnonymousNodes).
|
|
191
|
+
* @param src - source node indices
|
|
192
|
+
* @param dst - target node indices
|
|
193
|
+
* @param weights - per-edge weights; 1 when omitted
|
|
194
|
+
* @returns the first new logical edge index
|
|
195
|
+
*/
|
|
196
|
+
addEdges(src: U32, dst: U32, weights?: F32 | F64): number;
|
|
197
|
+
/**
|
|
198
|
+
* Set the weight of a live edge (allocates the weight array on first use).
|
|
199
|
+
* @param edge - the logical edge index
|
|
200
|
+
* @param weight - the weight; E_INVALID_WEIGHT for NaN
|
|
201
|
+
*/
|
|
202
|
+
setEdgeWeight(edge: number, weight: number): void;
|
|
203
|
+
/**
|
|
204
|
+
* Read a live edge's endpoints back.
|
|
205
|
+
* @param edge - the logical edge index
|
|
206
|
+
* @returns [source index, target index] in declared orientation
|
|
207
|
+
*/
|
|
208
|
+
edgeEndpoints(edge: number): readonly [source: number, target: number];
|
|
209
|
+
/**
|
|
210
|
+
* Read a live edge's weight back.
|
|
211
|
+
* @param edge - the logical edge index
|
|
212
|
+
* @returns the weight (1 when unweighted)
|
|
213
|
+
*/
|
|
214
|
+
edgeWeight(edge: number): number;
|
|
215
|
+
/**
|
|
216
|
+
* Total lookup of a live node by id.
|
|
217
|
+
* @param id - the node id
|
|
218
|
+
* @returns the node index, or INVALID_INDEX
|
|
219
|
+
*/
|
|
220
|
+
indexOf(id: NodeId): number;
|
|
221
|
+
/**
|
|
222
|
+
* Declare a node column; the same declaration again returns the existing handle, a different one is
|
|
223
|
+
* E_COLUMN_EXISTS.
|
|
224
|
+
* @param decl - the declaration
|
|
225
|
+
* @returns the column handle
|
|
226
|
+
*/
|
|
227
|
+
declareNodeColumn(decl: ColumnDecl): ColumnHandle;
|
|
228
|
+
/**
|
|
229
|
+
* Declare an edge column; the same declaration again returns the existing handle, a different one is
|
|
230
|
+
* E_COLUMN_EXISTS.
|
|
231
|
+
* @param decl - the declaration
|
|
232
|
+
* @returns the column handle
|
|
233
|
+
*/
|
|
234
|
+
declareEdgeColumn(decl: ColumnDecl): ColumnHandle;
|
|
235
|
+
/**
|
|
236
|
+
* Look up a node column handle.
|
|
237
|
+
* @param name - the column name
|
|
238
|
+
* @returns the handle, or INVALID_INDEX when absent
|
|
239
|
+
*/
|
|
240
|
+
nodeColumn(name: string): ColumnHandle;
|
|
241
|
+
/**
|
|
242
|
+
* Look up an edge column handle.
|
|
243
|
+
* @param name - the column name
|
|
244
|
+
* @returns the handle, or INVALID_INDEX when absent
|
|
245
|
+
*/
|
|
246
|
+
edgeColumn(name: string): ColumnHandle;
|
|
247
|
+
/**
|
|
248
|
+
* Widen an inferred node column to a wider dtype of the design section 5.1 order without
|
|
249
|
+
* changing any value (a text importer that knows from the lexical grammar that `2.0` cells
|
|
250
|
+
* are f64 although every value so far was integral). Optional: a sink without it makes such an
|
|
251
|
+
* importer report the dtype it could not widen.
|
|
252
|
+
* @param column - the handle or name
|
|
253
|
+
* @param dtype - the dtype to widen to
|
|
254
|
+
*/
|
|
255
|
+
widenNodeColumn?(column: ColumnHandle | string, dtype: Dtype): void;
|
|
256
|
+
/**
|
|
257
|
+
* Widen an inferred edge column; see widenNodeColumn().
|
|
258
|
+
* @param column - the handle or name
|
|
259
|
+
* @param dtype - the dtype to widen to
|
|
260
|
+
*/
|
|
261
|
+
widenEdgeColumn?(column: ColumnHandle | string, dtype: Dtype): void;
|
|
262
|
+
/**
|
|
263
|
+
* Set one node cell; a string column name auto-declares with inference (design section 5.1).
|
|
264
|
+
* @param column - the handle or name
|
|
265
|
+
* @param index - the node index
|
|
266
|
+
* @param value - the value
|
|
267
|
+
*/
|
|
268
|
+
setNodeValue(column: ColumnHandle | string, index: number, value: unknown): void;
|
|
269
|
+
/**
|
|
270
|
+
* Set one edge cell; a string column name auto-declares with inference.
|
|
271
|
+
* @param column - the handle or name
|
|
272
|
+
* @param edge - the logical edge index
|
|
273
|
+
* @param value - the value
|
|
274
|
+
*/
|
|
275
|
+
setEdgeValue(column: ColumnHandle | string, edge: number, value: unknown): void;
|
|
276
|
+
/**
|
|
277
|
+
* Set a graph-level attribute (the graph table's single row).
|
|
278
|
+
* @param name - the column name
|
|
279
|
+
* @param value - the value
|
|
280
|
+
* @param decl - declaration fields for a new column
|
|
281
|
+
*/
|
|
282
|
+
setGraphValue(name: string, value: unknown, decl?: ColumnDeclPatch): void;
|
|
283
|
+
/**
|
|
284
|
+
* Merge fields into the graph metadata; non-JSON extra values are E_COLUMN_TYPE.
|
|
285
|
+
* @param meta - the fields to set
|
|
286
|
+
*/
|
|
287
|
+
setMeta(meta: GraphMetaPatch): void;
|
|
288
|
+
/**
|
|
289
|
+
* Create an extension table (design section 5.10).
|
|
290
|
+
* @param name - the table name, e.g. "temporal:node:price"
|
|
291
|
+
* @param decls - its columns
|
|
292
|
+
* @returns the table handle
|
|
293
|
+
*/
|
|
294
|
+
addExtensionTable(name: string, decls: readonly ColumnDecl[]): ExtensionHandle;
|
|
295
|
+
/**
|
|
296
|
+
* Append a row to an extension table.
|
|
297
|
+
* @param table - the table handle
|
|
298
|
+
* @param values - one value per declared column
|
|
299
|
+
* @returns the new row index
|
|
300
|
+
*/
|
|
301
|
+
addExtensionRow(table: ExtensionHandle, values: readonly unknown[]): number;
|
|
302
|
+
/**
|
|
303
|
+
* Add a node from a record; on an existing live id every key present overwrites that row (last-write-wins per
|
|
304
|
+
* attribute).
|
|
305
|
+
* @param id - the node id
|
|
306
|
+
* @param attrs - attribute values keyed by column name
|
|
307
|
+
* @returns the node index
|
|
308
|
+
*/
|
|
309
|
+
addNodeRecord(id: NodeId, attrs: Readonly<Record<string, unknown>>): number;
|
|
310
|
+
/**
|
|
311
|
+
* Add an edge from a record; always creates a new edge (parallels are kept).
|
|
312
|
+
* @param source - source node id
|
|
313
|
+
* @param target - target node id
|
|
314
|
+
* @param attrs - attribute values keyed by column name
|
|
315
|
+
* @param weightKey - the key holding the weight; default "weight"; null = no weight
|
|
316
|
+
* @returns the logical edge index
|
|
317
|
+
*/
|
|
318
|
+
addEdgeRecord(
|
|
319
|
+
source: NodeId,
|
|
320
|
+
target: NodeId,
|
|
321
|
+
attrs: Readonly<Record<string, unknown>>,
|
|
322
|
+
weightKey?: string | null,
|
|
323
|
+
): number;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The only mutable object in the package and the producer of snapshots (design section 6): a
|
|
328
|
+
* long-lived, structure-of-arrays accumulator that can be frozen repeatedly. freeze() never shares
|
|
329
|
+
* core arrays or columns with the snapshot it returns (invariant I18; the id Map and ids array are
|
|
330
|
+
* shared by design), is deterministic (I15), and preserves index prefixes between freezes with only
|
|
331
|
+
* appends in between (I16). Indices are never reused while the builder lives except through a
|
|
332
|
+
* compacting freeze, after which builder indices equal the new snapshot's (decision C7).
|
|
333
|
+
*
|
|
334
|
+
* Instance contract of the GraphBuilder class in src/builder/graph-builder.ts, which implements it
|
|
335
|
+
* and adds `constructor(options: GraphBuilderOptions)` and `static from(snapshot, options?)`; the
|
|
336
|
+
* public barrel exports the class and every public type names the class.
|
|
337
|
+
*/
|
|
338
|
+
export interface GraphBuilderContract extends GraphSink {
|
|
339
|
+
/** Live node count. */
|
|
340
|
+
readonly nodeCount: number;
|
|
341
|
+
/** Next node index to be assigned. */
|
|
342
|
+
readonly nodeBound: number;
|
|
343
|
+
/** Next logical edge index to be assigned. */
|
|
344
|
+
readonly edgeBound: number;
|
|
345
|
+
/** Increments on every topology or weight mutation; column writes and freeze() do not count. */
|
|
346
|
+
readonly mutationCount: number;
|
|
347
|
+
/** Mutated since the last freeze(). */
|
|
348
|
+
readonly dirty: boolean;
|
|
349
|
+
/** Fix the direction so importers cannot change it; every later changing setDirected() is E_DIRECTED. */
|
|
350
|
+
lockDirected(): void;
|
|
351
|
+
// nodes
|
|
352
|
+
/**
|
|
353
|
+
* Append nodes whose ids are their own indices, never touching the id Map while every node is anonymous.
|
|
354
|
+
* @param count - how many
|
|
355
|
+
* @returns the first new index
|
|
356
|
+
*/
|
|
357
|
+
addAnonymousNodes(count: number): number;
|
|
358
|
+
/**
|
|
359
|
+
* Whether a live node has this id.
|
|
360
|
+
* @param id - the node id
|
|
361
|
+
* @returns true when present and alive
|
|
362
|
+
*/
|
|
363
|
+
hasNode(id: NodeId): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* The id of a live node index.
|
|
366
|
+
* @param index - the node index
|
|
367
|
+
* @returns the id; E_INDEX_RANGE when out of range or dead
|
|
368
|
+
*/
|
|
369
|
+
idOf(index: number): NodeId;
|
|
370
|
+
/**
|
|
371
|
+
* Tombstone a node and every live incident edge (both directions); O(degree); bumps mutationCount.
|
|
372
|
+
* @param id - the node id
|
|
373
|
+
* @returns the removed live incident edge indices
|
|
374
|
+
*/
|
|
375
|
+
removeNode(id: NodeId): U32;
|
|
376
|
+
/**
|
|
377
|
+
* Tombstone a node by index and every live incident edge.
|
|
378
|
+
* @param index - the node index
|
|
379
|
+
* @returns the removed live incident edge indices
|
|
380
|
+
*/
|
|
381
|
+
removeNodeByIndex(index: number): U32;
|
|
382
|
+
// edges
|
|
383
|
+
/**
|
|
384
|
+
* Add a logical edge by node index; E_UNKNOWN_NODE (details.index) for a dead or out-of-range index.
|
|
385
|
+
* @param u - source node index
|
|
386
|
+
* @param v - target node index
|
|
387
|
+
* @param weight - the weight; 1 when omitted
|
|
388
|
+
* @returns the logical edge index
|
|
389
|
+
*/
|
|
390
|
+
addEdgeByIndex(u: number, v: number, weight?: number): number;
|
|
391
|
+
/**
|
|
392
|
+
* Bulk add edges by id.
|
|
393
|
+
* @param src - source node ids
|
|
394
|
+
* @param dst - target node ids
|
|
395
|
+
* @param weights - per-edge weights; 1 when omitted
|
|
396
|
+
* @returns the first new logical edge index
|
|
397
|
+
*/
|
|
398
|
+
addEdgesByIds(src: ArrayLike<NodeId>, dst: ArrayLike<NodeId>, weights?: ArrayLike<number>): number;
|
|
399
|
+
/**
|
|
400
|
+
* Tombstone an edge; O(1); bumps mutationCount.
|
|
401
|
+
* @param edge - the logical edge index
|
|
402
|
+
* @returns true when a live edge was removed
|
|
403
|
+
*/
|
|
404
|
+
removeEdge(edge: number): boolean;
|
|
405
|
+
/**
|
|
406
|
+
* Whether an edge index is live.
|
|
407
|
+
* @param edge - the logical edge index
|
|
408
|
+
* @returns true when live
|
|
409
|
+
*/
|
|
410
|
+
hasEdge(edge: number): boolean;
|
|
411
|
+
/**
|
|
412
|
+
* Live edges leaving a node, read from the incidence lists (O(degree)). On an undirected
|
|
413
|
+
* builder every incident edge leaves the node (invariant I7: the snapshot's row holds both
|
|
414
|
+
* orientations), so the declared orientation is ignored and a self-loop is listed once.
|
|
415
|
+
* @param index - the node index
|
|
416
|
+
* @returns a fresh ascending array of live edge indices
|
|
417
|
+
*/
|
|
418
|
+
outEdgesOf(index: number): U32;
|
|
419
|
+
/**
|
|
420
|
+
* Live edges entering a node (O(degree)); on an undirected builder the same set as outEdgesOf
|
|
421
|
+
* (the alias rule of inDegree === outDegree).
|
|
422
|
+
* @param index - the node index
|
|
423
|
+
* @returns a fresh ascending array of live edge indices
|
|
424
|
+
*/
|
|
425
|
+
inEdgesOf(index: number): U32;
|
|
426
|
+
/**
|
|
427
|
+
* Live edges u -> v (undirected: either orientation), for answering "is there an edge" before a freeze.
|
|
428
|
+
* @param u - source node index
|
|
429
|
+
* @param v - target node index
|
|
430
|
+
* @returns a fresh array of live edge indices
|
|
431
|
+
*/
|
|
432
|
+
findEdges(u: number, v: number): U32;
|
|
433
|
+
// attributes
|
|
434
|
+
/**
|
|
435
|
+
* Bulk-set a node column; length must equal nodeBound.
|
|
436
|
+
* @param name - the column name
|
|
437
|
+
* @param data - the values
|
|
438
|
+
* @param decl - declaration fields
|
|
439
|
+
*/
|
|
440
|
+
setNodeColumn(name: string, data: TypedArrayData, decl?: ColumnDeclPatch): void;
|
|
441
|
+
/**
|
|
442
|
+
* Bulk-set an edge column; length must equal edgeBound.
|
|
443
|
+
* @param name - the column name
|
|
444
|
+
* @param data - the values
|
|
445
|
+
* @param decl - declaration fields
|
|
446
|
+
*/
|
|
447
|
+
setEdgeColumn(name: string, data: TypedArrayData, decl?: ColumnDeclPatch): void;
|
|
448
|
+
// composition
|
|
449
|
+
/**
|
|
450
|
+
* Append another snapshot (disjoint union, or merge by id), re-interning dictionaries (design section 6.6).
|
|
451
|
+
* @param snapshot - the snapshot to append
|
|
452
|
+
* @param options - duplicate-id handling
|
|
453
|
+
* @param options.onDuplicateNode - "merge" (default) overwrites set rows of existing ids; "error" throws
|
|
454
|
+
* E_DUPLICATE_ID
|
|
455
|
+
*/
|
|
456
|
+
addGraph(snapshot: GraphSnapshot, options?: { readonly onDuplicateNode?: "merge" | "error" | undefined }): void;
|
|
457
|
+
// output and lifecycle
|
|
458
|
+
/**
|
|
459
|
+
* Run the freeze pipeline of design section 6.3 and return a snapshot; the builder keeps its staging unless release
|
|
460
|
+
* is set.
|
|
461
|
+
* @param options - freeze options
|
|
462
|
+
* @returns the frozen snapshot
|
|
463
|
+
*/
|
|
464
|
+
freeze(options?: FreezeOptions): GraphSnapshot;
|
|
465
|
+
/**
|
|
466
|
+
* freeze() plus the report of what was renumbered, merged, dropped and widened.
|
|
467
|
+
* @param options - freeze options
|
|
468
|
+
* @returns the snapshot and its report
|
|
469
|
+
*/
|
|
470
|
+
freezeWithReport(options?: FreezeOptions): { snapshot: GraphSnapshot; report: FreezeReport };
|
|
471
|
+
/** Empty the builder (nodes, edges, columns, meta) while keeping its options. */
|
|
472
|
+
clear(): void;
|
|
473
|
+
/** Release everything; every further call throws E_BUILDER_DISPOSED. */
|
|
474
|
+
dispose(): void;
|
|
475
|
+
/**
|
|
476
|
+
* Bytes of staging currently held.
|
|
477
|
+
* @returns the byte count
|
|
478
|
+
*/
|
|
479
|
+
byteLength(): number;
|
|
480
|
+
}
|