data-structure-typed 0.8.17 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +7 -0
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +2 -0
- package/dist/data-structures/index.js +2 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/index.d.ts +1 -0
- package/dist/data-structures/queue/index.js +1 -0
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +2 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/index.ts +1 -0
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
|
@@ -1,63 +1,136 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Trie = exports.TrieNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.
|
|
15
|
+
var TrieNode = /** @class */ (function () {
|
|
16
|
+
function TrieNode(v) {
|
|
17
|
+
this._value = v;
|
|
7
18
|
this._isEnd = false;
|
|
19
|
+
this._children = new Map();
|
|
8
20
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
Object.defineProperty(TrieNode.prototype, "children", {
|
|
22
|
+
get: function () {
|
|
23
|
+
return this._children;
|
|
24
|
+
},
|
|
25
|
+
set: function (v) {
|
|
26
|
+
this._children = v;
|
|
27
|
+
},
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: true
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(TrieNode.prototype, "isEnd", {
|
|
32
|
+
get: function () {
|
|
33
|
+
return this._isEnd;
|
|
34
|
+
},
|
|
35
|
+
set: function (v) {
|
|
36
|
+
this._isEnd = v;
|
|
37
|
+
},
|
|
38
|
+
enumerable: false,
|
|
39
|
+
configurable: true
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(TrieNode.prototype, "val", {
|
|
42
|
+
get: function () {
|
|
43
|
+
return this._value;
|
|
44
|
+
},
|
|
45
|
+
set: function (v) {
|
|
46
|
+
this._value = v;
|
|
47
|
+
},
|
|
48
|
+
enumerable: false,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
return TrieNode;
|
|
52
|
+
}());
|
|
22
53
|
exports.TrieNode = TrieNode;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
54
|
+
var Trie = /** @class */ (function () {
|
|
55
|
+
function Trie(words) {
|
|
56
|
+
var e_1, _a;
|
|
57
|
+
this._root = new TrieNode('');
|
|
58
|
+
if (words) {
|
|
59
|
+
try {
|
|
60
|
+
for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
|
|
61
|
+
var i = words_1_1.value;
|
|
62
|
+
this.put(i);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
66
|
+
finally {
|
|
67
|
+
try {
|
|
68
|
+
if (words_1_1 && !words_1_1.done && (_a = words_1.return)) _a.call(words_1);
|
|
69
|
+
}
|
|
70
|
+
finally { if (e_1) throw e_1.error; }
|
|
71
|
+
}
|
|
72
|
+
}
|
|
32
73
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
Object.defineProperty(Trie.prototype, "root", {
|
|
75
|
+
get: function () {
|
|
76
|
+
return this._root;
|
|
77
|
+
},
|
|
78
|
+
set: function (v) {
|
|
79
|
+
this._root = v;
|
|
80
|
+
},
|
|
81
|
+
enumerable: false,
|
|
82
|
+
configurable: true
|
|
83
|
+
});
|
|
84
|
+
Trie.prototype.put = function (word) {
|
|
85
|
+
var e_2, _a;
|
|
86
|
+
var cur = this._root;
|
|
87
|
+
try {
|
|
88
|
+
for (var word_1 = __values(word), word_1_1 = word_1.next(); !word_1_1.done; word_1_1 = word_1.next()) {
|
|
89
|
+
var c = word_1_1.value;
|
|
90
|
+
var nodeC = cur.children.get(c);
|
|
91
|
+
if (!nodeC) {
|
|
92
|
+
nodeC = new TrieNode(c);
|
|
93
|
+
cur.children.set(c, nodeC);
|
|
94
|
+
}
|
|
95
|
+
cur = nodeC;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
99
|
+
finally {
|
|
100
|
+
try {
|
|
101
|
+
if (word_1_1 && !word_1_1.done && (_a = word_1.return)) _a.call(word_1);
|
|
102
|
+
}
|
|
103
|
+
finally { if (e_2) throw e_2.error; }
|
|
42
104
|
}
|
|
43
105
|
cur.isEnd = true;
|
|
44
106
|
return true;
|
|
45
|
-
}
|
|
46
|
-
has(input) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
107
|
+
};
|
|
108
|
+
Trie.prototype.has = function (input) {
|
|
109
|
+
var e_3, _a;
|
|
110
|
+
var cur = this._root;
|
|
111
|
+
try {
|
|
112
|
+
for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
|
|
113
|
+
var c = input_1_1.value;
|
|
114
|
+
var nodeC = cur.children.get(c);
|
|
115
|
+
if (!nodeC)
|
|
116
|
+
return false;
|
|
117
|
+
cur = nodeC;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
121
|
+
finally {
|
|
122
|
+
try {
|
|
123
|
+
if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
|
|
124
|
+
}
|
|
125
|
+
finally { if (e_3) throw e_3.error; }
|
|
53
126
|
}
|
|
54
127
|
return cur.isEnd;
|
|
55
|
-
}
|
|
56
|
-
remove(word) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
128
|
+
};
|
|
129
|
+
Trie.prototype.remove = function (word) {
|
|
130
|
+
var isDeleted = false;
|
|
131
|
+
var dfs = function (cur, i) {
|
|
132
|
+
var char = word[i];
|
|
133
|
+
var child = cur.children.get(char);
|
|
61
134
|
if (child) {
|
|
62
135
|
if (i === word.length - 1) {
|
|
63
136
|
if (child.isEnd) {
|
|
@@ -72,7 +145,7 @@ class Trie {
|
|
|
72
145
|
}
|
|
73
146
|
return false;
|
|
74
147
|
}
|
|
75
|
-
|
|
148
|
+
var res = dfs(child, i + 1);
|
|
76
149
|
if (res && !cur.isEnd && child.children.size === 0) {
|
|
77
150
|
cur.children.delete(char);
|
|
78
151
|
return true;
|
|
@@ -83,59 +156,140 @@ class Trie {
|
|
|
83
156
|
};
|
|
84
157
|
dfs(this.root, 0);
|
|
85
158
|
return isDeleted;
|
|
86
|
-
}
|
|
159
|
+
};
|
|
87
160
|
// --- start additional methods ---
|
|
88
161
|
/**
|
|
89
162
|
* Only can present as a prefix, not a word
|
|
90
163
|
* @param input
|
|
91
164
|
*/
|
|
92
|
-
isAbsPrefix(input) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
165
|
+
Trie.prototype.isAbsPrefix = function (input) {
|
|
166
|
+
var e_4, _a;
|
|
167
|
+
var cur = this._root;
|
|
168
|
+
try {
|
|
169
|
+
for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
|
|
170
|
+
var c = input_2_1.value;
|
|
171
|
+
var nodeC = cur.children.get(c);
|
|
172
|
+
if (!nodeC)
|
|
173
|
+
return false;
|
|
174
|
+
cur = nodeC;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
178
|
+
finally {
|
|
179
|
+
try {
|
|
180
|
+
if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
|
|
181
|
+
}
|
|
182
|
+
finally { if (e_4) throw e_4.error; }
|
|
99
183
|
}
|
|
100
184
|
return !cur.isEnd;
|
|
101
|
-
}
|
|
185
|
+
};
|
|
102
186
|
/**
|
|
103
|
-
* Can present as a prefix or word
|
|
187
|
+
* Can present as a abs prefix or word
|
|
104
188
|
* @param input
|
|
105
189
|
*/
|
|
106
|
-
isPrefix(input) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
190
|
+
Trie.prototype.isPrefix = function (input) {
|
|
191
|
+
var e_5, _a;
|
|
192
|
+
var cur = this._root;
|
|
193
|
+
try {
|
|
194
|
+
for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
|
|
195
|
+
var c = input_3_1.value;
|
|
196
|
+
var nodeC = cur.children.get(c);
|
|
197
|
+
if (!nodeC)
|
|
198
|
+
return false;
|
|
199
|
+
cur = nodeC;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
203
|
+
finally {
|
|
204
|
+
try {
|
|
205
|
+
if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
|
|
206
|
+
}
|
|
207
|
+
finally { if (e_5) throw e_5.error; }
|
|
113
208
|
}
|
|
114
209
|
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Check if the input string is the common prefix of all the words
|
|
213
|
+
* @param input
|
|
214
|
+
*/
|
|
215
|
+
Trie.prototype.isCommonPrefix = function (input) {
|
|
216
|
+
var commonPre = '';
|
|
217
|
+
var dfs = function (cur) {
|
|
218
|
+
commonPre += cur.val;
|
|
219
|
+
if (commonPre === input)
|
|
220
|
+
return;
|
|
221
|
+
if (cur.isEnd)
|
|
222
|
+
return;
|
|
223
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
224
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
225
|
+
else
|
|
226
|
+
return;
|
|
227
|
+
};
|
|
228
|
+
dfs(this._root);
|
|
229
|
+
return commonPre === input;
|
|
230
|
+
};
|
|
231
|
+
// Retrieve the longest common prefix of all the words
|
|
232
|
+
Trie.prototype.getLongestCommonPrefix = function () {
|
|
233
|
+
var commonPre = '';
|
|
234
|
+
var dfs = function (cur) {
|
|
235
|
+
commonPre += cur.val;
|
|
236
|
+
if (cur.isEnd)
|
|
237
|
+
return;
|
|
238
|
+
if (cur && cur.children && cur.children.size === 1)
|
|
239
|
+
dfs(Array.from(cur.children.values())[0]);
|
|
240
|
+
else
|
|
241
|
+
return;
|
|
242
|
+
};
|
|
243
|
+
dfs(this._root);
|
|
244
|
+
return commonPre;
|
|
245
|
+
};
|
|
246
|
+
Trie.prototype.getAll = function (prefix) {
|
|
247
|
+
var e_6, _a;
|
|
248
|
+
if (prefix === void 0) { prefix = ''; }
|
|
249
|
+
var words = [];
|
|
118
250
|
function dfs(node, word) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
251
|
+
var e_7, _a;
|
|
252
|
+
try {
|
|
253
|
+
for (var _b = __values(node.children.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
254
|
+
var char = _c.value;
|
|
255
|
+
var charNode = node.children.get(char);
|
|
256
|
+
if (charNode !== undefined) {
|
|
257
|
+
dfs(charNode, word.concat(char));
|
|
258
|
+
}
|
|
123
259
|
}
|
|
124
260
|
}
|
|
261
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
262
|
+
finally {
|
|
263
|
+
try {
|
|
264
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
265
|
+
}
|
|
266
|
+
finally { if (e_7) throw e_7.error; }
|
|
267
|
+
}
|
|
125
268
|
if (node.isEnd) {
|
|
126
269
|
words.push(word);
|
|
127
270
|
}
|
|
128
271
|
}
|
|
129
|
-
|
|
272
|
+
var startNode = this._root;
|
|
130
273
|
if (prefix) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
274
|
+
try {
|
|
275
|
+
for (var prefix_1 = __values(prefix), prefix_1_1 = prefix_1.next(); !prefix_1_1.done; prefix_1_1 = prefix_1.next()) {
|
|
276
|
+
var c = prefix_1_1.value;
|
|
277
|
+
var nodeC = startNode.children.get(c);
|
|
278
|
+
if (nodeC)
|
|
279
|
+
startNode = nodeC;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
283
|
+
finally {
|
|
284
|
+
try {
|
|
285
|
+
if (prefix_1_1 && !prefix_1_1.done && (_a = prefix_1.return)) _a.call(prefix_1);
|
|
286
|
+
}
|
|
287
|
+
finally { if (e_6) throw e_6.error; }
|
|
135
288
|
}
|
|
136
289
|
}
|
|
137
290
|
dfs(startNode, prefix);
|
|
138
291
|
return words;
|
|
139
|
-
}
|
|
140
|
-
|
|
292
|
+
};
|
|
293
|
+
return Trie;
|
|
294
|
+
}());
|
|
141
295
|
exports.Trie = Trie;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type VertexId = string | number;
|
|
2
|
+
export type DijkstraResult<V> = {
|
|
3
|
+
distMap: Map<V, number>;
|
|
4
|
+
preMap: Map<V, V | null>;
|
|
5
|
+
seen: Set<V>;
|
|
6
|
+
paths: V[][];
|
|
7
|
+
minDist: number;
|
|
8
|
+
minPath: V[];
|
|
9
|
+
} | null;
|
|
10
|
+
export interface IGraph<V, E> {
|
|
11
|
+
containsVertex(vertexOrId: V | VertexId): boolean;
|
|
12
|
+
getVertex(vertexOrId: VertexId | V): V | null;
|
|
13
|
+
getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
14
|
+
vertexSet(): Map<VertexId, V>;
|
|
15
|
+
addVertex(v: V): boolean;
|
|
16
|
+
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
17
|
+
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
18
|
+
degreeOf(vertexOrId: V | VertexId): number;
|
|
19
|
+
edgesOf(vertexOrId: V | VertexId): E[];
|
|
20
|
+
containsEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
21
|
+
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
22
|
+
edgeSet(): E[];
|
|
23
|
+
addEdge(edge: E): boolean;
|
|
24
|
+
removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
25
|
+
removeEdge(edge: E): E | null;
|
|
26
|
+
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
27
|
+
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
28
|
+
getNeighbors(vertexOrId: V | VertexId): V[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BinaryTreeNode } from "../binary-tree";
|
|
2
|
+
export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
|
|
3
|
+
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
4
|
+
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
5
|
+
export type BinaryTreeNodeId = number;
|
|
6
|
+
export type BinaryTreeDeleted<T> = {
|
|
7
|
+
deleted: BinaryTreeNode<T> | null | undefined;
|
|
8
|
+
needBalanced: BinaryTreeNode<T> | null;
|
|
9
|
+
};
|
|
10
|
+
export type ResultByProperty<T> = T | BinaryTreeNode<T> | number | BinaryTreeNodeId;
|
|
11
|
+
export type ResultsByProperty<T> = ResultByProperty<T>[];
|
|
12
|
+
export interface BinaryTreeNodeObj<T> {
|
|
13
|
+
id: BinaryTreeNodeId;
|
|
14
|
+
val: T;
|
|
15
|
+
count?: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BSTNode } from '../binary-tree';
|
|
2
|
+
import type { BinaryTreeNodeId } from './binary-tree';
|
|
3
|
+
export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
|
|
4
|
+
export type BSTDeletedResult<T> = {
|
|
5
|
+
deleted: BSTNode<T> | null;
|
|
6
|
+
needBalanced: BSTNode<T> | null;
|
|
7
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VertexId } from './abstract-graph';
|
|
2
|
+
export interface IDirectedGraph<V, E> {
|
|
3
|
+
incomingEdgesOf(vertex: V): E[];
|
|
4
|
+
outgoingEdgesOf(vertex: V): E[];
|
|
5
|
+
inDegreeOf(vertexOrId: V | VertexId): number;
|
|
6
|
+
outDegreeOf(vertexOrId: V | VertexId): number;
|
|
7
|
+
getEdgeSrc(e: E): V | null;
|
|
8
|
+
getEdgeDest(e: E): V | null;
|
|
9
|
+
}
|
|
10
|
+
export type TopologicalStatus = 0 | 1 | 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DoublyLinkedListGetBy = 'node' | 'val';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './binary-tree';
|
|
2
|
+
export * from './bst';
|
|
3
|
+
export * from './avl-tree';
|
|
4
|
+
export * from './segment-tree';
|
|
5
|
+
export * from './tree-multiset';
|
|
6
|
+
export * from './abstract-graph';
|
|
7
|
+
export * from './directed-graph';
|
|
8
|
+
export * from './priority-queue';
|
|
9
|
+
export * from './heap';
|
|
10
|
+
export * from './singly-linked-list';
|
|
11
|
+
export * from './doubly-linked-list';
|
|
12
|
+
export * from './navigator';
|
|
13
|
+
export * from './utils';
|
|
@@ -0,0 +1,29 @@
|
|
|
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("./binary-tree"), exports);
|
|
18
|
+
__exportStar(require("./bst"), exports);
|
|
19
|
+
__exportStar(require("./avl-tree"), exports);
|
|
20
|
+
__exportStar(require("./segment-tree"), exports);
|
|
21
|
+
__exportStar(require("./tree-multiset"), exports);
|
|
22
|
+
__exportStar(require("./abstract-graph"), exports);
|
|
23
|
+
__exportStar(require("./directed-graph"), exports);
|
|
24
|
+
__exportStar(require("./priority-queue"), exports);
|
|
25
|
+
__exportStar(require("./heap"), exports);
|
|
26
|
+
__exportStar(require("./singly-linked-list"), exports);
|
|
27
|
+
__exportStar(require("./doubly-linked-list"), exports);
|
|
28
|
+
__exportStar(require("./navigator"), exports);
|
|
29
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Direction = 'up' | 'right' | 'down' | 'left';
|
|
2
|
+
export type Turning = {
|
|
3
|
+
[key in Direction]: Direction;
|
|
4
|
+
};
|
|
5
|
+
export interface NavigatorParams<T> {
|
|
6
|
+
matrix: T[][];
|
|
7
|
+
turning: Turning;
|
|
8
|
+
onMove: (cur: [number, number]) => void;
|
|
9
|
+
init: {
|
|
10
|
+
cur: [number, number];
|
|
11
|
+
charDir: Direction;
|
|
12
|
+
VISITED: T;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SegmentTreeNodeVal = number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SinglyLinkedList } from "../linked-list";
|
|
2
|
+
/** Type used for filter and find methods, returning a boolean */
|
|
3
|
+
export type TTestFunction<NodeData> = (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean;
|
|
4
|
+
/** Type used for map and forEach methods, returning anything */
|
|
5
|
+
export type TMapFunction<NodeData> = (data: any, index: number, list: SinglyLinkedList<NodeData>) => any;
|
|
@@ -26,8 +26,8 @@ export type DebounceOptions = {
|
|
|
26
26
|
maxWait?: number;
|
|
27
27
|
};
|
|
28
28
|
export interface DebouncedFunction<F extends Procedure> {
|
|
29
|
-
(this: ThisParameterType<F>, ...args: Parameters<F>): void;
|
|
30
29
|
cancel: () => void;
|
|
30
|
+
(this: ThisParameterType<F>, ...args: [...Parameters<F>]): void;
|
|
31
31
|
}
|
|
32
32
|
export type MonthKey = 'January' | 'February' | 'March' | 'April' | 'May' | 'June' | 'July' | 'August' | 'September' | 'October' | 'November' | 'December';
|
|
33
33
|
export type Month = {
|
|
@@ -44,3 +44,9 @@ export declare class TreeNode<T> {
|
|
|
44
44
|
getHeight(): number;
|
|
45
45
|
}
|
|
46
46
|
export type OrderType = 'InOrder' | 'PreOrder' | 'PostOrder';
|
|
47
|
+
export type DeepProxy<T> = T extends (...args: any[]) => infer R ? (...args: [...Parameters<T>]) => DeepProxy<R> : T extends object ? {
|
|
48
|
+
[K in keyof T]: DeepProxy<T[K]>;
|
|
49
|
+
} : T;
|
|
50
|
+
export type DeepProxyOnChange = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
|
|
51
|
+
export type DeepProxyOnGet = (target: any, property: string | symbol, value: any, receiver: any, descriptor: any, result: any) => void;
|
|
52
|
+
export type CurryFunc<T> = T extends (...args: infer Args) => infer R ? Args extends [infer Arg, ...infer RestArgs] ? (arg: Arg) => CurryFunc<(...args: RestArgs) => R> : R : T;
|