data-structure-typed 0.8.18 → 1.12.9
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/.dependency-cruiser.js +449 -0
- package/.idea/data-structure-typed.iml +2 -0
- package/.idea/modules.xml +1 -1
- package/README.md +298 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
- package/dist/data-structures/binary-tree/avl-tree.js +150 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
- package/dist/data-structures/binary-tree/binary-tree.js +747 -369
- package/dist/data-structures/binary-tree/bst.d.ts +20 -8
- package/dist/data-structures/binary-tree/bst.js +164 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
- package/dist/data-structures/binary-tree/segment-tree.js +95 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
- package/dist/data-structures/graph/abstract-graph.js +712 -323
- package/dist/data-structures/graph/directed-graph.d.ts +114 -12
- package/dist/data-structures/graph/directed-graph.js +372 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
- package/dist/data-structures/graph/undirected-graph.js +233 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
- package/dist/data-structures/hash/coordinate-map.js +70 -20
- package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
- package/dist/data-structures/hash/coordinate-set.js +58 -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 +26 -37
- package/dist/data-structures/heap/heap.js +56 -60
- package/dist/data-structures/heap/max-heap.d.ts +8 -2
- package/dist/data-structures/heap/max-heap.js +32 -9
- package/dist/data-structures/heap/min-heap.d.ts +9 -2
- package/dist/data-structures/heap/min-heap.js +33 -9
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
- package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
- package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
- package/dist/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/data-structures/matrix/matrix.js +19 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
- package/dist/data-structures/matrix/matrix2d.js +158 -61
- package/dist/data-structures/matrix/navigator.d.ts +34 -16
- package/dist/data-structures/matrix/navigator.js +65 -18
- package/dist/data-structures/matrix/vector2d.d.ts +153 -29
- package/dist/data-structures/matrix/vector2d.js +249 -102
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
- package/dist/data-structures/priority-queue/priority-queue.js +285 -116
- package/dist/data-structures/queue/deque.d.ts +69 -0
- package/dist/data-structures/queue/deque.js +151 -56
- package/dist/data-structures/queue/queue.d.ts +34 -37
- package/dist/data-structures/queue/queue.js +59 -61
- package/dist/data-structures/stack/stack.d.ts +29 -35
- package/dist/data-structures/stack/stack.js +51 -56
- package/dist/data-structures/trie/trie.d.ts +36 -6
- package/dist/data-structures/trie/trie.js +256 -83
- 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.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/utils/trampoline.d.ts +14 -0
- package/dist/utils/trampoline.js +130 -0
- package/dist/utils/types/index.js +17 -0
- package/dist/{types → utils}/types/utils.d.ts +15 -1
- package/dist/{types → utils/types}/utils.js +21 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
- package/dist/utils/utils.js +651 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +85 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +423 -0
- package/docs/classes/AaTree.html +117 -0
- package/docs/classes/AbstractEdge.html +198 -0
- package/docs/classes/AbstractGraph.html +891 -0
- package/docs/classes/AbstractVertex.html +164 -0
- package/docs/classes/ArrayDeque.html +384 -0
- package/docs/classes/BST.html +1893 -0
- package/docs/classes/BSTNode.html +425 -0
- package/docs/classes/BTree.html +117 -0
- package/docs/classes/BinaryIndexedTree.html +244 -0
- package/docs/classes/BinaryTree.html +1754 -0
- package/docs/classes/BinaryTreeNode.html +396 -0
- package/docs/classes/Character.html +165 -0
- package/docs/classes/CoordinateMap.html +394 -0
- package/docs/classes/CoordinateSet.html +355 -0
- package/docs/classes/Deque.html +617 -0
- package/docs/classes/DirectedEdge.html +247 -0
- package/docs/classes/DirectedGraph.html +1207 -0
- package/docs/classes/DirectedVertex.html +154 -0
- package/docs/classes/DoublyLinkedList.html +619 -0
- package/docs/classes/DoublyLinkedListNode.html +160 -0
- package/docs/classes/Heap.html +315 -0
- package/docs/classes/Matrix2D.html +447 -0
- package/docs/classes/MatrixNTI2D.html +181 -0
- package/docs/classes/MaxHeap.html +325 -0
- package/docs/classes/MaxPriorityQueue.html +668 -0
- package/docs/classes/MinHeap.html +326 -0
- package/docs/classes/MinPriorityQueue.html +668 -0
- package/docs/classes/Navigator.html +285 -0
- package/docs/classes/ObjectDeque.html +289 -0
- package/docs/classes/PriorityQueue.html +643 -0
- package/docs/classes/Queue.html +337 -0
- package/docs/classes/RBTree.html +117 -0
- package/docs/classes/SegmentTree.html +234 -0
- package/docs/classes/SegmentTreeNode.html +302 -0
- package/docs/classes/SinglyLinkedList.html +1035 -0
- package/docs/classes/SinglyLinkedListNode.html +304 -0
- package/docs/classes/SplayTree.html +117 -0
- package/docs/classes/Stack.html +313 -0
- package/docs/classes/TreeMultiSet.html +1897 -0
- package/docs/classes/Trie.html +317 -0
- package/docs/classes/TrieNode.html +221 -0
- package/docs/classes/TwoThreeTree.html +117 -0
- package/docs/classes/UndirectedEdge.html +220 -0
- package/docs/classes/UndirectedGraph.html +1006 -0
- package/docs/classes/UndirectedVertex.html +154 -0
- package/docs/classes/Vector2D.html +746 -0
- package/docs/enums/CP.html +126 -0
- package/docs/enums/FamilyPosition.html +126 -0
- package/docs/enums/LoopType.html +119 -0
- package/docs/index.html +288 -0
- package/docs/modules.html +146 -0
- package/jest.config.js +5 -0
- package/package.json +33 -47
- package/rename_clear_files.sh +29 -0
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +58 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
- package/src/data-structures/binary-tree/binary-tree.ts +460 -145
- package/src/data-structures/binary-tree/bst.ts +31 -25
- 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/segment-tree.ts +25 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +224 -108
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +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/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +132 -26
- package/src/data-structures/graph/undirected-graph.ts +78 -11
- package/src/data-structures/hash/coordinate-map.ts +33 -1
- package/src/data-structures/hash/coordinate-set.ts +25 -0
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +27 -41
- package/src/data-structures/heap/max-heap.ts +8 -2
- package/src/data-structures/heap/min-heap.ts +9 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
- package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
- package/src/data-structures/matrix/matrix.ts +11 -0
- package/src/data-structures/matrix/matrix2d.ts +90 -10
- package/src/data-structures/matrix/navigator.ts +34 -14
- package/src/data-structures/matrix/vector2d.ts +187 -63
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/priority-queue.ts +200 -78
- package/src/data-structures/queue/deque.ts +71 -2
- package/src/data-structures/queue/queue.ts +37 -40
- package/src/data-structures/stack/stack.ts +32 -38
- package/src/data-structures/trie/trie.ts +83 -14
- 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 +13 -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 +1 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/trampoline.ts +51 -0
- package/src/utils/types/index.ts +1 -0
- package/src/{types → utils/types}/utils.ts +27 -5
- package/src/{utils.ts → utils/utils.ts} +41 -131
- package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
- package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
- package/tsconfig.json +9 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/data-structures/trampoline.js +0 -52
- 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/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/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/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/data-structures/trampoline.ts +0 -91
- package/src/types/index.ts +0 -1
- /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
- /package/dist/{types → utils}/types/index.d.ts +0 -0
- /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// 操作 常见名称 Ada Java JavaScript C++ Python Perl PHP Ruby
|
|
3
|
-
// 尾部插入 inject, snoc Append offerLast push push_back append push array_push push
|
|
4
|
-
// 头部插入 push, cons Prepend offerFirst unshift push_front appendleft unshift array_unshift unshift
|
|
5
|
-
// 尾部删除 eject Delete_Last pollLast pop pop_back pop pop array_pop pop
|
|
6
|
-
// 头部删除 pop Delete_First pollFirst shift pop_front popleft shift array_shift shift
|
|
7
|
-
// 查看尾部 Last_Element peekLast [length - 1] back [-1] $array[-1] end last
|
|
8
|
-
// 查看头部 First_Element peekFirst [0] front [0] $array[0] reset first
|
|
9
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
3
|
exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
var DoublyLinkedListNode = /** @class */ (function () {
|
|
5
|
+
function DoublyLinkedListNode(nodeValue) {
|
|
13
6
|
this.val = nodeValue;
|
|
14
7
|
this.next = null;
|
|
15
8
|
this.prev = null;
|
|
16
9
|
}
|
|
17
|
-
|
|
10
|
+
return DoublyLinkedListNode;
|
|
11
|
+
}());
|
|
18
12
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
var DoublyLinkedList = /** @class */ (function () {
|
|
14
|
+
function DoublyLinkedList() {
|
|
21
15
|
this._first = null;
|
|
22
16
|
this._last = null;
|
|
23
17
|
this._size = 0;
|
|
24
18
|
// --- end extra methods ---
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
Object.defineProperty(DoublyLinkedList.prototype, "size", {
|
|
21
|
+
get: function () {
|
|
22
|
+
return this._size;
|
|
23
|
+
},
|
|
24
|
+
set: function (v) {
|
|
25
|
+
this._size = v;
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
32
30
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param val
|
|
31
|
+
* The function adds a new node with a given value to the beginning of a doubly linked list.
|
|
32
|
+
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
|
|
33
|
+
* the doubly linked list.
|
|
34
|
+
* @returns A boolean value is being returned.
|
|
35
35
|
*/
|
|
36
|
-
offerFirst(val) {
|
|
37
|
-
|
|
36
|
+
DoublyLinkedList.prototype.offerFirst = function (val) {
|
|
37
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
38
38
|
if (this._size === 0) {
|
|
39
39
|
this._first = newNode;
|
|
40
40
|
this._last = newNode;
|
|
@@ -47,13 +47,15 @@ class DoublyLinkedList {
|
|
|
47
47
|
}
|
|
48
48
|
this._size++;
|
|
49
49
|
return true;
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param val
|
|
52
|
+
* The function adds a new node with a given value to the end of a doubly linked list.
|
|
53
|
+
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
|
|
54
|
+
* doubly linked list.
|
|
55
|
+
* @returns a boolean value, which is always true.
|
|
54
56
|
*/
|
|
55
|
-
offerLast(val) {
|
|
56
|
-
|
|
57
|
+
DoublyLinkedList.prototype.offerLast = function (val) {
|
|
58
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
57
59
|
if (this._size === 0) {
|
|
58
60
|
this._first = newNode;
|
|
59
61
|
this._last = newNode;
|
|
@@ -66,8 +68,16 @@ class DoublyLinkedList {
|
|
|
66
68
|
}
|
|
67
69
|
this._size++;
|
|
68
70
|
return true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The `peekFirst` function returns the first node or value in a doubly linked list, depending on the specified
|
|
74
|
+
* parameter.
|
|
75
|
+
* @param {DoublyLinkedListGetBy} [by] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy. It
|
|
76
|
+
* is used to specify whether to return the first node, the value of the first node, or the first node itself.
|
|
77
|
+
* @returns The method `peekFirst` returns either the first node of the doubly linked list (`DoublyLinkedListNode<T>`),
|
|
78
|
+
* the value of the first node (`T`), or `null` depending on the value of the `by` parameter.
|
|
79
|
+
*/
|
|
80
|
+
DoublyLinkedList.prototype.peekFirst = function (by) {
|
|
71
81
|
var _a, _b, _c, _d, _e;
|
|
72
82
|
switch (by) {
|
|
73
83
|
case 'node':
|
|
@@ -77,9 +87,17 @@ class DoublyLinkedList {
|
|
|
77
87
|
default:
|
|
78
88
|
return (_e = (_d = this._first) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
|
|
79
89
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* The `peekLast` function returns the last node or value in a doubly linked list.
|
|
93
|
+
* @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
|
|
94
|
+
* It specifies whether to return the last node, the value of the last node, or both. The default value is 'val', which
|
|
95
|
+
* means that if no value is provided for the "by" parameter, the method
|
|
96
|
+
* @returns The method `peekLast` returns the last node, value, or null based on the specified `by` parameter.
|
|
97
|
+
*/
|
|
98
|
+
DoublyLinkedList.prototype.peekLast = function (by) {
|
|
82
99
|
var _a, _b, _c, _d, _e;
|
|
100
|
+
if (by === void 0) { by = 'val'; }
|
|
83
101
|
switch (by) {
|
|
84
102
|
case 'node':
|
|
85
103
|
return (_a = this._last) !== null && _a !== void 0 ? _a : null;
|
|
@@ -88,15 +106,23 @@ class DoublyLinkedList {
|
|
|
88
106
|
default:
|
|
89
107
|
return (_e = (_d = this._last) === null || _d === void 0 ? void 0 : _d.val) !== null && _e !== void 0 ? _e : null;
|
|
90
108
|
}
|
|
91
|
-
}
|
|
109
|
+
};
|
|
92
110
|
/**
|
|
93
|
-
*
|
|
111
|
+
* The function `pollFirst` removes and returns the first element of a doubly linked list, either as a node or its
|
|
112
|
+
* value, depending on the specified parameter.
|
|
113
|
+
* @param {DoublyLinkedListGetBy} [by=val] - The "by" parameter is an optional parameter of type DoublyLinkedListGetBy.
|
|
114
|
+
* It specifies the criteria by which the first element should be retrieved from the doubly linked list. The default
|
|
115
|
+
* value is 'val', which means the first element will be retrieved by its value. Other possible values for "by
|
|
116
|
+
* @returns The method `pollFirst` returns either the value of the first node in the doubly linked list, the first node
|
|
117
|
+
* itself, or null if the list is empty. The specific return type depends on the value of the `by` parameter. If `by`
|
|
118
|
+
* is set to 'node', the method returns the first node. If `by` is set to 'val', the method returns the value
|
|
94
119
|
*/
|
|
95
|
-
pollFirst
|
|
120
|
+
DoublyLinkedList.prototype.pollFirst = function (by) {
|
|
96
121
|
var _a, _b, _c;
|
|
122
|
+
if (by === void 0) { by = 'val'; }
|
|
97
123
|
if (this._size === 0)
|
|
98
124
|
return null;
|
|
99
|
-
|
|
125
|
+
var oldHead = this._first;
|
|
100
126
|
if (this._size === 1) {
|
|
101
127
|
this._first = null;
|
|
102
128
|
this._last = null;
|
|
@@ -117,15 +143,23 @@ class DoublyLinkedList {
|
|
|
117
143
|
default:
|
|
118
144
|
return (_c = oldHead === null || oldHead === void 0 ? void 0 : oldHead.val) !== null && _c !== void 0 ? _c : null;
|
|
119
145
|
}
|
|
120
|
-
}
|
|
146
|
+
};
|
|
121
147
|
/**
|
|
122
|
-
*
|
|
148
|
+
* The function `pollLast` removes and returns the last element in a doubly linked list, either as a node or its value,
|
|
149
|
+
* depending on the specified parameter.
|
|
150
|
+
* @param {DoublyLinkedListGetBy} [by=val] - The parameter "by" is of type DoublyLinkedListGetBy, which is an enum that
|
|
151
|
+
* can have two possible values: 'node' or 'val'. It determines the type of value that will be returned by the pollLast
|
|
152
|
+
* method. If 'node' is specified, the method will return the
|
|
153
|
+
* @returns The method `pollLast` returns either a `DoublyLinkedListNode<T>`, the value of the node (`T`), or `null`.
|
|
154
|
+
* The specific type that is returned depends on the value of the `by` parameter. If `by` is set to `'node'`, then a
|
|
155
|
+
* `DoublyLinkedListNode<T>` is returned. If `by` is set to `'
|
|
123
156
|
*/
|
|
124
|
-
pollLast
|
|
157
|
+
DoublyLinkedList.prototype.pollLast = function (by) {
|
|
125
158
|
var _a, _b, _c;
|
|
159
|
+
if (by === void 0) { by = 'val'; }
|
|
126
160
|
if (this._size === 0)
|
|
127
161
|
return null;
|
|
128
|
-
|
|
162
|
+
var polled = this._last;
|
|
129
163
|
if (this._size === 1) {
|
|
130
164
|
this._first = null;
|
|
131
165
|
this._last = null;
|
|
@@ -146,7 +180,7 @@ class DoublyLinkedList {
|
|
|
146
180
|
default:
|
|
147
181
|
return (_c = polled === null || polled === void 0 ? void 0 : polled.val) !== null && _c !== void 0 ? _c : null;
|
|
148
182
|
}
|
|
149
|
-
}
|
|
183
|
+
};
|
|
150
184
|
/**
|
|
151
185
|
* Returns the node at the specified index of the linked list.
|
|
152
186
|
* If index = 0; first element in the list is returned.
|
|
@@ -154,11 +188,12 @@ class DoublyLinkedList {
|
|
|
154
188
|
* @param index Index of the node to be retrieved
|
|
155
189
|
* @param by Return value type
|
|
156
190
|
*/
|
|
157
|
-
get(index, by
|
|
191
|
+
DoublyLinkedList.prototype.get = function (index, by) {
|
|
158
192
|
var _a, _b;
|
|
193
|
+
if (by === void 0) { by = 'val'; }
|
|
159
194
|
if (index < 0 || index >= this._size)
|
|
160
195
|
return null;
|
|
161
|
-
|
|
196
|
+
var count, current;
|
|
162
197
|
if (index <= this._size / 2) {
|
|
163
198
|
count = 0;
|
|
164
199
|
current = this._first;
|
|
@@ -183,7 +218,7 @@ class DoublyLinkedList {
|
|
|
183
218
|
default:
|
|
184
219
|
return (_b = current === null || current === void 0 ? void 0 : current.val) !== null && _b !== void 0 ? _b : null;
|
|
185
220
|
}
|
|
186
|
-
}
|
|
221
|
+
};
|
|
187
222
|
/**
|
|
188
223
|
* Updates the value of the node at the specified index.
|
|
189
224
|
* If index = 0; Value of the first element in the list is updated.
|
|
@@ -191,33 +226,33 @@ class DoublyLinkedList {
|
|
|
191
226
|
* @param index Index of the node to be updated
|
|
192
227
|
* @param val New value of the node
|
|
193
228
|
*/
|
|
194
|
-
set(index, val) {
|
|
195
|
-
|
|
229
|
+
DoublyLinkedList.prototype.set = function (index, val) {
|
|
230
|
+
var foundNode = this.get(index, 'node');
|
|
196
231
|
if (foundNode !== null) {
|
|
197
232
|
foundNode.val = val;
|
|
198
233
|
return true;
|
|
199
234
|
}
|
|
200
235
|
return false;
|
|
201
|
-
}
|
|
202
|
-
isEmpty() {
|
|
236
|
+
};
|
|
237
|
+
DoublyLinkedList.prototype.isEmpty = function () {
|
|
203
238
|
return this._size === 0;
|
|
204
|
-
}
|
|
239
|
+
};
|
|
205
240
|
// --- start extra methods ---
|
|
206
241
|
/**
|
|
207
242
|
* Inserts a new node at the specified index.
|
|
208
243
|
* @param index Index at which the new node has to be inserted
|
|
209
244
|
* @param val Value of the new node to be inserted
|
|
210
245
|
*/
|
|
211
|
-
insert(index, val) {
|
|
246
|
+
DoublyLinkedList.prototype.insert = function (index, val) {
|
|
212
247
|
if (index < 0 || index > this._size)
|
|
213
248
|
return false;
|
|
214
249
|
if (index === 0)
|
|
215
250
|
return !!this.offerFirst(val);
|
|
216
251
|
if (index === this._size)
|
|
217
252
|
return !!this.offerLast(val);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
253
|
+
var newNode = new DoublyLinkedListNode(val);
|
|
254
|
+
var prevNode = this.get(index - 1, 'node');
|
|
255
|
+
var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
|
|
221
256
|
if (prevNode)
|
|
222
257
|
prevNode.next = newNode;
|
|
223
258
|
newNode.prev = prevNode;
|
|
@@ -226,12 +261,16 @@ class DoublyLinkedList {
|
|
|
226
261
|
nextNode.prev = newNode;
|
|
227
262
|
this._size++;
|
|
228
263
|
return true;
|
|
229
|
-
}
|
|
264
|
+
};
|
|
230
265
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
266
|
+
* The `remove` function removes an element at a specified index from a data structure, updating the links between
|
|
267
|
+
* nodes accordingly.
|
|
268
|
+
* @param {number} index - The index parameter represents the position of the element to be removed in the data
|
|
269
|
+
* structure. It is of type number.
|
|
270
|
+
* @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
|
|
271
|
+
* if the index is out of bounds.
|
|
233
272
|
*/
|
|
234
|
-
remove(index) {
|
|
273
|
+
DoublyLinkedList.prototype.remove = function (index) {
|
|
235
274
|
var _a, _b, _c;
|
|
236
275
|
if (index < 0 || index > this._size - 1)
|
|
237
276
|
return null;
|
|
@@ -240,9 +279,9 @@ class DoublyLinkedList {
|
|
|
240
279
|
else if (index === this._size - 1)
|
|
241
280
|
return (_b = (_a = this.pollLast('node')) === null || _a === void 0 ? void 0 : _a.val) !== null && _b !== void 0 ? _b : null;
|
|
242
281
|
else {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
282
|
+
var prevNode = this.get(index - 1, 'node');
|
|
283
|
+
var removeNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
|
|
284
|
+
var nextNode = removeNode === null || removeNode === void 0 ? void 0 : removeNode.next;
|
|
246
285
|
if (prevNode)
|
|
247
286
|
prevNode.next = nextNode !== null && nextNode !== void 0 ? nextNode : null;
|
|
248
287
|
if (nextNode)
|
|
@@ -254,6 +293,7 @@ class DoublyLinkedList {
|
|
|
254
293
|
this._size--;
|
|
255
294
|
return (_c = removeNode === null || removeNode === void 0 ? void 0 : removeNode.val) !== null && _c !== void 0 ? _c : null;
|
|
256
295
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
296
|
+
};
|
|
297
|
+
return DoublyLinkedList;
|
|
298
|
+
}());
|
|
259
299
|
exports.DoublyLinkedList = DoublyLinkedList;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
|
+
* @license MIT
|
|
4
|
+
*/
|
|
5
5
|
/**
|
|
6
6
|
* The class which represents one link or node in a linked list
|
|
7
7
|
* ```ts
|
|
@@ -72,6 +72,13 @@ export declare class SinglyLinkedListNode<NodeData = any> {
|
|
|
72
72
|
* ```
|
|
73
73
|
*/
|
|
74
74
|
export declare class SinglyLinkedList<NodeData = any> {
|
|
75
|
+
/** The head of the list, the first node */
|
|
76
|
+
head: SinglyLinkedListNode<NodeData> | null;
|
|
77
|
+
/** The tail of the list, the last node */
|
|
78
|
+
tail: SinglyLinkedListNode<NodeData> | null;
|
|
79
|
+
/** Internal size reference */
|
|
80
|
+
private size;
|
|
81
|
+
constructor(...args: NodeData[]);
|
|
75
82
|
/**
|
|
76
83
|
* The length of the list
|
|
77
84
|
*/
|
|
@@ -85,13 +92,6 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
85
92
|
* @param iterable Any iterable datatype like Array or Map
|
|
86
93
|
*/
|
|
87
94
|
static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
|
|
88
|
-
/** The head of the list, the first node */
|
|
89
|
-
head: SinglyLinkedListNode<NodeData> | null;
|
|
90
|
-
/** The tail of the list, the last node */
|
|
91
|
-
tail: SinglyLinkedListNode<NodeData> | null;
|
|
92
|
-
/** Internal size reference */
|
|
93
|
-
private size;
|
|
94
|
-
constructor(...args: NodeData[]);
|
|
95
95
|
/**
|
|
96
96
|
* Get the node val at a specified index, zero based
|
|
97
97
|
* ```ts
|
|
@@ -117,7 +117,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
117
117
|
* ```
|
|
118
118
|
* @param f A function to be applied to the val of each node
|
|
119
119
|
*/
|
|
120
|
-
findNodeIndex(f:
|
|
120
|
+
findNodeIndex(f: (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean): ({
|
|
121
121
|
node: SinglyLinkedListNode<NodeData>;
|
|
122
122
|
index: number;
|
|
123
123
|
}) | undefined;
|
|
@@ -130,7 +130,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
130
130
|
* ```
|
|
131
131
|
* @param f Function to test val against
|
|
132
132
|
*/
|
|
133
|
-
findNode(f:
|
|
133
|
+
findNode(f: (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean): SinglyLinkedListNode<NodeData> | undefined;
|
|
134
134
|
/**
|
|
135
135
|
* Returns the value of the first element in the list that
|
|
136
136
|
* satisfies the provided testing function. Otherwise undefined is returned.
|
|
@@ -139,7 +139,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
139
139
|
* ```
|
|
140
140
|
* @param f Function to test val against
|
|
141
141
|
*/
|
|
142
|
-
find(f:
|
|
142
|
+
find(f: (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean): NodeData | undefined;
|
|
143
143
|
/**
|
|
144
144
|
* Returns the index of the first node in the list that
|
|
145
145
|
* satisfies the provided testing function. Ohterwise -1 is returned.
|
|
@@ -148,7 +148,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
148
148
|
* ```
|
|
149
149
|
* @param f Function to test val against
|
|
150
150
|
*/
|
|
151
|
-
findIndex(f:
|
|
151
|
+
findIndex(f: (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean): number;
|
|
152
152
|
/**
|
|
153
153
|
* Append one or any number of nodes to the end of the list.
|
|
154
154
|
* This modifies the list in place and returns the list itself
|
|
@@ -298,7 +298,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
298
298
|
* @param f Function to execute for each element, taking up to three arguments.
|
|
299
299
|
* @param reverse Indicates if the list should be walked in reverse order, default is false
|
|
300
300
|
*/
|
|
301
|
-
forEach(f:
|
|
301
|
+
forEach(f: (data: any, index: number, list: SinglyLinkedList<NodeData>) => any, reverse?: boolean): void;
|
|
302
302
|
/**
|
|
303
303
|
* The map() method creates a new list with the results of
|
|
304
304
|
* calling a provided function on every node in the calling list.
|
|
@@ -308,7 +308,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
308
308
|
* @param f Function that produces an node of the new list, taking up to three arguments
|
|
309
309
|
* @param reverse Indicates if the list should be mapped in reverse order, default is false
|
|
310
310
|
*/
|
|
311
|
-
map(f:
|
|
311
|
+
map(f: (data: any, index: number, list: SinglyLinkedList<NodeData>) => any, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
|
|
312
312
|
/**
|
|
313
313
|
* The filter() method creates a new list with all nodes
|
|
314
314
|
* that pass the test implemented by the provided function.
|
|
@@ -318,7 +318,7 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
318
318
|
* @param f Function to test each node val in the list. Return true to keep the node
|
|
319
319
|
* @param reverse Indicates if the list should be filtered in reverse order, default is false
|
|
320
320
|
*/
|
|
321
|
-
filter(f:
|
|
321
|
+
filter(f: (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
|
|
322
322
|
/**
|
|
323
323
|
* Reduce over each node in the list
|
|
324
324
|
* ```ts
|
|
@@ -355,4 +355,3 @@ export declare class SinglyLinkedList<NodeData = any> {
|
|
|
355
355
|
/** Private helper function to reduce duplication of pop() and shift() methods */
|
|
356
356
|
private removeFromAnyEnd;
|
|
357
357
|
}
|
|
358
|
-
export {};
|