stack-typed 2.1.0 → 2.1.2
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/dist/cjs/index.cjs +552 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +548 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/stack-typed.js +563 -0
- package/dist/umd/stack-typed.js.map +1 -0
- package/dist/umd/stack-typed.min.js +9 -0
- package/dist/umd/stack-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -28
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* data-structure-typed
|
|
4
|
-
*
|
|
5
|
-
* @author Pablo Zeng
|
|
6
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
7
|
-
* @license MIT License
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = void 0;
|
|
11
|
-
const abstract_graph_1 = require("./abstract-graph");
|
|
12
|
-
const utils_1 = require("../../utils");
|
|
13
|
-
class DirectedVertex extends abstract_graph_1.AbstractVertex {
|
|
14
|
-
constructor(key, value) {
|
|
15
|
-
super(key, value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.DirectedVertex = DirectedVertex;
|
|
19
|
-
class DirectedEdge extends abstract_graph_1.AbstractEdge {
|
|
20
|
-
constructor(src, dest, weight, value) {
|
|
21
|
-
super(weight, value);
|
|
22
|
-
this.src = src;
|
|
23
|
-
this.dest = dest;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.DirectedEdge = DirectedEdge;
|
|
27
|
-
/**
|
|
28
|
-
* Directed graph implementation.
|
|
29
|
-
* @template V - Vertex value type.
|
|
30
|
-
* @template E - Edge value type.
|
|
31
|
-
* @template VO - Concrete vertex class (extends AbstractVertex<V>).
|
|
32
|
-
* @template EO - Concrete edge class (extends AbstractEdge<E>).
|
|
33
|
-
* @remarks Time O(1), Space O(1)
|
|
34
|
-
* @example examples will be generated by unit test
|
|
35
|
-
*/
|
|
36
|
-
class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
37
|
-
/**
|
|
38
|
-
* Construct a directed graph with runtime defaults.
|
|
39
|
-
* @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
40
|
-
* @remarks Time O(1), Space O(1)
|
|
41
|
-
*/
|
|
42
|
-
constructor(options) {
|
|
43
|
-
super(options);
|
|
44
|
-
this._outEdgeMap = new Map();
|
|
45
|
-
this._inEdgeMap = new Map();
|
|
46
|
-
}
|
|
47
|
-
get outEdgeMap() {
|
|
48
|
-
return this._outEdgeMap;
|
|
49
|
-
}
|
|
50
|
-
set outEdgeMap(v) {
|
|
51
|
-
this._outEdgeMap = v;
|
|
52
|
-
}
|
|
53
|
-
get inEdgeMap() {
|
|
54
|
-
return this._inEdgeMap;
|
|
55
|
-
}
|
|
56
|
-
set inEdgeMap(v) {
|
|
57
|
-
this._inEdgeMap = v;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Construct a directed graph from keys with value initializer `v => v`.
|
|
61
|
-
* @template K - Vertex key type.
|
|
62
|
-
* @param keys - Iterable of vertex keys.
|
|
63
|
-
* @returns DirectedGraph with all keys added.
|
|
64
|
-
* @remarks Time O(V), Space O(V)
|
|
65
|
-
*/
|
|
66
|
-
static fromKeys(keys) {
|
|
67
|
-
const g = new DirectedGraph({
|
|
68
|
-
vertexValueInitializer: (k) => k
|
|
69
|
-
});
|
|
70
|
-
for (const k of keys)
|
|
71
|
-
g.addVertex(k);
|
|
72
|
-
return g;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Construct a directed graph from `[key, value]` entries.
|
|
76
|
-
* @template V - Vertex value type.
|
|
77
|
-
* @param entries - Iterable of `[key, value]` pairs.
|
|
78
|
-
* @returns DirectedGraph with all vertices added.
|
|
79
|
-
* @remarks Time O(V), Space O(V)
|
|
80
|
-
*/
|
|
81
|
-
static fromEntries(entries) {
|
|
82
|
-
const g = new DirectedGraph();
|
|
83
|
-
for (const [k, v] of entries)
|
|
84
|
-
g.addVertex(k, v);
|
|
85
|
-
return g;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a directed vertex instance. Does not insert into the graph.
|
|
89
|
-
* @param key - Vertex identifier.
|
|
90
|
-
* @param value - Optional payload.
|
|
91
|
-
* @returns Concrete vertex instance.
|
|
92
|
-
* @remarks Time O(1), Space O(1)
|
|
93
|
-
*/
|
|
94
|
-
createVertex(key, value) {
|
|
95
|
-
return new DirectedVertex(key, value);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Create a directed edge instance. Does not insert into the graph.
|
|
99
|
-
* @param src - Source vertex key.
|
|
100
|
-
* @param dest - Destination vertex key.
|
|
101
|
-
* @param weight - Edge weight; defaults to `defaultEdgeWeight`.
|
|
102
|
-
* @param value - Edge payload.
|
|
103
|
-
* @returns Concrete edge instance.
|
|
104
|
-
* @remarks Time O(1), Space O(1)
|
|
105
|
-
*/
|
|
106
|
-
createEdge(src, dest, weight, value) {
|
|
107
|
-
var _a;
|
|
108
|
-
return new DirectedEdge(src, dest, (_a = weight !== null && weight !== void 0 ? weight : this.options.defaultEdgeWeight) !== null && _a !== void 0 ? _a : 1, value);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get the unique edge from `src` to `dest`, if present.
|
|
112
|
-
* @param srcOrKey - Source vertex or key.
|
|
113
|
-
* @param destOrKey - Destination vertex or key.
|
|
114
|
-
* @returns Edge instance or `undefined`.
|
|
115
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
116
|
-
*/
|
|
117
|
-
getEdge(srcOrKey, destOrKey) {
|
|
118
|
-
let edgeMap = [];
|
|
119
|
-
if (srcOrKey !== undefined && destOrKey !== undefined) {
|
|
120
|
-
const src = this._getVertex(srcOrKey);
|
|
121
|
-
const dest = this._getVertex(destOrKey);
|
|
122
|
-
if (src && dest) {
|
|
123
|
-
const srcOutEdges = this._outEdgeMap.get(src);
|
|
124
|
-
if (srcOutEdges) {
|
|
125
|
-
edgeMap = srcOutEdges.filter(edge => edge.dest === dest.key);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return edgeMap[0] || undefined;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Delete edge `src -> dest` if present.
|
|
133
|
-
* @param srcOrKey - Source vertex or key.
|
|
134
|
-
* @param destOrKey - Destination vertex or key.
|
|
135
|
-
* @returns Removed edge or `undefined`.
|
|
136
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
137
|
-
*/
|
|
138
|
-
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
139
|
-
const src = this._getVertex(srcOrKey);
|
|
140
|
-
const dest = this._getVertex(destOrKey);
|
|
141
|
-
let removed = undefined;
|
|
142
|
-
if (!src || !dest) {
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
|
-
const srcOutEdges = this._outEdgeMap.get(src);
|
|
146
|
-
if (srcOutEdges) {
|
|
147
|
-
(0, utils_1.arrayRemove)(srcOutEdges, (edge) => edge.dest === dest.key);
|
|
148
|
-
}
|
|
149
|
-
const destInEdges = this._inEdgeMap.get(dest);
|
|
150
|
-
if (destInEdges) {
|
|
151
|
-
removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.src === src.key)[0] || undefined;
|
|
152
|
-
}
|
|
153
|
-
return removed;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Delete an edge by instance or by `(srcKey, destKey)`.
|
|
157
|
-
* @param edgeOrSrcVertexKey - Edge instance or source vertex/key.
|
|
158
|
-
* @param destVertexKey - Optional destination vertex/key when deleting by pair.
|
|
159
|
-
* @returns Removed edge or `undefined`.
|
|
160
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
161
|
-
*/
|
|
162
|
-
deleteEdge(edgeOrSrcVertexKey, destVertexKey) {
|
|
163
|
-
let removed = undefined;
|
|
164
|
-
let src, dest;
|
|
165
|
-
if (this.isVertexKey(edgeOrSrcVertexKey)) {
|
|
166
|
-
if (this.isVertexKey(destVertexKey)) {
|
|
167
|
-
src = this._getVertex(edgeOrSrcVertexKey);
|
|
168
|
-
dest = this._getVertex(destVertexKey);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
src = this._getVertex(edgeOrSrcVertexKey.src);
|
|
176
|
-
dest = this._getVertex(edgeOrSrcVertexKey.dest);
|
|
177
|
-
}
|
|
178
|
-
if (src && dest) {
|
|
179
|
-
const srcOutEdges = this._outEdgeMap.get(src);
|
|
180
|
-
if (srcOutEdges && srcOutEdges.length > 0) {
|
|
181
|
-
(0, utils_1.arrayRemove)(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest === null || dest === void 0 ? void 0 : dest.key));
|
|
182
|
-
}
|
|
183
|
-
const destInEdges = this._inEdgeMap.get(dest);
|
|
184
|
-
if (destInEdges && destInEdges.length > 0) {
|
|
185
|
-
removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.src === src.key && edge.dest === dest.key)[0];
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return removed;
|
|
189
|
-
}
|
|
190
|
-
deleteVertex(vertexOrKey) {
|
|
191
|
-
let vertexKey;
|
|
192
|
-
let vertex;
|
|
193
|
-
if (this.isVertexKey(vertexOrKey)) {
|
|
194
|
-
vertex = this.getVertex(vertexOrKey);
|
|
195
|
-
vertexKey = vertexOrKey;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
vertex = vertexOrKey;
|
|
199
|
-
vertexKey = this._getVertexKey(vertexOrKey);
|
|
200
|
-
}
|
|
201
|
-
if (vertex) {
|
|
202
|
-
/**
|
|
203
|
-
* One-step neighbors following outgoing edges.
|
|
204
|
-
* @param vertexOrKey - Vertex or key.
|
|
205
|
-
* @returns Array of neighbor vertices.
|
|
206
|
-
* @remarks Time O(deg_out), Space O(deg_out)
|
|
207
|
-
*/
|
|
208
|
-
const neighbors = this.getNeighbors(vertex);
|
|
209
|
-
for (const neighbor of neighbors) {
|
|
210
|
-
this.deleteEdgeSrcToDest(vertex, neighbor);
|
|
211
|
-
}
|
|
212
|
-
this._outEdgeMap.delete(vertex);
|
|
213
|
-
this._inEdgeMap.delete(vertex);
|
|
214
|
-
}
|
|
215
|
-
return this._vertexMap.delete(vertexKey);
|
|
216
|
-
}
|
|
217
|
-
deleteEdgesBetween(v1, v2) {
|
|
218
|
-
const removed = [];
|
|
219
|
-
if (v1 && v2) {
|
|
220
|
-
const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
|
|
221
|
-
const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
|
|
222
|
-
if (v1ToV2)
|
|
223
|
-
removed.push(v1ToV2);
|
|
224
|
-
if (v2ToV1)
|
|
225
|
-
removed.push(v2ToV1);
|
|
226
|
-
}
|
|
227
|
-
return removed;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Incoming edges of a vertex.
|
|
231
|
-
* @param vertexOrKey - Vertex or key.
|
|
232
|
-
* @returns Array of incoming edges.
|
|
233
|
-
* @remarks Time O(deg_in), Space O(deg_in)
|
|
234
|
-
*/
|
|
235
|
-
incomingEdgesOf(vertexOrKey) {
|
|
236
|
-
const target = this._getVertex(vertexOrKey);
|
|
237
|
-
if (target) {
|
|
238
|
-
return this.inEdgeMap.get(target) || [];
|
|
239
|
-
}
|
|
240
|
-
return [];
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Outgoing edges of a vertex.
|
|
244
|
-
* @param vertexOrKey - Vertex or key.
|
|
245
|
-
* @returns Array of outgoing edges.
|
|
246
|
-
* @remarks Time O(deg_out), Space O(deg_out)
|
|
247
|
-
*/
|
|
248
|
-
outgoingEdgesOf(vertexOrKey) {
|
|
249
|
-
const target = this._getVertex(vertexOrKey);
|
|
250
|
-
if (target) {
|
|
251
|
-
return this._outEdgeMap.get(target) || [];
|
|
252
|
-
}
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Degree (in + out) of a vertex.
|
|
257
|
-
* @param vertexOrKey - Vertex or key.
|
|
258
|
-
* @returns Non-negative integer.
|
|
259
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
260
|
-
*/
|
|
261
|
-
degreeOf(vertexOrKey) {
|
|
262
|
-
/**
|
|
263
|
-
* In-degree of a vertex.
|
|
264
|
-
* @param vertexOrKey - Vertex or key.
|
|
265
|
-
* @returns Non-negative integer.
|
|
266
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
267
|
-
*/
|
|
268
|
-
/**
|
|
269
|
-
* Out-degree of a vertex.
|
|
270
|
-
* @param vertexOrKey - Vertex or key.
|
|
271
|
-
* @returns Non-negative integer.
|
|
272
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
273
|
-
*/
|
|
274
|
-
return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
|
|
275
|
-
}
|
|
276
|
-
inDegreeOf(vertexOrKey) {
|
|
277
|
-
return this.incomingEdgesOf(vertexOrKey).length;
|
|
278
|
-
}
|
|
279
|
-
outDegreeOf(vertexOrKey) {
|
|
280
|
-
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* All incident edges of a vertex.
|
|
284
|
-
* @param vertexOrKey - Vertex or key.
|
|
285
|
-
* @returns Array of incident edges.
|
|
286
|
-
* @remarks Time O(deg_in + deg_out), Space O(deg_in + deg_out)
|
|
287
|
-
*/
|
|
288
|
-
edgesOf(vertexOrKey) {
|
|
289
|
-
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
290
|
-
}
|
|
291
|
-
getEdgeSrc(e) {
|
|
292
|
-
return this._getVertex(e.src);
|
|
293
|
-
}
|
|
294
|
-
getEdgeDest(e) {
|
|
295
|
-
return this._getVertex(e.dest);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Direct children reachable by one outgoing edge.
|
|
299
|
-
* @param vertex - Vertex or key.
|
|
300
|
-
* @returns Array of neighbor vertices.
|
|
301
|
-
* @remarks Time O(deg_out), Space O(deg_out)
|
|
302
|
-
*/
|
|
303
|
-
getDestinations(vertex) {
|
|
304
|
-
if (vertex === undefined) {
|
|
305
|
-
return [];
|
|
306
|
-
}
|
|
307
|
-
const destinations = [];
|
|
308
|
-
const outgoingEdges = this.outgoingEdgesOf(vertex);
|
|
309
|
-
for (const outEdge of outgoingEdges) {
|
|
310
|
-
const child = this.getEdgeDest(outEdge);
|
|
311
|
-
if (child) {
|
|
312
|
-
destinations.push(child);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return destinations;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Topological sort if DAG; returns `undefined` if a cycle exists.
|
|
319
|
-
* @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
|
|
320
|
-
* @returns Array of keys/vertices, or `undefined` when cycle is found.
|
|
321
|
-
* @remarks Time O(V + E), Space O(V)
|
|
322
|
-
*/
|
|
323
|
-
topologicalSort(propertyName) {
|
|
324
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
325
|
-
const statusMap = new Map();
|
|
326
|
-
for (const entry of this.vertexMap) {
|
|
327
|
-
statusMap.set(entry[1], 0);
|
|
328
|
-
}
|
|
329
|
-
let sorted = [];
|
|
330
|
-
let hasCycle = false;
|
|
331
|
-
const dfs = (cur) => {
|
|
332
|
-
statusMap.set(cur, 1);
|
|
333
|
-
const children = this.getDestinations(cur);
|
|
334
|
-
for (const child of children) {
|
|
335
|
-
const childStatus = statusMap.get(child);
|
|
336
|
-
if (childStatus === 0) {
|
|
337
|
-
dfs(child);
|
|
338
|
-
}
|
|
339
|
-
else if (childStatus === 1) {
|
|
340
|
-
hasCycle = true;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
statusMap.set(cur, 2);
|
|
344
|
-
sorted.push(cur);
|
|
345
|
-
};
|
|
346
|
-
for (const entry of this.vertexMap) {
|
|
347
|
-
if (statusMap.get(entry[1]) === 0) {
|
|
348
|
-
dfs(entry[1]);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (hasCycle)
|
|
352
|
-
return undefined;
|
|
353
|
-
if (propertyName === 'key')
|
|
354
|
-
sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
|
|
355
|
-
return sorted.reverse();
|
|
356
|
-
}
|
|
357
|
-
edgeSet() {
|
|
358
|
-
let edgeMap = [];
|
|
359
|
-
this._outEdgeMap.forEach(outEdges => {
|
|
360
|
-
edgeMap = [...edgeMap, ...outEdges];
|
|
361
|
-
});
|
|
362
|
-
return edgeMap;
|
|
363
|
-
}
|
|
364
|
-
getNeighbors(vertexOrKey) {
|
|
365
|
-
const neighbors = [];
|
|
366
|
-
const vertex = this._getVertex(vertexOrKey);
|
|
367
|
-
if (vertex) {
|
|
368
|
-
const outEdges = this.outgoingEdgesOf(vertex);
|
|
369
|
-
for (const outEdge of outEdges) {
|
|
370
|
-
const neighbor = this._getVertex(outEdge.dest);
|
|
371
|
-
if (neighbor) {
|
|
372
|
-
neighbors.push(neighbor);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return neighbors;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Resolve an edge's `[src, dest]` endpoints to vertex instances.
|
|
380
|
-
* @param edge - Edge instance.
|
|
381
|
-
* @returns `[src, dest]` or `undefined` if either endpoint is missing.
|
|
382
|
-
* @remarks Time O(1), Space O(1)
|
|
383
|
-
*/
|
|
384
|
-
getEndsOfEdge(edge) {
|
|
385
|
-
if (!this.hasEdge(edge.src, edge.dest)) {
|
|
386
|
-
return undefined;
|
|
387
|
-
}
|
|
388
|
-
const v1 = this._getVertex(edge.src);
|
|
389
|
-
const v2 = this._getVertex(edge.dest);
|
|
390
|
-
if (v1 && v2) {
|
|
391
|
-
return [v1, v2];
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
return undefined;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Whether the graph has no vertices and no edges.
|
|
399
|
-
* @remarks Time O(1), Space O(1)
|
|
400
|
-
*/
|
|
401
|
-
isEmpty() {
|
|
402
|
-
return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Remove all vertices and edges.
|
|
406
|
-
* @remarks Time O(V + E), Space O(1)
|
|
407
|
-
*/
|
|
408
|
-
clear() {
|
|
409
|
-
this._vertexMap = new Map();
|
|
410
|
-
this._inEdgeMap = new Map();
|
|
411
|
-
this._outEdgeMap = new Map();
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Deep clone as the same concrete class.
|
|
415
|
-
* @returns A new graph of the same concrete class (`this` type).
|
|
416
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
417
|
-
*/
|
|
418
|
-
clone() {
|
|
419
|
-
return super.clone();
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Tarjan's algorithm for strongly connected components.
|
|
423
|
-
* @returns `{ dfnMap, lowMap, SCCs }`.
|
|
424
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
425
|
-
*/
|
|
426
|
-
tarjan() {
|
|
427
|
-
const dfnMap = new Map();
|
|
428
|
-
const lowMap = new Map();
|
|
429
|
-
const SCCs = new Map();
|
|
430
|
-
let time = 0;
|
|
431
|
-
const stack = [];
|
|
432
|
-
const inStack = new Set();
|
|
433
|
-
const dfs = (vertex) => {
|
|
434
|
-
dfnMap.set(vertex, time);
|
|
435
|
-
lowMap.set(vertex, time);
|
|
436
|
-
time++;
|
|
437
|
-
stack.push(vertex);
|
|
438
|
-
inStack.add(vertex);
|
|
439
|
-
const neighbors = this.getNeighbors(vertex);
|
|
440
|
-
for (const neighbor of neighbors) {
|
|
441
|
-
if (!dfnMap.has(neighbor)) {
|
|
442
|
-
dfs(neighbor);
|
|
443
|
-
lowMap.set(vertex, Math.min(lowMap.get(vertex), lowMap.get(neighbor)));
|
|
444
|
-
}
|
|
445
|
-
else if (inStack.has(neighbor)) {
|
|
446
|
-
lowMap.set(vertex, Math.min(lowMap.get(vertex), dfnMap.get(neighbor)));
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
if (dfnMap.get(vertex) === lowMap.get(vertex)) {
|
|
450
|
-
const SCC = [];
|
|
451
|
-
let poppedVertex;
|
|
452
|
-
do {
|
|
453
|
-
poppedVertex = stack.pop();
|
|
454
|
-
inStack.delete(poppedVertex);
|
|
455
|
-
SCC.push(poppedVertex);
|
|
456
|
-
} while (poppedVertex !== vertex);
|
|
457
|
-
SCCs.set(SCCs.size, SCC);
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
for (const vertex of this.vertexMap.values()) {
|
|
461
|
-
if (!dfnMap.has(vertex)) {
|
|
462
|
-
dfs(vertex);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return { dfnMap, lowMap, SCCs };
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* DFN index map computed by `tarjan()`.
|
|
469
|
-
* @returns Map from vertex to DFN index.
|
|
470
|
-
* @remarks Time O(V), Space O(V)
|
|
471
|
-
*/
|
|
472
|
-
getDFNMap() {
|
|
473
|
-
return this.tarjan().dfnMap;
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* LOW link map computed by `tarjan()`.
|
|
477
|
-
* @returns Map from vertex to LOW value.
|
|
478
|
-
* @remarks Time O(V), Space O(V)
|
|
479
|
-
*/
|
|
480
|
-
getLowMap() {
|
|
481
|
-
return this.tarjan().lowMap;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Strongly connected components computed by `tarjan()`.
|
|
485
|
-
* @returns Map from SCC id to vertices.
|
|
486
|
-
* @remarks Time O(#SCC + V), Space O(V)
|
|
487
|
-
*/
|
|
488
|
-
getSCCs() {
|
|
489
|
-
return this.tarjan().SCCs;
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Internal hook to attach a directed edge into adjacency maps.
|
|
493
|
-
* @param edge - Edge instance.
|
|
494
|
-
* @returns `true` if inserted; otherwise `false`.
|
|
495
|
-
* @remarks Time O(1) avg, Space O(1)
|
|
496
|
-
*/
|
|
497
|
-
_addEdge(edge) {
|
|
498
|
-
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
const srcVertex = this._getVertex(edge.src);
|
|
502
|
-
const destVertex = this._getVertex(edge.dest);
|
|
503
|
-
if (srcVertex && destVertex) {
|
|
504
|
-
const srcOutEdges = this._outEdgeMap.get(srcVertex);
|
|
505
|
-
if (srcOutEdges) {
|
|
506
|
-
srcOutEdges.push(edge);
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
this._outEdgeMap.set(srcVertex, [edge]);
|
|
510
|
-
}
|
|
511
|
-
const destInEdges = this._inEdgeMap.get(destVertex);
|
|
512
|
-
if (destInEdges) {
|
|
513
|
-
destInEdges.push(edge);
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
this._inEdgeMap.set(destVertex, [edge]);
|
|
517
|
-
}
|
|
518
|
-
return true;
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
return false;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
exports.DirectedGraph = DirectedGraph;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./abstract-graph"), exports);
|
|
18
|
-
__exportStar(require("./directed-graph"), exports);
|
|
19
|
-
__exportStar(require("./undirected-graph"), exports);
|
|
20
|
-
__exportStar(require("./map-graph"), exports);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { MapGraphCoordinate, VertexKey } from '../../types';
|
|
9
|
-
import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
|
|
10
|
-
export declare class MapVertex<V = any> extends DirectedVertex<V> {
|
|
11
|
-
lat: number;
|
|
12
|
-
long: number;
|
|
13
|
-
constructor(key: VertexKey, value: V, lat: number, long: number);
|
|
14
|
-
}
|
|
15
|
-
export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
16
|
-
constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Directed graph variant carrying geospatial coordinates.
|
|
20
|
-
* @template V - Vertex value type.
|
|
21
|
-
* @template E - Edge value type.
|
|
22
|
-
* @template VO - Concrete vertex class (MapVertex<V>).
|
|
23
|
-
* @template EO - Concrete edge class (MapEdge<E>).
|
|
24
|
-
* @remarks Time O(1), Space O(1)
|
|
25
|
-
* @example examples will be generated by unit test
|
|
26
|
-
*/
|
|
27
|
-
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
28
|
-
/**
|
|
29
|
-
* Construct a MapGraph.
|
|
30
|
-
* @param originCoord - Origin coordinate `[lat, long]` used as default.
|
|
31
|
-
* @param bottomRight - Optional bottom-right coordinate for bounding boxes.
|
|
32
|
-
* @remarks Time O(1), Space O(1)
|
|
33
|
-
*/
|
|
34
|
-
constructor(originCoord: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
|
|
35
|
-
protected _originCoord: MapGraphCoordinate;
|
|
36
|
-
get originCoord(): MapGraphCoordinate;
|
|
37
|
-
protected _bottomRight: MapGraphCoordinate | undefined;
|
|
38
|
-
get bottomRight(): MapGraphCoordinate | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Create a map vertex with optional coordinates.
|
|
41
|
-
* @param key - Vertex identifier.
|
|
42
|
-
* @param value - Optional payload.
|
|
43
|
-
* @param lat - Latitude (defaults to `originCoord[0]`).
|
|
44
|
-
* @param long - Longitude (defaults to `originCoord[1]`).
|
|
45
|
-
* @returns MapVertex instance.
|
|
46
|
-
* @remarks Time O(1), Space O(1)
|
|
47
|
-
*/
|
|
48
|
-
createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
|
|
49
|
-
/**
|
|
50
|
-
* Create a map edge (directed) with optional weight/value.
|
|
51
|
-
* @param src - Source key.
|
|
52
|
-
* @param dest - Destination key.
|
|
53
|
-
* @param weight - Edge weight.
|
|
54
|
-
* @param value - Edge payload.
|
|
55
|
-
* @returns MapEdge instance.
|
|
56
|
-
* @remarks Time O(1), Space O(1)
|
|
57
|
-
*/
|
|
58
|
-
createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
|
|
59
|
-
/**
|
|
60
|
-
* Deep clone as the same concrete class.
|
|
61
|
-
* @returns A new graph of the same concrete class (`this` type).
|
|
62
|
-
* @remarks Time O(V + E), Space O(V + E)
|
|
63
|
-
*/
|
|
64
|
-
clone(): this;
|
|
65
|
-
/**
|
|
66
|
-
* Include `originCoord` and `bottomRight` so `clone()/filter()` preserve geospatial settings.
|
|
67
|
-
* @returns Options bag extending super snapshot.
|
|
68
|
-
* @remarks Time O(1), Space O(1)
|
|
69
|
-
*/
|
|
70
|
-
protected _snapshotOptions(): Record<string, unknown>;
|
|
71
|
-
/**
|
|
72
|
-
* Re-create a same-species MapGraph instance from snapshot options.
|
|
73
|
-
* @param options - Snapshot options providing `originCoord`/`bottomRight`.
|
|
74
|
-
* @returns Empty MapGraph instance of `this` type.
|
|
75
|
-
* @remarks Time O(1), Space O(1)
|
|
76
|
-
*/
|
|
77
|
-
protected _createInstance(options?: Partial<Record<string, unknown>>): this;
|
|
78
|
-
}
|