@atlaspack/graph 3.5.10-typescript-1fd1095e8.0 → 3.5.10-typescript-e99c742e9.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/lib/AdjacencyList.d.ts +607 -0
- package/lib/BitSet.d.ts +19 -0
- package/lib/ContentGraph.d.ts +23 -0
- package/lib/Graph.d.ts +91 -0
- package/lib/index.d.ts +7 -0
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/types.d.ts +9 -0
- package/package.json +9 -9
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import { NullEdgeType, AllEdgeTypes } from './Graph';
|
|
2
|
+
import type { NodeId } from './types';
|
|
3
|
+
/** The address of the node in the nodes map. */
|
|
4
|
+
type NodeAddress = number;
|
|
5
|
+
type EdgeHash = number;
|
|
6
|
+
/** The address of the edge in the edges map. */
|
|
7
|
+
type EdgeAddress = number;
|
|
8
|
+
export type SerializedAdjacencyList<TEdgeType> = {
|
|
9
|
+
nodes: Uint32Array;
|
|
10
|
+
edges: Uint32Array;
|
|
11
|
+
};
|
|
12
|
+
export type AdjacencyListOptions<TEdgeType> = {
|
|
13
|
+
/** The initial number of edges to accommodate. */
|
|
14
|
+
initialCapacity?: number;
|
|
15
|
+
/** The max amount by which to grow the capacity. */
|
|
16
|
+
maxGrowFactor?: number;
|
|
17
|
+
/** The min amount by which to grow the capacity. */
|
|
18
|
+
minGrowFactor?: number;
|
|
19
|
+
/** The size after which to grow the capacity by the minimum factor. */
|
|
20
|
+
peakCapacity?: number;
|
|
21
|
+
/** The percentage of deleted edges above which the capacity should shrink. */
|
|
22
|
+
unloadFactor?: number;
|
|
23
|
+
/** The amount by which to shrink the capacity. */
|
|
24
|
+
shrinkFactor?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* `AdjacencyList` maps nodes to lists of their adjacent nodes.
|
|
28
|
+
*
|
|
29
|
+
* It is implemented as a hashmap of nodes, where each node has
|
|
30
|
+
* doubly linked lists of edges of each unique edge type.
|
|
31
|
+
* The edges are stored in a separate hashmap, where each edge has
|
|
32
|
+
* a pointer to the originating node, the terminating node, and
|
|
33
|
+
* the next and previous edges to and from adjacent nodes.
|
|
34
|
+
*
|
|
35
|
+
* The hash maps are each stored in a `Uint32Array` backed
|
|
36
|
+
* by a `SharedArrayBuffer`. See `SharedTypeMap` for more details.
|
|
37
|
+
*
|
|
38
|
+
* It's primary interface is through the `getNodeIdsConnectedFrom`
|
|
39
|
+
* and `getNodeIdsConnectedTo` methods, which return the list of
|
|
40
|
+
* nodes connected from or to a given node, respectively.
|
|
41
|
+
*
|
|
42
|
+
* It is also possible to get the lists of edges connected from or to
|
|
43
|
+
* a given node, using the `getOutboundEdgesByType` and
|
|
44
|
+
* `getInboundEdgesByType` methods.
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export default class AdjacencyList<TEdgeType extends number = NullEdgeType> {
|
|
48
|
+
#private;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new `AdjacencyList` in one of two ways:
|
|
51
|
+
* - with specified options, or
|
|
52
|
+
* - with data serialized from a previous `AdjacencyList`.
|
|
53
|
+
*/
|
|
54
|
+
constructor(opts?: SerializedAdjacencyList<TEdgeType | NullEdgeType> | AdjacencyListOptions<TEdgeType | NullEdgeType>);
|
|
55
|
+
/**
|
|
56
|
+
* Create a new `AdjacencyList` with data serialized
|
|
57
|
+
* from another `AdjacencyList`.
|
|
58
|
+
*/
|
|
59
|
+
static deserialize<TEdgeType extends number = NullEdgeType>(opts: SerializedAdjacencyList<TEdgeType>): AdjacencyList<TEdgeType>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns a serializable object of the nodes and edges in the AdjacencyList.
|
|
62
|
+
*/
|
|
63
|
+
serialize(): SerializedAdjacencyList<TEdgeType>;
|
|
64
|
+
/** Statistics about the current state of the `AdjacencyList`. */
|
|
65
|
+
get stats(): {
|
|
66
|
+
/** The maximum number of edges the graph can contain. */
|
|
67
|
+
capacity: number;
|
|
68
|
+
/** The number of nodes in the graph. */
|
|
69
|
+
nodes: number;
|
|
70
|
+
/** The number of edge types associated with nodes in the graph. */
|
|
71
|
+
nodeEdgeTypes: number;
|
|
72
|
+
/** The size of the raw nodes buffer, in mb. */
|
|
73
|
+
nodeBufferSize: string;
|
|
74
|
+
/** The current load on the nodes array. */
|
|
75
|
+
nodeLoad: string;
|
|
76
|
+
/** The number of edges in the graph. */
|
|
77
|
+
edges: number;
|
|
78
|
+
/** The number of edges deleted from the graph. */
|
|
79
|
+
deleted: number;
|
|
80
|
+
/** The number of unique edge types in the graph. */
|
|
81
|
+
edgeTypes: number;
|
|
82
|
+
/** The size of the raw edges buffer, in mb. */
|
|
83
|
+
edgeBufferSize: string;
|
|
84
|
+
/** The current load on the edges array, including deletes. */
|
|
85
|
+
edgeLoadWithDeletes: string;
|
|
86
|
+
/** The current load on the edges array. */
|
|
87
|
+
edgeLoad: string;
|
|
88
|
+
/** The total number of edge hash collisions. */
|
|
89
|
+
collisions: number;
|
|
90
|
+
/** The number of collisions for the most common hash. */
|
|
91
|
+
maxCollisions: number;
|
|
92
|
+
/** The average number of collisions per hash. */
|
|
93
|
+
avgCollisions: number;
|
|
94
|
+
/**
|
|
95
|
+
* The actual distribution of hashes vs. the expected (uniform) distribution.
|
|
96
|
+
*
|
|
97
|
+
* From: https://en.wikipedia.org/wiki/Hash_function#Testing_and_measurement
|
|
98
|
+
*
|
|
99
|
+
* > A ratio within one confidence interval (0.95 - 1.05) is indicative
|
|
100
|
+
* > that the hash function...has an expected uniform distribution.
|
|
101
|
+
*/
|
|
102
|
+
uniformity: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Resize the internal nodes array.
|
|
106
|
+
*
|
|
107
|
+
* This is used in `addNode` and in `addEdge` when
|
|
108
|
+
* the `nodes` array is at capacity,
|
|
109
|
+
*/
|
|
110
|
+
resizeNodes(size: number): void;
|
|
111
|
+
/**
|
|
112
|
+
* Resize the internal edges array.
|
|
113
|
+
*
|
|
114
|
+
* This is used in `addEdge` when the `edges` array is at capacity.
|
|
115
|
+
*/
|
|
116
|
+
resizeEdges(size: number): void;
|
|
117
|
+
/**
|
|
118
|
+
* Adds a node to the graph.
|
|
119
|
+
*
|
|
120
|
+
* Note that this method does not increment the node count
|
|
121
|
+
* (that only happens in `addEdge`), it _may_ preemptively resize
|
|
122
|
+
* the nodes array if it is at capacity, under the assumption that
|
|
123
|
+
* at least 1 edge to or from this new node will be added.
|
|
124
|
+
*
|
|
125
|
+
* Returns the id of the added node.
|
|
126
|
+
*/
|
|
127
|
+
addNode(): NodeId;
|
|
128
|
+
/**
|
|
129
|
+
* Adds an edge to the graph.
|
|
130
|
+
*
|
|
131
|
+
* This method will increment the edge count, and it _may_
|
|
132
|
+
* also increment the node count, if the originating or
|
|
133
|
+
* terminating node does not yet have any edges of the given type.
|
|
134
|
+
*
|
|
135
|
+
* If either the `nodes` or `edges` arrays are at capacity,
|
|
136
|
+
* this method will resize them before adding.
|
|
137
|
+
*
|
|
138
|
+
* Furthermore, if the `edges` array has a high number of
|
|
139
|
+
* deleted edges, it may reclaim the space before adding.
|
|
140
|
+
*
|
|
141
|
+
* Returns `true` if the edge was added,
|
|
142
|
+
* or `false` if the edge already exists.
|
|
143
|
+
*/
|
|
144
|
+
addEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Iterate over all edges in insertion order.
|
|
147
|
+
*/
|
|
148
|
+
getAllEdges(): Iterator<{
|
|
149
|
+
type: TEdgeType | NullEdgeType;
|
|
150
|
+
from: NodeId;
|
|
151
|
+
to: NodeId;
|
|
152
|
+
}>;
|
|
153
|
+
/**
|
|
154
|
+
* Check if the graph has an edge connecting the `from` and `to` nodes.
|
|
155
|
+
*/
|
|
156
|
+
hasEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType>): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Remove an edge connecting the `from` and `to` nodes.
|
|
159
|
+
*
|
|
160
|
+
* Note that space for the deleted edge is not reclaimed
|
|
161
|
+
* until the `edges` array is resized.
|
|
162
|
+
*
|
|
163
|
+
* This method will increment the edge delete count.
|
|
164
|
+
*/
|
|
165
|
+
removeEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType): void;
|
|
166
|
+
/**
|
|
167
|
+
* Check if the given node has any edges incoming from other nodes.
|
|
168
|
+
*
|
|
169
|
+
* Essentially, this is an orphan check. If a node has no incoming edges,
|
|
170
|
+
* it (and its entire subgraph) is completely disconnected from the
|
|
171
|
+
* rest of the graph.
|
|
172
|
+
*/
|
|
173
|
+
hasInboundEdges(to: NodeId): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Get a list of every node (labeled `from`) connecting _to_
|
|
176
|
+
* the given `to` node, along with the edge `type` connecting them.
|
|
177
|
+
*/
|
|
178
|
+
getInboundEdgesByType(to: NodeId): {
|
|
179
|
+
type: TEdgeType | NullEdgeType;
|
|
180
|
+
from: NodeId;
|
|
181
|
+
}[];
|
|
182
|
+
/**
|
|
183
|
+
* Get a list of every node (labeled `to`) connected _from_
|
|
184
|
+
* the given `from` node, along with the edge `type` connecting them.
|
|
185
|
+
*/
|
|
186
|
+
getOutboundEdgesByType(from: NodeId): {
|
|
187
|
+
type: TEdgeType | NullEdgeType;
|
|
188
|
+
to: NodeId;
|
|
189
|
+
}[];
|
|
190
|
+
/**
|
|
191
|
+
* Get the list of node ids connected from this node.
|
|
192
|
+
*
|
|
193
|
+
* If `type` is specified, only return nodes connected by edges of that type.
|
|
194
|
+
* If `type` is an array, return nodes connected by edges of any of those types.
|
|
195
|
+
* If `type` is `AllEdgeTypes` (`-1`), return nodes connected by edges of any type.
|
|
196
|
+
*/
|
|
197
|
+
getNodeIdsConnectedFrom(from: NodeId, type?: AllEdgeTypes | TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType>): NodeId[];
|
|
198
|
+
forEachNodeIdConnectedFromReverse(from: NodeId, fn: (nodeId: NodeId) => boolean, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
199
|
+
forEachNodeIdConnectedTo(to: NodeId, fn: (nodeId: NodeId) => boolean | undefined, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
200
|
+
/**
|
|
201
|
+
* Get the list of node ids connected to this node.
|
|
202
|
+
*
|
|
203
|
+
* If `type` is specified, only return nodes connected by edges of that type.
|
|
204
|
+
* If `type` is an array, return nodes connected by edges of any of those types.
|
|
205
|
+
* If `type` is `AllEdgeTypes` (`-1`), return nodes connected by edges of any type.
|
|
206
|
+
*/
|
|
207
|
+
getNodeIdsConnectedTo(to: NodeId, type?: AllEdgeTypes | TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType>): NodeId[];
|
|
208
|
+
inspect(): any;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `SharedTypeMap` is a hashmap of items,
|
|
212
|
+
* where each item has its own 'type' field.
|
|
213
|
+
*
|
|
214
|
+
* The `SharedTypeMap` is backed by a shared array buffer of fixed length.
|
|
215
|
+
* The buffer is partitioned into:
|
|
216
|
+
* - a header, which stores the capacity and number of items in the map,
|
|
217
|
+
* - a hash table, which is an array of pointers to linked lists of items
|
|
218
|
+
* with the same hash,
|
|
219
|
+
* - an items array, which is where the linked items are stored.
|
|
220
|
+
*
|
|
221
|
+
* hash table item
|
|
222
|
+
* (capacity) (ITEM_SIZE)
|
|
223
|
+
* ┌──────┴──────┐ ┌──┴──┐
|
|
224
|
+
* ┌──┬──┬──┬───────┬──┬──┬──┬───────┬──┬──┐
|
|
225
|
+
* │ │ │ │ ... │ │ │ │ ... │ │ │
|
|
226
|
+
* └──┴──┴──┴───────┴──┴──┴──┴───────┴──┴──┘
|
|
227
|
+
* └──┬──┘ └─────────┬─────────┘
|
|
228
|
+
* header items
|
|
229
|
+
* (HEADER_SIZE) (capacity * ITEM_SIZE)
|
|
230
|
+
*
|
|
231
|
+
*
|
|
232
|
+
* An item is added with a hash key that fits within the range of the hash
|
|
233
|
+
* table capacity. The item is stored at the next available address after the
|
|
234
|
+
* hash table, and a pointer to the address is stored in the hash table at
|
|
235
|
+
* the index matching the hash. If the hash is already pointing at an item,
|
|
236
|
+
* the pointer is stored in the `next` field of the existing item instead.
|
|
237
|
+
*
|
|
238
|
+
* hash table items
|
|
239
|
+
* ┌─────────┴────────┐┌───────────────────────┴────────────────────────┐
|
|
240
|
+
* 0 1 2 11 17 23 29 35
|
|
241
|
+
* ┌───┐┌───┐┌───┐┌───┐┌───┬───┐┌───┬───┐┌───┬───┐┌───┬───┐┌───┬───┐┌───┐
|
|
242
|
+
* │17 ││11 ││35 ││...││23 │ 1 ││29 │ 1 ││ 0 │ 2 ││ 0 │ 2 ││ 0 │ 1 ││...│
|
|
243
|
+
* └───┘└───┘└───┘└───┘└───┴───┘└───┴───┘└───┴───┘└───┴───┘└───┴───┘└───┘
|
|
244
|
+
* │ │ │ ▲ ▲ ▲ ▲ ▲
|
|
245
|
+
* └────┼────┼─────────┼────────┴────────┼────────┘ │
|
|
246
|
+
* └────┼─────────┴─────────────────┘ │
|
|
247
|
+
* └─────────────────────────────────────────────┘
|
|
248
|
+
*/
|
|
249
|
+
export declare class SharedTypeMap<TItemType, THash, TAddress extends number> implements Iterable<TAddress> {
|
|
250
|
+
#private;
|
|
251
|
+
/**
|
|
252
|
+
* The header for the `SharedTypeMap` comprises 2 4-byte chunks:
|
|
253
|
+
*
|
|
254
|
+
* struct SharedTypeMapHeader {
|
|
255
|
+
* int capacity;
|
|
256
|
+
* int count;
|
|
257
|
+
* }
|
|
258
|
+
*
|
|
259
|
+
* ┌──────────┬───────┐
|
|
260
|
+
* │ CAPACITY │ COUNT │
|
|
261
|
+
* └──────────┴───────┘
|
|
262
|
+
*/
|
|
263
|
+
static HEADER_SIZE: number;
|
|
264
|
+
/**
|
|
265
|
+
* Each item in `SharedTypeMap` comprises 2 4-byte chunks:
|
|
266
|
+
*
|
|
267
|
+
* struct Node {
|
|
268
|
+
* int next;
|
|
269
|
+
* int type;
|
|
270
|
+
* }
|
|
271
|
+
*
|
|
272
|
+
* ┌──────┬──────┐
|
|
273
|
+
* │ NEXT │ TYPE │
|
|
274
|
+
* └──────┴──────┘
|
|
275
|
+
*/
|
|
276
|
+
static ITEM_SIZE: number;
|
|
277
|
+
/** The largest possible capacity. */
|
|
278
|
+
static get MAX_CAPACITY<TItemType, THash, TAddress extends number>(): number;
|
|
279
|
+
/** Assert that the given `capacity` does not exceed `MAX_CAPACITY`. */
|
|
280
|
+
static assertMaxCapacity<TItemType, THash, TAddress extends number>(capacity: number): void;
|
|
281
|
+
data: Uint32Array;
|
|
282
|
+
/** The total number of items that can fit in the map. */
|
|
283
|
+
get capacity(): number;
|
|
284
|
+
/** The number of items in the map. */
|
|
285
|
+
get count(): number;
|
|
286
|
+
/** The ratio of the count to the capacity. */
|
|
287
|
+
get load(): number;
|
|
288
|
+
/** The total length of the map, in bytes. */
|
|
289
|
+
get length(): number;
|
|
290
|
+
/** The address of the first item in the map. */
|
|
291
|
+
get addressableLimit(): number;
|
|
292
|
+
/** The size of the map in mb, as a localized string. */
|
|
293
|
+
get bufferSize(): string;
|
|
294
|
+
/**
|
|
295
|
+
* Create a new `SharedTypeMap` in one of two ways:
|
|
296
|
+
* - with a capacity of `capacityOrData` if it is a number,
|
|
297
|
+
* - or with `capacityOrData` as its data, if it is a `Uint32Array`.
|
|
298
|
+
*/
|
|
299
|
+
constructor(capacityOrData: number | Uint32Array);
|
|
300
|
+
/**
|
|
301
|
+
* Overwrite the data in this map with the given `data`.
|
|
302
|
+
*
|
|
303
|
+
* The `data` is expected to conform to the same
|
|
304
|
+
* partitioning and schema as the data in this map,
|
|
305
|
+
* and is expected to be of equal or smaller capacity to this map.
|
|
306
|
+
*/
|
|
307
|
+
set(data: Uint32Array): void;
|
|
308
|
+
/**
|
|
309
|
+
* Given a `count` (defaulting to `this.count`),
|
|
310
|
+
* get the load on the map.
|
|
311
|
+
*
|
|
312
|
+
* The load is the ratio of the `count` the capacity of the map.
|
|
313
|
+
*
|
|
314
|
+
* If the load is `1`, it means the map is at capacity, and needs
|
|
315
|
+
* to be resized before adding more items.
|
|
316
|
+
*/
|
|
317
|
+
getLoad(count?: number): number;
|
|
318
|
+
/**
|
|
319
|
+
* Given a `capacity` (defaulting to `this.capacity`),
|
|
320
|
+
* get the length of the map, in bytes.
|
|
321
|
+
*/
|
|
322
|
+
getLength(capacity?: number): number;
|
|
323
|
+
/** Get the next available address in the map. */
|
|
324
|
+
getNextAddress(): TAddress;
|
|
325
|
+
/** Get the address of the first item with the given hash. */
|
|
326
|
+
head(hash: THash): TAddress | null;
|
|
327
|
+
/** Get the address of the next item with the same hash as the given item. */
|
|
328
|
+
next(item: TAddress): TAddress | null;
|
|
329
|
+
/** Get the type of the item at the given `item` address. */
|
|
330
|
+
typeOf(item: TAddress): TItemType;
|
|
331
|
+
/**
|
|
332
|
+
* Store an item of `type` at the `item` address and
|
|
333
|
+
* link the address to the `hash` bucket.
|
|
334
|
+
*/
|
|
335
|
+
link(hash: THash, item: TAddress, type: TItemType): void;
|
|
336
|
+
/**
|
|
337
|
+
* Remove the link to the `item` address from the `hash` bucket.
|
|
338
|
+
*/
|
|
339
|
+
unlink(hash: THash, item: TAddress): void;
|
|
340
|
+
forEach(cb: (item: TAddress) => void): void;
|
|
341
|
+
[Symbol.iterator](): Iterator<TAddress>;
|
|
342
|
+
inspect(): {
|
|
343
|
+
header: Uint32Array;
|
|
344
|
+
table: Uint32Array;
|
|
345
|
+
data: Uint32Array;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Nodes are stored in a `SharedTypeMap`, keyed on node id plus an edge type.
|
|
350
|
+
* This means that for any given unique node id, there may be `e` nodes in the
|
|
351
|
+
* map, where `e` is the number of unique edge types in the graph.
|
|
352
|
+
*
|
|
353
|
+
* The _hash_ for a node is simply the node id (as issued by `getId`),
|
|
354
|
+
* and forms the head of linked list of unique _edge types_ connected
|
|
355
|
+
* to or from the same node id.
|
|
356
|
+
*
|
|
357
|
+
* In addition to a unique edge type, each Node contains the heads and tails
|
|
358
|
+
* of doubly linked lists of incoming and outgoing edges of the same type.
|
|
359
|
+
*
|
|
360
|
+
* Note that the links in the doubly linked lists are Edges (not Nodes),
|
|
361
|
+
* which are stored in a corresponding `EdgeTypeMap`.
|
|
362
|
+
*/
|
|
363
|
+
export declare class NodeTypeMap<TEdgeType> extends SharedTypeMap<TEdgeType, NodeId, NodeAddress> {
|
|
364
|
+
#private;
|
|
365
|
+
/**
|
|
366
|
+
* In addition to the header defined by `SharedTypeMap`, the header for
|
|
367
|
+
* the node map includes a 4-byte `nextId` chunk:
|
|
368
|
+
*
|
|
369
|
+
* struct NodeTypeMapHeader {
|
|
370
|
+
* int capacity; // from `SharedTypeMap`
|
|
371
|
+
* int count; // from `SharedTypeMap`
|
|
372
|
+
* int nextId;
|
|
373
|
+
* }
|
|
374
|
+
*
|
|
375
|
+
* ┌──────────┬───────┬─────────┐
|
|
376
|
+
* │ CAPACITY │ COUNT │ NEXT_ID │
|
|
377
|
+
* └──────────┴───────┴─────────┘
|
|
378
|
+
*
|
|
379
|
+
* The `nextId` is a count of the number of times `getId` has been called.
|
|
380
|
+
* This is distinct concept from the `count`, which tracks the number of times
|
|
381
|
+
* `add` has been called.
|
|
382
|
+
*
|
|
383
|
+
* The reason for this distinction is that `getId` is called once per node
|
|
384
|
+
* (to issue a _unique_ id) and will _always increment_ the `nextId` counter,
|
|
385
|
+
* whereas `add` is called once per edge, and will only increment the `count`
|
|
386
|
+
* if the _type_ of edge is new for the given node.
|
|
387
|
+
*/
|
|
388
|
+
static HEADER_SIZE: number;
|
|
389
|
+
/**
|
|
390
|
+
* In addition to the item fields defined by `SharedTypeMap`,
|
|
391
|
+
* each node includes another 4 4-byte chunks:
|
|
392
|
+
*
|
|
393
|
+
* struct Node {
|
|
394
|
+
* int next; // from `SharedTypeMap`
|
|
395
|
+
* int type; // from `SharedTypeMap`
|
|
396
|
+
* int firstIn;
|
|
397
|
+
* int firstOut;
|
|
398
|
+
* int lastIn;
|
|
399
|
+
* int lastOut;
|
|
400
|
+
* }
|
|
401
|
+
*
|
|
402
|
+
* ┌──────┬──────┬──────────┬───────────┬─────────┬──────────┐
|
|
403
|
+
* │ NEXT │ TYPE │ FIRST_IN │ FIRST_OUT │ LAST_IN │ LAST_OUT │
|
|
404
|
+
* └──────┴──────┴──────────┴───────────┴─────────┴──────────┘
|
|
405
|
+
*
|
|
406
|
+
* The `Node` implicitly maps a node id (the hash the node was added with)
|
|
407
|
+
* to the first and last incoming and outgoing edges of the same _edge type_.
|
|
408
|
+
*/
|
|
409
|
+
static ITEM_SIZE: number;
|
|
410
|
+
get nextId(): NodeId;
|
|
411
|
+
set nextId(nextId: NodeId);
|
|
412
|
+
/**
|
|
413
|
+
* Get the load on the node map.
|
|
414
|
+
*
|
|
415
|
+
* The load is the greater of either:
|
|
416
|
+
* - the ratio of the number of node ids to the capacity of the map,
|
|
417
|
+
* - or the ratio of the `count` to the capacity of the map.
|
|
418
|
+
*
|
|
419
|
+
* if `count` is not provided, the default is the number of items
|
|
420
|
+
* currently added to the map.
|
|
421
|
+
*/
|
|
422
|
+
getLoad(count?: number): number;
|
|
423
|
+
/** Increment the node counter to get a unique node id. */
|
|
424
|
+
getId(): NodeId;
|
|
425
|
+
/**
|
|
426
|
+
* Add new lists of edges of the given `type` to and from the given `node`.
|
|
427
|
+
*/
|
|
428
|
+
add(node: NodeId, type: TEdgeType): NodeAddress;
|
|
429
|
+
/**
|
|
430
|
+
* Get the address of the lists edges of the given `type`
|
|
431
|
+
* to and from the given `node`.
|
|
432
|
+
*/
|
|
433
|
+
addressOf(node: NodeId, type: TEdgeType): NodeAddress | null;
|
|
434
|
+
/**
|
|
435
|
+
* Given a `node` address, get the _head_ of the linked list
|
|
436
|
+
* of incoming edges of the same type to the same node.
|
|
437
|
+
*/
|
|
438
|
+
firstIn(node: NodeAddress): EdgeAddress | null;
|
|
439
|
+
/**
|
|
440
|
+
* Given a `node` address, get the _head_ of the linked list
|
|
441
|
+
* of outgoing edges of the same type from the same node.
|
|
442
|
+
*/
|
|
443
|
+
firstOut(node: NodeAddress): EdgeAddress | null;
|
|
444
|
+
/**
|
|
445
|
+
* Given a `node` address, get the _tail_ of the linked list
|
|
446
|
+
* of incoming edges of the same type to the same node.
|
|
447
|
+
*/
|
|
448
|
+
lastIn(node: NodeAddress): EdgeAddress | null;
|
|
449
|
+
/**
|
|
450
|
+
* Given a `node` address, get the _tail_ of the linked list
|
|
451
|
+
* of outgoing edges of the same type from the same node.
|
|
452
|
+
*/
|
|
453
|
+
lastOut(node: NodeAddress): EdgeAddress | null;
|
|
454
|
+
/**
|
|
455
|
+
* Set `edge` as the last incoming edge to `node`.
|
|
456
|
+
* If `node` has no incoming edges, set `edge`
|
|
457
|
+
* as the first incoming edge, as well.
|
|
458
|
+
*
|
|
459
|
+
* Returns the address of the old last incoming edge, if any.
|
|
460
|
+
*/
|
|
461
|
+
linkIn(node: NodeAddress, edge: EdgeAddress): EdgeAddress | null;
|
|
462
|
+
/**
|
|
463
|
+
* If `edge` is the last incoming edge to `node`,
|
|
464
|
+
* update the node's last incoming edge to `prev`.
|
|
465
|
+
*
|
|
466
|
+
* If `edge` is the first incoming edge to `node`,
|
|
467
|
+
* update the node's first incoming edge to `next`.
|
|
468
|
+
*/
|
|
469
|
+
unlinkIn(node: NodeAddress, edge: EdgeAddress, prev: EdgeAddress | null, next: EdgeAddress | null): void;
|
|
470
|
+
/**
|
|
471
|
+
* Set `edge` as the last outgoing edge from `node`.
|
|
472
|
+
* If `node` has no outgoing edges, set `edge`
|
|
473
|
+
* as the first outgoing edge, as well.
|
|
474
|
+
*
|
|
475
|
+
* Returns the address of the old last outgoing edge, if any.
|
|
476
|
+
*/
|
|
477
|
+
linkOut(node: NodeAddress, edge: EdgeAddress): EdgeAddress | null;
|
|
478
|
+
/**
|
|
479
|
+
* If `edge` is the last outgoing edge from `node`,
|
|
480
|
+
* update the node's last outgoing edge to `prev`.
|
|
481
|
+
*
|
|
482
|
+
* If `edge` is the first outgoing edge from `node`,
|
|
483
|
+
* update the node's first outgoing edge to `next`.
|
|
484
|
+
*/
|
|
485
|
+
unlinkOut(node: NodeAddress, edge: EdgeAddress, prev: EdgeAddress | null, next: EdgeAddress | null): void;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Edges are stored in a `SharedTypeMap`,
|
|
489
|
+
* keyed on the 'from' and 'to' node ids, and the edge type.
|
|
490
|
+
*
|
|
491
|
+
* The _hash_ for an edge is a hash of the edge's `from`, `to`, and `type` values,
|
|
492
|
+
* and forms the head of linked list of edges with the same hash.
|
|
493
|
+
*
|
|
494
|
+
* In addition to the `from`, `to` and `type` values, each Edge contains
|
|
495
|
+
* the next and previous links of doubly linked lists of the _adjacent_ edges
|
|
496
|
+
* of the same type, both incoming to the `to` node, and outgoing from
|
|
497
|
+
* the `from` node.
|
|
498
|
+
*/
|
|
499
|
+
export declare class EdgeTypeMap<TEdgeType> extends SharedTypeMap<TEdgeType, EdgeHash, EdgeAddress> {
|
|
500
|
+
#private;
|
|
501
|
+
/**
|
|
502
|
+
* In addition to the header defined by `SharedTypeMap`, the header for
|
|
503
|
+
* the edge map includes a 4-byte `deletes` chunk:
|
|
504
|
+
*
|
|
505
|
+
* struct EdgeTypeMapHeader {
|
|
506
|
+
* int capacity; // from `SharedTypeMap`
|
|
507
|
+
* int count; // from `SharedTypeMap`
|
|
508
|
+
* int deletes;
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* ┌──────────┬───────┬─────────┐
|
|
512
|
+
* │ CAPACITY │ COUNT │ DELETES │
|
|
513
|
+
* └──────────┴───────┴─────────┘
|
|
514
|
+
*
|
|
515
|
+
* Since new edges are always appended, the space for deleted edges
|
|
516
|
+
* is not reused. Instead, the `deletes` count is incremented when an
|
|
517
|
+
* edge is deleted. The next available address is calculated by
|
|
518
|
+
* adding the `count` and `deletes` values to the header size.
|
|
519
|
+
*
|
|
520
|
+
* The only way to reclaim the space used by deleted edges is to resize the map.
|
|
521
|
+
*/
|
|
522
|
+
static HEADER_SIZE: number;
|
|
523
|
+
/**
|
|
524
|
+
* In addition to the item fields defined by `SharedTypeMap`,
|
|
525
|
+
* each edge includes another 6 4-byte chunks:
|
|
526
|
+
*
|
|
527
|
+
* struct Edge {
|
|
528
|
+
* int next; // from `SharedTypeMap`
|
|
529
|
+
* int type; // from `SharedTypeMap`
|
|
530
|
+
* int from;
|
|
531
|
+
* int to;
|
|
532
|
+
* int nextIn;
|
|
533
|
+
* int prevIn;
|
|
534
|
+
* int nextOut;
|
|
535
|
+
* int prevOut;
|
|
536
|
+
* }
|
|
537
|
+
*
|
|
538
|
+
* ┌──────┬──────┬──────┬────┬─────────┬─────────┬──────────┬──────────┐
|
|
539
|
+
* │ NEXT │ TYPE │ FROM │ TO │ NEXT_IN │ PREV_IN │ NEXT_OUT │ PREV_OUT │
|
|
540
|
+
* └──────┴──────┴──────┴────┴─────────┴─────────┴──────────┴──────────┘
|
|
541
|
+
*
|
|
542
|
+
* The `Edge` implicitly maps an edge hash (the hash of the edge's `FROM`,
|
|
543
|
+
* `TO`, and `TYPE` values) to the next and previous adjacent edges of the
|
|
544
|
+
* same _edge type_.
|
|
545
|
+
*/
|
|
546
|
+
static ITEM_SIZE: number;
|
|
547
|
+
/** The number of deleted edges currently occupying space in the map. */
|
|
548
|
+
get deletes(): number;
|
|
549
|
+
/** Get the next available address in the map. */
|
|
550
|
+
getNextAddress(): EdgeAddress;
|
|
551
|
+
/**
|
|
552
|
+
* Add an edge of the given `type` between the `to` and `from` nodes
|
|
553
|
+
* and link the address to the `hash` bucket.
|
|
554
|
+
*/
|
|
555
|
+
add(hash: EdgeHash, from: NodeId, to: NodeId, type: TEdgeType): EdgeAddress;
|
|
556
|
+
/**
|
|
557
|
+
* Remove the `to` and `from` nodes for the given `edge` address
|
|
558
|
+
* and increment the `deletes` counter.
|
|
559
|
+
*/
|
|
560
|
+
delete(edge: EdgeAddress): void;
|
|
561
|
+
/**
|
|
562
|
+
* Get the address of the edge with the given `hash`, `from` and `to` nodes,
|
|
563
|
+
* and edge `type`.
|
|
564
|
+
*/
|
|
565
|
+
addressOf(hash: EdgeHash, from: NodeId, to: NodeId, type: TEdgeType): EdgeAddress | null;
|
|
566
|
+
/** Get the id of the 'from' node for the given `edge` address. */
|
|
567
|
+
from(edge: EdgeAddress): NodeId;
|
|
568
|
+
/** Get the id of the 'to' node for the given `edge` address. */
|
|
569
|
+
to(edge: EdgeAddress): NodeId;
|
|
570
|
+
/**
|
|
571
|
+
* Get the address of the next edge _of the same type_
|
|
572
|
+
* incoming _to the same node_ as the edge at the given address.
|
|
573
|
+
*/
|
|
574
|
+
nextIn(edge: EdgeAddress): EdgeAddress | null;
|
|
575
|
+
/**
|
|
576
|
+
* Get the address of the previous edge _of the same type_
|
|
577
|
+
* incoming _to the same node_ as the edge at the given address.
|
|
578
|
+
*/
|
|
579
|
+
prevIn(edge: EdgeAddress): EdgeAddress | null;
|
|
580
|
+
/** Link two adjacent edges of the same type incoming to the same node. */
|
|
581
|
+
linkIn(edge: EdgeAddress, next: EdgeAddress): void;
|
|
582
|
+
/**
|
|
583
|
+
* Unlink an edge from the doubly linked list of incoming edges
|
|
584
|
+
* to the same node.
|
|
585
|
+
*/
|
|
586
|
+
unlinkIn(edge: EdgeAddress): void;
|
|
587
|
+
/**
|
|
588
|
+
* Get the address of the next edge _of the same type_
|
|
589
|
+
* outgoing _from the same node_ as the edge at the given address.
|
|
590
|
+
*/
|
|
591
|
+
nextOut(edge: EdgeAddress): EdgeAddress | null;
|
|
592
|
+
/**
|
|
593
|
+
* Get the address of the previous edge _of the same type_
|
|
594
|
+
* outgoing _from the same node_ as the edge at the given address.
|
|
595
|
+
*/
|
|
596
|
+
prevOut(edge: EdgeAddress): EdgeAddress | null;
|
|
597
|
+
/** Link two adjacent edges of the same type outgoing from the same node. */
|
|
598
|
+
linkOut(edge: EdgeAddress, next: EdgeAddress): void;
|
|
599
|
+
/**
|
|
600
|
+
* Unlink an edge from the doubly linked list of outgoing edges
|
|
601
|
+
* of the same type from the same node.
|
|
602
|
+
*/
|
|
603
|
+
unlinkOut(edge: EdgeAddress): void;
|
|
604
|
+
/** Create a hash of the edge connecting the `from` and `to` nodes. */
|
|
605
|
+
hash(from: NodeId, to: NodeId, type: TEdgeType): EdgeHash;
|
|
606
|
+
}
|
|
607
|
+
export {};
|
package/lib/BitSet.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class BitSet {
|
|
2
|
+
bits: Uint32Array;
|
|
3
|
+
constructor(maxBits: number);
|
|
4
|
+
clone(): BitSet;
|
|
5
|
+
static union(a: BitSet, b: BitSet): BitSet;
|
|
6
|
+
static intersect(a: BitSet, b: BitSet): BitSet;
|
|
7
|
+
get capacity(): number;
|
|
8
|
+
add(bit: number): void;
|
|
9
|
+
delete(bit: number): void;
|
|
10
|
+
has(bit: number): boolean;
|
|
11
|
+
empty(): boolean;
|
|
12
|
+
clear(): void;
|
|
13
|
+
intersect(other: BitSet): void;
|
|
14
|
+
union(other: BitSet): void;
|
|
15
|
+
remove(other: BitSet): void;
|
|
16
|
+
size(): number;
|
|
17
|
+
equals(other: BitSet): boolean;
|
|
18
|
+
forEach(fn: (bit: number) => void): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContentKey, NodeId } from './types';
|
|
2
|
+
import Graph, { SerializedGraph, GraphOpts } from './Graph';
|
|
3
|
+
export type ContentGraphOpts<TNode, TEdgeType extends number = 1> = GraphOpts<TNode, TEdgeType> & {
|
|
4
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
5
|
+
_nodeIdToContentKey: Map<NodeId, ContentKey>;
|
|
6
|
+
};
|
|
7
|
+
export type SerializedContentGraph<TNode, TEdgeType extends number = 1> = SerializedGraph<TNode, TEdgeType> & {
|
|
8
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
9
|
+
};
|
|
10
|
+
export default class ContentGraph<TNode, TEdgeType extends number = 1> extends Graph<TNode, TEdgeType> {
|
|
11
|
+
_contentKeyToNodeId: Map<ContentKey, NodeId>;
|
|
12
|
+
_nodeIdToContentKey: Map<NodeId, ContentKey>;
|
|
13
|
+
constructor(opts?: ContentGraphOpts<TNode, TEdgeType> | null);
|
|
14
|
+
static deserialize<TNode, TEdgeType extends number = 1>(opts: ContentGraphOpts<TNode, TEdgeType>): ContentGraph<TNode, TEdgeType>;
|
|
15
|
+
serialize(): SerializedContentGraph<TNode, TEdgeType>;
|
|
16
|
+
addNodeByContentKey(contentKey: ContentKey, node: TNode): NodeId;
|
|
17
|
+
addNodeByContentKeyIfNeeded(contentKey: ContentKey, node: TNode): NodeId;
|
|
18
|
+
getNodeByContentKey(contentKey: ContentKey): TNode | null | undefined;
|
|
19
|
+
getContentKeyByNodeId(nodeId: NodeId): ContentKey;
|
|
20
|
+
getNodeIdByContentKey(contentKey: ContentKey): NodeId;
|
|
21
|
+
hasContentKey(contentKey: ContentKey): boolean;
|
|
22
|
+
removeNode(nodeId: NodeId, removeOrphans?: boolean): void;
|
|
23
|
+
}
|
package/lib/Graph.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import AdjacencyList, { SerializedAdjacencyList } from './AdjacencyList';
|
|
2
|
+
import type { Edge, NodeId } from './types';
|
|
3
|
+
import type { TraversalActions, GraphVisitor, GraphTraversalCallback } from '@atlaspack/types';
|
|
4
|
+
import { BitSet } from './BitSet';
|
|
5
|
+
export type NullEdgeType = 1;
|
|
6
|
+
export declare const NULL_EDGE_TYPE: NullEdgeType;
|
|
7
|
+
export type GraphOpts<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
8
|
+
nodes?: Array<TNode | null>;
|
|
9
|
+
adjacencyList?: SerializedAdjacencyList<TEdgeType>;
|
|
10
|
+
rootNodeId?: NodeId | null | undefined;
|
|
11
|
+
initialCapacity?: number;
|
|
12
|
+
};
|
|
13
|
+
export type SerializedGraph<TNode, TEdgeType extends number = NullEdgeType> = {
|
|
14
|
+
nodes: Array<TNode | null>;
|
|
15
|
+
adjacencyList: SerializedAdjacencyList<TEdgeType>;
|
|
16
|
+
rootNodeId: NodeId | null | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type AllEdgeTypes = -1;
|
|
19
|
+
export declare const ALL_EDGE_TYPES: AllEdgeTypes;
|
|
20
|
+
/**
|
|
21
|
+
* Options for DFS traversal.
|
|
22
|
+
*/
|
|
23
|
+
export type DFSParams<TContext> = {
|
|
24
|
+
visit: GraphVisitor<NodeId, TContext>;
|
|
25
|
+
/**
|
|
26
|
+
* Custom function to get next entries to visit.
|
|
27
|
+
*
|
|
28
|
+
* This can be a performance bottleneck as arrays are created on every node visit.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated This will be replaced by a static `traversalType` set of orders in the future
|
|
31
|
+
*
|
|
32
|
+
* Currently, this is only used in 3 ways:
|
|
33
|
+
*
|
|
34
|
+
* - Traversing down the tree (normal DFS)
|
|
35
|
+
* - Traversing up the tree (ancestors)
|
|
36
|
+
* - Filtered version of traversal; which does not need to exist at the DFS level as the visitor
|
|
37
|
+
* can handle filtering
|
|
38
|
+
* - Sorted traversal of BundleGraph entries, which does not have a clear use-case, but may
|
|
39
|
+
* not be safe to remove
|
|
40
|
+
*
|
|
41
|
+
* Only due to the latter we aren't replacing this.
|
|
42
|
+
*/
|
|
43
|
+
getChildren: (nodeId: NodeId) => Array<NodeId>;
|
|
44
|
+
startNodeId?: NodeId | null | undefined;
|
|
45
|
+
};
|
|
46
|
+
export default class Graph<TNode, TEdgeType extends number = NullEdgeType> {
|
|
47
|
+
nodes: Array<TNode | null>;
|
|
48
|
+
adjacencyList: AdjacencyList<TEdgeType>;
|
|
49
|
+
rootNodeId: NodeId | null | undefined;
|
|
50
|
+
_visited: BitSet | null | undefined;
|
|
51
|
+
constructor(opts?: GraphOpts<TNode, TEdgeType> | null);
|
|
52
|
+
setRootNodeId(id?: NodeId | null): void;
|
|
53
|
+
static deserialize<TNode, TEdgeType extends number = NullEdgeType>(opts: GraphOpts<TNode, TEdgeType>): Graph<TNode, TEdgeType>;
|
|
54
|
+
serialize(): SerializedGraph<TNode, TEdgeType>;
|
|
55
|
+
getAllEdges(): Iterator<Edge<TEdgeType | NullEdgeType>>;
|
|
56
|
+
addNode(node: TNode): NodeId;
|
|
57
|
+
hasNode(id: NodeId): boolean;
|
|
58
|
+
getNode(id: NodeId): TNode | null | undefined;
|
|
59
|
+
addEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType): boolean;
|
|
60
|
+
hasEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType>): boolean;
|
|
61
|
+
forEachNodeIdConnectedTo(to: NodeId, fn: (nodeId: NodeId) => boolean | undefined, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
62
|
+
forEachNodeIdConnectedFrom(from: NodeId, fn: (nodeId: NodeId) => void, type?: AllEdgeTypes | TEdgeType | NullEdgeType): void;
|
|
63
|
+
getNodeIdsConnectedTo(nodeId: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): Array<NodeId>;
|
|
64
|
+
getNodeIdsConnectedFrom(nodeId: NodeId, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): Array<NodeId>;
|
|
65
|
+
removeNode(nodeId: NodeId, removeOrphans?: boolean): void;
|
|
66
|
+
removeEdges(nodeId: NodeId, type?: TEdgeType | NullEdgeType): void;
|
|
67
|
+
removeEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
68
|
+
_removeEdge(from: NodeId, to: NodeId, type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
69
|
+
isOrphanedNode(nodeId: NodeId): boolean;
|
|
70
|
+
updateNode(nodeId: NodeId, node: TNode): void;
|
|
71
|
+
replaceNodeIdsConnectedTo(fromNodeId: NodeId, toNodeIds: ReadonlyArray<NodeId>, replaceFilter?: null | ((arg1: NodeId) => boolean), type?: TEdgeType | NullEdgeType, removeOrphans?: boolean): void;
|
|
72
|
+
traverse<TContext>(visit: GraphVisitor<NodeId, TContext>, startNodeId?: NodeId | null, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
73
|
+
filteredTraverse<TValue, TContext>(filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined, visit: GraphVisitor<TValue, TContext>, startNodeId?: NodeId | null, type?: TEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
74
|
+
traverseAncestors<TContext>(startNodeId: NodeId | null | undefined, visit: GraphVisitor<NodeId, TContext>, type?: TEdgeType | NullEdgeType | Array<TEdgeType | NullEdgeType> | AllEdgeTypes): TContext | null | undefined;
|
|
75
|
+
dfsFast<TContext>(visit: GraphTraversalCallback<NodeId, TContext>, startNodeId?: NodeId | null): TContext | null | undefined;
|
|
76
|
+
postOrderDfsFast(visit: GraphTraversalCallback<NodeId, TraversalActions>, startNodeId?: NodeId | null): void;
|
|
77
|
+
/**
|
|
78
|
+
* Iterative implementation of DFS that supports all use-cases.
|
|
79
|
+
*
|
|
80
|
+
* This replaces `dfs` and will replace `dfsFast`.
|
|
81
|
+
*/
|
|
82
|
+
dfs<TContext>({ visit, startNodeId, getChildren, }: DFSParams<TContext>): TContext | null | undefined;
|
|
83
|
+
bfs(visit: (nodeId: NodeId) => boolean | null | undefined): NodeId | null | undefined;
|
|
84
|
+
topoSort(type?: TEdgeType): Array<NodeId>;
|
|
85
|
+
findAncestor(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): NodeId | null | undefined;
|
|
86
|
+
findAncestors(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): Array<NodeId>;
|
|
87
|
+
findDescendant(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): NodeId | null | undefined;
|
|
88
|
+
findDescendants(nodeId: NodeId, fn: (nodeId: NodeId) => boolean): Array<NodeId>;
|
|
89
|
+
_assertHasNodeId(nodeId: NodeId): void;
|
|
90
|
+
}
|
|
91
|
+
export declare function mapVisitor<NodeId, TValue, TContext>(filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined, visit: GraphVisitor<TValue, TContext>): GraphVisitor<NodeId, TContext>;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { NodeId, ContentKey, Edge } from './types';
|
|
2
|
+
export type { GraphOpts } from './Graph';
|
|
3
|
+
export type { ContentGraphOpts, SerializedContentGraph } from './ContentGraph';
|
|
4
|
+
export { toNodeId, fromNodeId } from './types';
|
|
5
|
+
export { default as Graph, ALL_EDGE_TYPES, mapVisitor } from './Graph';
|
|
6
|
+
export { default as ContentGraph } from './ContentGraph';
|
|
7
|
+
export { BitSet } from './BitSet';
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NodeId = number;
|
|
2
|
+
export declare function toNodeId(x: number): NodeId;
|
|
3
|
+
export declare function fromNodeId(x: NodeId): number;
|
|
4
|
+
export type ContentKey = string;
|
|
5
|
+
export type Edge<TEdgeType extends number> = {
|
|
6
|
+
from: NodeId;
|
|
7
|
+
to: NodeId;
|
|
8
|
+
type: TEdgeType;
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/graph",
|
|
3
|
-
"version": "3.5.10-typescript-
|
|
3
|
+
"version": "3.5.10-typescript-e99c742e9.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,24 +10,24 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.ts",
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">= 16.0.0"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
20
|
"benchmark": "node ./benchmark/BitSet.js",
|
|
20
|
-
"check-ts": "tsc --
|
|
21
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@atlaspack/feature-flags": "2.19.3-typescript-
|
|
24
|
+
"@atlaspack/feature-flags": "2.19.3-typescript-e99c742e9.0",
|
|
24
25
|
"nullthrows": "^1.1.1"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
|
-
"@atlaspack/babel-register": "2.14.2-typescript-
|
|
28
|
+
"@atlaspack/babel-register": "2.14.2-typescript-e99c742e9.0",
|
|
28
29
|
"benny": "^3.7.1"
|
|
29
30
|
},
|
|
30
31
|
"type": "commonjs",
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
}
|
|
32
|
+
"gitHead": "e99c742e92175ac411d807daf2ba45d5bacebb58"
|
|
33
|
+
}
|