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
|
@@ -3,37 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Queue = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @copyright 2020
|
|
7
|
-
*
|
|
6
|
+
* @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
|
|
8
7
|
* @class
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
var Queue = /** @class */ (function () {
|
|
11
10
|
/**
|
|
12
11
|
* Creates a queue.
|
|
13
12
|
* @param {array} [elements]
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
function Queue(elements) {
|
|
16
15
|
this._nodes = elements || [];
|
|
17
16
|
this._offset = 0;
|
|
18
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a queue from an existing array.
|
|
20
|
+
* @public
|
|
21
|
+
* @static
|
|
22
|
+
* @param {array} elements
|
|
23
|
+
* @return {Queue}
|
|
24
|
+
*/
|
|
25
|
+
Queue.fromArray = function (elements) {
|
|
26
|
+
return new Queue(elements);
|
|
27
|
+
};
|
|
19
28
|
/**
|
|
20
29
|
* Adds an element at the back of the queue.
|
|
21
30
|
* @public
|
|
22
31
|
* @param {any} element
|
|
23
32
|
*/
|
|
24
|
-
offer(element) {
|
|
33
|
+
Queue.prototype.offer = function (element) {
|
|
25
34
|
this._nodes.push(element);
|
|
26
35
|
return this;
|
|
27
|
-
}
|
|
36
|
+
};
|
|
28
37
|
/**
|
|
29
38
|
* Dequeues the front element in the queue.
|
|
30
39
|
* @public
|
|
31
40
|
* @returns {any}
|
|
32
41
|
*/
|
|
33
|
-
poll() {
|
|
42
|
+
Queue.prototype.poll = function () {
|
|
34
43
|
if (this.size() === 0)
|
|
35
44
|
return null;
|
|
36
|
-
|
|
45
|
+
var first = this.peek();
|
|
37
46
|
this._offset += 1;
|
|
38
47
|
if (this._offset * 2 < this._nodes.length)
|
|
39
48
|
return first;
|
|
@@ -42,72 +51,63 @@ class Queue {
|
|
|
42
51
|
this._nodes = this._nodes.slice(this._offset);
|
|
43
52
|
this._offset = 0;
|
|
44
53
|
return first;
|
|
45
|
-
}
|
|
54
|
+
};
|
|
46
55
|
/**
|
|
47
56
|
* Returns the front element of the queue.
|
|
48
57
|
* @public
|
|
49
58
|
* @returns {any}
|
|
50
59
|
*/
|
|
51
|
-
peek() {
|
|
60
|
+
Queue.prototype.peek = function () {
|
|
52
61
|
return this.size() > 0 ? this._nodes[this._offset] : null;
|
|
53
|
-
}
|
|
62
|
+
};
|
|
54
63
|
/**
|
|
55
64
|
* Returns the back element of the queue.
|
|
56
65
|
* @public
|
|
57
66
|
* @returns {any}
|
|
58
67
|
*/
|
|
59
|
-
peekLast() {
|
|
68
|
+
Queue.prototype.peekLast = function () {
|
|
60
69
|
return this.size() > 0 ? this._nodes[this._nodes.length - 1] : null;
|
|
61
|
-
}
|
|
70
|
+
};
|
|
62
71
|
/**
|
|
63
72
|
* Returns the number of elements in the queue.
|
|
64
73
|
* @public
|
|
65
74
|
* @returns {number}
|
|
66
75
|
*/
|
|
67
|
-
size() {
|
|
76
|
+
Queue.prototype.size = function () {
|
|
68
77
|
return this._nodes.length - this._offset;
|
|
69
|
-
}
|
|
78
|
+
};
|
|
70
79
|
/**
|
|
71
80
|
* Checks if the queue is empty.
|
|
72
81
|
* @public
|
|
73
82
|
* @returns {boolean}
|
|
74
83
|
*/
|
|
75
|
-
isEmpty() {
|
|
84
|
+
Queue.prototype.isEmpty = function () {
|
|
76
85
|
return this.size() === 0;
|
|
77
|
-
}
|
|
86
|
+
};
|
|
78
87
|
/**
|
|
79
88
|
* Returns the remaining elements in the queue as an array.
|
|
80
89
|
* @public
|
|
81
90
|
* @returns {array}
|
|
82
91
|
*/
|
|
83
|
-
toArray() {
|
|
92
|
+
Queue.prototype.toArray = function () {
|
|
84
93
|
return this._nodes.slice(this._offset);
|
|
85
|
-
}
|
|
94
|
+
};
|
|
86
95
|
/**
|
|
87
96
|
* Clears the queue.
|
|
88
97
|
* @public
|
|
89
98
|
*/
|
|
90
|
-
clear() {
|
|
99
|
+
Queue.prototype.clear = function () {
|
|
91
100
|
this._nodes = [];
|
|
92
101
|
this._offset = 0;
|
|
93
|
-
}
|
|
102
|
+
};
|
|
94
103
|
/**
|
|
95
104
|
* Creates a shallow copy of the queue.
|
|
96
105
|
* @public
|
|
97
106
|
* @return {Queue}
|
|
98
107
|
*/
|
|
99
|
-
clone() {
|
|
108
|
+
Queue.prototype.clone = function () {
|
|
100
109
|
return new Queue(this._nodes.slice(this._offset));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @public
|
|
105
|
-
* @static
|
|
106
|
-
* @param {array} elements
|
|
107
|
-
* @return {Queue}
|
|
108
|
-
*/
|
|
109
|
-
static fromArray(elements) {
|
|
110
|
-
return new Queue(elements);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
110
|
+
};
|
|
111
|
+
return Queue;
|
|
112
|
+
}());
|
|
113
113
|
exports.Queue = Queue;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license MIT
|
|
3
|
-
* @copyright 2020
|
|
4
|
-
*
|
|
3
|
+
* @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
|
|
5
4
|
* @class
|
|
6
5
|
*/
|
|
7
6
|
export declare class Stack<T> {
|
|
@@ -11,6 +10,14 @@ export declare class Stack<T> {
|
|
|
11
10
|
* @param {array} [elements]
|
|
12
11
|
*/
|
|
13
12
|
constructor(elements?: T[]);
|
|
13
|
+
/**
|
|
14
|
+
* Creates a stack from an existing array
|
|
15
|
+
* @public
|
|
16
|
+
* @static
|
|
17
|
+
* @param {array} [elements]
|
|
18
|
+
* @return {Stack}
|
|
19
|
+
*/
|
|
20
|
+
static fromArray<T>(elements: T[]): Stack<T>;
|
|
14
21
|
/**
|
|
15
22
|
* Checks if the stack is empty.
|
|
16
23
|
* @public
|
|
@@ -58,12 +65,4 @@ export declare class Stack<T> {
|
|
|
58
65
|
* @return {Stack}
|
|
59
66
|
*/
|
|
60
67
|
clone(): Stack<T>;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a stack from an existing array
|
|
63
|
-
* @public
|
|
64
|
-
* @static
|
|
65
|
-
* @param {array} [elements]
|
|
66
|
-
* @return {Stack}
|
|
67
|
-
*/
|
|
68
|
-
static fromArray<T>(elements: T[]): Stack<T>;
|
|
69
68
|
}
|
|
@@ -3,95 +3,95 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stack = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @copyright 2020
|
|
7
|
-
*
|
|
6
|
+
* @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
|
|
8
7
|
* @class
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
var Stack = /** @class */ (function () {
|
|
11
10
|
/**
|
|
12
11
|
* Creates a stack.
|
|
13
12
|
* @param {array} [elements]
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
function Stack(elements) {
|
|
16
15
|
this._elements = Array.isArray(elements) ? elements : [];
|
|
17
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a stack from an existing array
|
|
19
|
+
* @public
|
|
20
|
+
* @static
|
|
21
|
+
* @param {array} [elements]
|
|
22
|
+
* @return {Stack}
|
|
23
|
+
*/
|
|
24
|
+
Stack.fromArray = function (elements) {
|
|
25
|
+
return new Stack(elements);
|
|
26
|
+
};
|
|
18
27
|
/**
|
|
19
28
|
* Checks if the stack is empty.
|
|
20
29
|
* @public
|
|
21
30
|
* @returns {boolean}
|
|
22
31
|
*/
|
|
23
|
-
isEmpty() {
|
|
32
|
+
Stack.prototype.isEmpty = function () {
|
|
24
33
|
return this._elements.length === 0;
|
|
25
|
-
}
|
|
34
|
+
};
|
|
26
35
|
/**
|
|
27
36
|
* Returns the number of elements in the stack.
|
|
28
37
|
* @public
|
|
29
38
|
* @returns {number}
|
|
30
39
|
*/
|
|
31
|
-
size() {
|
|
40
|
+
Stack.prototype.size = function () {
|
|
32
41
|
return this._elements.length;
|
|
33
|
-
}
|
|
42
|
+
};
|
|
34
43
|
/**
|
|
35
44
|
* Returns the top element in the stack.
|
|
36
45
|
* @public
|
|
37
46
|
* @returns {object}
|
|
38
47
|
*/
|
|
39
|
-
peek() {
|
|
48
|
+
Stack.prototype.peek = function () {
|
|
40
49
|
if (this.isEmpty())
|
|
41
50
|
return null;
|
|
42
51
|
return this._elements[this._elements.length - 1];
|
|
43
|
-
}
|
|
52
|
+
};
|
|
44
53
|
/**
|
|
45
54
|
* Adds an element to the top of the stack.
|
|
46
55
|
* @public
|
|
47
56
|
* @param {object} element
|
|
48
57
|
*/
|
|
49
|
-
push(element) {
|
|
58
|
+
Stack.prototype.push = function (element) {
|
|
50
59
|
this._elements.push(element);
|
|
51
60
|
return this;
|
|
52
|
-
}
|
|
61
|
+
};
|
|
53
62
|
/**
|
|
54
63
|
* Removes and returns the top element in the stack.
|
|
55
64
|
* @public
|
|
56
65
|
* @returns {object}
|
|
57
66
|
*/
|
|
58
|
-
pop() {
|
|
67
|
+
Stack.prototype.pop = function () {
|
|
59
68
|
if (this.isEmpty())
|
|
60
69
|
return null;
|
|
61
70
|
return this._elements.pop() || null;
|
|
62
|
-
}
|
|
71
|
+
};
|
|
63
72
|
/**
|
|
64
73
|
* Returns the remaining elements as an array.
|
|
65
74
|
* @public
|
|
66
75
|
* @returns {array}
|
|
67
76
|
*/
|
|
68
|
-
toArray() {
|
|
77
|
+
Stack.prototype.toArray = function () {
|
|
69
78
|
return this._elements.slice();
|
|
70
|
-
}
|
|
79
|
+
};
|
|
71
80
|
/**
|
|
72
81
|
* Clears all elements from the stack.
|
|
73
82
|
* @public
|
|
74
83
|
*/
|
|
75
|
-
clear() {
|
|
84
|
+
Stack.prototype.clear = function () {
|
|
76
85
|
this._elements = [];
|
|
77
|
-
}
|
|
86
|
+
};
|
|
78
87
|
/**
|
|
79
88
|
* Creates a shallow copy from the stack.
|
|
80
89
|
* @public
|
|
81
90
|
* @return {Stack}
|
|
82
91
|
*/
|
|
83
|
-
clone() {
|
|
92
|
+
Stack.prototype.clone = function () {
|
|
84
93
|
return new Stack(this._elements.slice());
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* @public
|
|
89
|
-
* @static
|
|
90
|
-
* @param {array} [elements]
|
|
91
|
-
* @return {Stack}
|
|
92
|
-
*/
|
|
93
|
-
static fromArray(elements) {
|
|
94
|
-
return new Stack(elements);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
94
|
+
};
|
|
95
|
+
return Stack;
|
|
96
|
+
}());
|
|
97
97
|
exports.Stack = Stack;
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
export type ArgumentTypes<T extends (...args: any[]) => any> = T extends (...args: infer A) => any ? A : never;
|
|
2
1
|
export declare const THUNK_SYMBOL: unique symbol;
|
|
3
|
-
export
|
|
2
|
+
export declare const isThunk: (fnOrValue: any) => boolean;
|
|
3
|
+
type ToThunkFn = () => ReturnType<TrlFn>;
|
|
4
|
+
type Thunk = () => ReturnType<ToThunkFn> & {
|
|
4
5
|
__THUNK__: typeof THUNK_SYMBOL;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export declare const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
export interface Trampoline<F extends ((...args: any[]) => any)> {
|
|
17
|
-
(...args: ArgumentTypes<F>): Unbox<ReturnType<F>>;
|
|
18
|
-
cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
|
|
19
|
-
}
|
|
20
|
-
export interface TrampolineAsync<F extends ((...args: any[]) => any)> {
|
|
21
|
-
(...args: ArgumentTypes<F>): Promise<Unbox<ReturnType<F>>>;
|
|
22
|
-
cont: Cont<ArgumentTypes<F>, ReturnType<F>>;
|
|
23
|
-
}
|
|
24
|
-
export declare const trampoline: <F extends (...args: any[]) => any>(fn: F) => Trampoline<F>;
|
|
25
|
-
export declare const trampolineAsync: <F extends (...args: any[]) => any>(fn: F) => TrampolineAsync<F>;
|
|
6
|
+
};
|
|
7
|
+
export declare const toThunk: (fn: ToThunkFn) => Thunk;
|
|
8
|
+
type TrlFn = (...args: any[]) => any;
|
|
9
|
+
export declare const trampoline: (fn: TrlFn) => ((...args: [...Parameters<TrlFn>]) => any) & {
|
|
10
|
+
cont: (...args: [...Parameters<TrlFn>]) => Thunk;
|
|
11
|
+
};
|
|
12
|
+
type TrlAsyncFn = (...args: any[]) => any;
|
|
13
|
+
export declare const trampolineAsync: (fn: TrlAsyncFn) => ((...args: [...Parameters<TrlAsyncFn>]) => Promise<any>) & {
|
|
14
|
+
cont: (...args: [...Parameters<TrlAsyncFn>]) => Thunk;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -8,45 +8,123 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
+
if (ar || !(i in from)) {
|
|
57
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
+
ar[i] = from[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
+
};
|
|
11
63
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
64
|
exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = void 0;
|
|
13
65
|
exports.THUNK_SYMBOL = Symbol('thunk');
|
|
14
|
-
|
|
15
|
-
return typeof
|
|
66
|
+
var isThunk = function (fnOrValue) {
|
|
67
|
+
return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
|
|
16
68
|
};
|
|
17
69
|
exports.isThunk = isThunk;
|
|
18
|
-
|
|
19
|
-
|
|
70
|
+
var toThunk = function (fn) {
|
|
71
|
+
var thunk = function () { return fn(); };
|
|
20
72
|
thunk.__THUNK__ = exports.THUNK_SYMBOL;
|
|
21
73
|
return thunk;
|
|
22
74
|
};
|
|
23
75
|
exports.toThunk = toThunk;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
76
|
+
var trampoline = function (fn) {
|
|
77
|
+
var cont = function () {
|
|
78
|
+
var args = [];
|
|
79
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
80
|
+
args[_i] = arguments[_i];
|
|
81
|
+
}
|
|
82
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
83
|
+
};
|
|
84
|
+
return Object.assign(function () {
|
|
85
|
+
var args = [];
|
|
86
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
87
|
+
args[_i] = arguments[_i];
|
|
88
|
+
}
|
|
89
|
+
var result = fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
90
|
+
while ((0, exports.isThunk)(result) && typeof result === 'function') {
|
|
29
91
|
result = result();
|
|
30
92
|
}
|
|
31
93
|
return result;
|
|
32
|
-
}, { cont });
|
|
94
|
+
}, { cont: cont });
|
|
33
95
|
};
|
|
34
96
|
exports.trampoline = trampoline;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
result = yield result();
|
|
97
|
+
var trampolineAsync = function (fn) {
|
|
98
|
+
var cont = function () {
|
|
99
|
+
var args = [];
|
|
100
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
101
|
+
args[_i] = arguments[_i];
|
|
41
102
|
}
|
|
42
|
-
return
|
|
43
|
-
}
|
|
103
|
+
return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
|
|
104
|
+
};
|
|
105
|
+
return Object.assign(function () {
|
|
106
|
+
var args = [];
|
|
107
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
|
+
args[_i] = arguments[_i];
|
|
109
|
+
}
|
|
110
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
111
|
+
var result;
|
|
112
|
+
return __generator(this, function (_a) {
|
|
113
|
+
switch (_a.label) {
|
|
114
|
+
case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
|
|
115
|
+
case 1:
|
|
116
|
+
result = _a.sent();
|
|
117
|
+
_a.label = 2;
|
|
118
|
+
case 2:
|
|
119
|
+
if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
|
|
120
|
+
return [4 /*yield*/, result()];
|
|
121
|
+
case 3:
|
|
122
|
+
result = _a.sent();
|
|
123
|
+
return [3 /*break*/, 2];
|
|
124
|
+
case 4: return [2 /*return*/, result];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}, { cont: cont });
|
|
44
129
|
};
|
|
45
130
|
exports.trampolineAsync = trampolineAsync;
|
|
46
|
-
const factorial = (0, exports.trampoline)((n, acc = 1) => {
|
|
47
|
-
return n
|
|
48
|
-
// Note: calling factorial.cont instead of factorial directly
|
|
49
|
-
? factorial.cont(n - 1, acc * n)
|
|
50
|
-
: acc;
|
|
51
|
-
});
|
|
52
|
-
// factorial(32768)
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
export declare class TrieNode {
|
|
2
|
+
protected _value: string;
|
|
3
|
+
constructor(v: string);
|
|
2
4
|
protected _children: Map<string, TrieNode>;
|
|
3
5
|
get children(): Map<string, TrieNode>;
|
|
4
6
|
set children(v: Map<string, TrieNode>);
|
|
5
7
|
protected _isEnd: boolean;
|
|
6
8
|
get isEnd(): boolean;
|
|
7
9
|
set isEnd(v: boolean);
|
|
10
|
+
get val(): string;
|
|
11
|
+
set val(v: string);
|
|
8
12
|
}
|
|
9
13
|
export declare class Trie {
|
|
14
|
+
constructor(words?: string[]);
|
|
10
15
|
protected _root: TrieNode;
|
|
11
16
|
get root(): TrieNode;
|
|
12
17
|
set root(v: TrieNode);
|
|
13
|
-
|
|
14
|
-
put(input: string): boolean;
|
|
18
|
+
put(word: string): boolean;
|
|
15
19
|
has(input: string): boolean;
|
|
16
20
|
remove(word: string): boolean;
|
|
17
21
|
/**
|
|
@@ -20,9 +24,15 @@ export declare class Trie {
|
|
|
20
24
|
*/
|
|
21
25
|
isAbsPrefix(input: string): boolean;
|
|
22
26
|
/**
|
|
23
|
-
* Can present as a prefix or word
|
|
27
|
+
* Can present as a abs prefix or word
|
|
24
28
|
* @param input
|
|
25
29
|
*/
|
|
26
30
|
isPrefix(input: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the input string is the common prefix of all the words
|
|
33
|
+
* @param input
|
|
34
|
+
*/
|
|
35
|
+
isCommonPrefix(input: string): boolean;
|
|
36
|
+
getLongestCommonPrefix(): string;
|
|
27
37
|
getAll(prefix?: string): string[];
|
|
28
38
|
}
|