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,21 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.CoordinateSet = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
21
|
+
* @license MIT
|
|
22
|
+
*/
|
|
23
|
+
var CoordinateSet = /** @class */ (function (_super) {
|
|
24
|
+
__extends(CoordinateSet, _super);
|
|
25
|
+
function CoordinateSet(joint) {
|
|
26
|
+
var _this = _super.call(this) || this;
|
|
27
|
+
_this._joint = '_';
|
|
8
28
|
if (joint !== undefined)
|
|
9
|
-
|
|
29
|
+
_this._joint = joint;
|
|
30
|
+
return _this;
|
|
10
31
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
32
|
+
/**
|
|
33
|
+
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
34
|
+
* joining its elements with a specified separator.
|
|
35
|
+
* @param {number[]} value - The parameter "value" is an array of numbers.
|
|
36
|
+
* @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
|
|
37
|
+
* in the joined value as an argument.
|
|
38
|
+
*/
|
|
39
|
+
CoordinateSet.prototype.has = function (value) {
|
|
40
|
+
return _super.prototype.has.call(this, value.join(this._joint));
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
|
|
44
|
+
* specified delimiter before calling the parent class's "add" function.
|
|
45
|
+
* @param {number[]} value - An array of numbers
|
|
46
|
+
* @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
|
|
47
|
+
* (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
|
|
48
|
+
*/
|
|
49
|
+
CoordinateSet.prototype.add = function (value) {
|
|
50
|
+
return _super.prototype.add.call(this, value.join(this._joint));
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The function overrides the delete method and deletes an element from a Set by joining the elements of the input
|
|
54
|
+
* array with a specified joint and then calling the delete method of the parent class.
|
|
55
|
+
* @param {number[]} value - An array of numbers
|
|
56
|
+
* @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
|
|
57
|
+
* `value` array joined together using the `_joint` property.
|
|
58
|
+
*/
|
|
59
|
+
CoordinateSet.prototype.delete = function (value) {
|
|
60
|
+
return _super.prototype.delete.call(this, value.join(this._joint));
|
|
61
|
+
};
|
|
62
|
+
return CoordinateSet;
|
|
63
|
+
}(Set));
|
|
21
64
|
exports.CoordinateSet = CoordinateSet;
|
|
@@ -15,3 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./hash-table"), exports);
|
|
18
|
+
__exportStar(require("./coordinate-map"), exports);
|
|
19
|
+
__exportStar(require("./coordinate-set"), exports);
|
|
20
|
+
__exportStar(require("./pair"), exports);
|
|
21
|
+
__exportStar(require("./tree-map"), exports);
|
|
22
|
+
__exportStar(require("./tree-set"), exports);
|
|
@@ -1,72 +1,61 @@
|
|
|
1
|
-
import { PriorityQueue } from '../priority-queue';
|
|
2
|
-
export interface HeapOptions<T> {
|
|
3
|
-
priority?: (element: T) => number;
|
|
4
|
-
}
|
|
5
|
-
export interface HeapItem<T> {
|
|
6
|
-
priority: number;
|
|
7
|
-
element: T | null;
|
|
8
|
-
}
|
|
9
1
|
/**
|
|
10
|
-
* @copyright
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
11
3
|
* @license MIT
|
|
12
|
-
*
|
|
13
|
-
* @abstract
|
|
14
|
-
* @class Heap
|
|
15
4
|
*/
|
|
5
|
+
import { PriorityQueue } from '../priority-queue';
|
|
6
|
+
import type { HeapItem, HeapOptions } from '../types';
|
|
16
7
|
export declare abstract class Heap<T> {
|
|
17
8
|
protected abstract _pq: PriorityQueue<HeapItem<T>>;
|
|
18
9
|
protected _priorityCb: (element: T) => number;
|
|
19
10
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
11
|
+
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
12
|
+
* options provided.
|
|
13
|
+
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
23
14
|
*/
|
|
24
15
|
protected constructor(options?: HeapOptions<T>);
|
|
25
16
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @returns
|
|
17
|
+
* The function returns the size of a priority queue.
|
|
18
|
+
* @returns The size of the priority queue.
|
|
28
19
|
*/
|
|
29
20
|
get size(): number;
|
|
30
21
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @returns {boolean}
|
|
22
|
+
* The function checks if a priority queue is empty.
|
|
23
|
+
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
33
24
|
*/
|
|
34
25
|
isEmpty(): boolean;
|
|
35
26
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @returns {object}
|
|
27
|
+
* The `peek` function returns the top item in the priority queue without removing it.
|
|
28
|
+
* @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue
|
|
39
29
|
*/
|
|
40
30
|
peek(): HeapItem<T> | null;
|
|
41
31
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
44
|
-
* @returns {object}
|
|
32
|
+
* The `peekLast` function returns the last item in the heap.
|
|
33
|
+
* @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue
|
|
45
34
|
*/
|
|
46
35
|
peekLast(): HeapItem<T> | null;
|
|
47
36
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
*
|
|
51
|
-
* @param priority
|
|
37
|
+
* The `offer` function adds an element to a priority queue with an optional priority value.
|
|
38
|
+
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
39
|
+
* type.
|
|
40
|
+
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
41
|
+
* element being offered to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
42
|
+
* the value of `element`. If the `element` parameter is not a number, then the
|
|
43
|
+
* @returns The `offer` method returns the instance of the `Heap` class.
|
|
52
44
|
* @throws {Error} if priority is not a valid number
|
|
53
45
|
*/
|
|
54
46
|
offer(element: T, priority?: number): Heap<T>;
|
|
55
47
|
/**
|
|
56
|
-
* Removes and returns an element with highest priority in the queue
|
|
57
|
-
* @
|
|
58
|
-
* @returns {object}
|
|
48
|
+
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
|
|
49
|
+
* @returns either a HeapItem<T> object or null.
|
|
59
50
|
*/
|
|
60
51
|
poll(): HeapItem<T> | null;
|
|
61
52
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
* @returns {array}
|
|
53
|
+
* The `toArray` function returns an array of `HeapItem<T>` objects.
|
|
54
|
+
* @returns An array of HeapItem<T> objects.Returns a sorted list of elements
|
|
65
55
|
*/
|
|
66
56
|
toArray(): HeapItem<T>[];
|
|
67
57
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @public
|
|
58
|
+
* The clear function clears the priority queue.
|
|
70
59
|
*/
|
|
71
60
|
clear(): void;
|
|
72
61
|
}
|
|
@@ -1,69 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Heap = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @copyright 2021 Pablo Rios <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT
|
|
7
|
-
*
|
|
8
|
-
* @abstract
|
|
9
|
-
* @class Heap
|
|
10
|
-
*/
|
|
11
|
-
class Heap {
|
|
4
|
+
var Heap = /** @class */ (function () {
|
|
12
5
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
6
|
+
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
7
|
+
* options provided.
|
|
8
|
+
* @param [options] - An optional object that contains configuration options for the Heap.
|
|
16
9
|
*/
|
|
17
|
-
|
|
10
|
+
function Heap(options) {
|
|
18
11
|
if (options) {
|
|
19
|
-
|
|
12
|
+
var priority = options.priority;
|
|
20
13
|
if (priority !== undefined && typeof priority !== 'function') {
|
|
21
14
|
throw new Error('.constructor expects a valid priority function');
|
|
22
15
|
}
|
|
23
|
-
this._priorityCb = priority || ((el)
|
|
16
|
+
this._priorityCb = priority || (function (el) { return +el; });
|
|
24
17
|
}
|
|
25
18
|
else {
|
|
26
|
-
this._priorityCb = (el)
|
|
19
|
+
this._priorityCb = function (el) { return +el; };
|
|
27
20
|
}
|
|
28
21
|
}
|
|
22
|
+
Object.defineProperty(Heap.prototype, "size", {
|
|
23
|
+
/**
|
|
24
|
+
* The function returns the size of a priority queue.
|
|
25
|
+
* @returns The size of the priority queue.
|
|
26
|
+
*/
|
|
27
|
+
get: function () {
|
|
28
|
+
return this._pq.size;
|
|
29
|
+
},
|
|
30
|
+
enumerable: false,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @returns {
|
|
34
|
+
* The function checks if a priority queue is empty.
|
|
35
|
+
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
|
-
return this._pq.size;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @public
|
|
38
|
-
* @returns {boolean}
|
|
39
|
-
*/
|
|
40
|
-
isEmpty() {
|
|
37
|
+
Heap.prototype.isEmpty = function () {
|
|
41
38
|
return this._pq.size < 1;
|
|
42
|
-
}
|
|
39
|
+
};
|
|
43
40
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @returns {object}
|
|
41
|
+
* The `peek` function returns the top item in the priority queue without removing it.
|
|
42
|
+
* @returns The `peek()` method is returning either a `HeapItem<T>` object or `null`.Returns an element with the highest priority in the queue
|
|
47
43
|
*/
|
|
48
|
-
peek() {
|
|
44
|
+
Heap.prototype.peek = function () {
|
|
49
45
|
return this._pq.peek();
|
|
50
|
-
}
|
|
46
|
+
};
|
|
51
47
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
54
|
-
* @returns {object}
|
|
48
|
+
* The `peekLast` function returns the last item in the heap.
|
|
49
|
+
* @returns The method `peekLast()` returns either a `HeapItem<T>` object or `null`.Returns an element with the lowest priority in the queue
|
|
55
50
|
*/
|
|
56
|
-
peekLast() {
|
|
51
|
+
Heap.prototype.peekLast = function () {
|
|
57
52
|
return this._pq.leaf();
|
|
58
|
-
}
|
|
53
|
+
};
|
|
59
54
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* @param priority
|
|
55
|
+
* The `offer` function adds an element to a priority queue with an optional priority value.
|
|
56
|
+
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
57
|
+
* type.
|
|
58
|
+
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
59
|
+
* element being offered to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
60
|
+
* the value of `element`. If the `element` parameter is not a number, then the
|
|
61
|
+
* @returns The `offer` method returns the instance of the `Heap` class.
|
|
64
62
|
* @throws {Error} if priority is not a valid number
|
|
65
63
|
*/
|
|
66
|
-
offer(element, priority) {
|
|
64
|
+
Heap.prototype.offer = function (element, priority) {
|
|
67
65
|
if (typeof element === 'number') {
|
|
68
66
|
priority = element;
|
|
69
67
|
}
|
|
@@ -79,36 +77,34 @@ class Heap {
|
|
|
79
77
|
throw new Error('.offer expects a numeric priority '
|
|
80
78
|
+ 'or a constructor callback that returns a number');
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
this._pq.offer({ priority: _priority, element });
|
|
80
|
+
var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
|
|
81
|
+
this._pq.offer({ priority: _priority, element: element });
|
|
84
82
|
return this;
|
|
85
|
-
}
|
|
83
|
+
};
|
|
86
84
|
/**
|
|
87
|
-
* Removes and returns an element with highest priority in the queue
|
|
88
|
-
* @
|
|
89
|
-
* @returns {object}
|
|
85
|
+
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
|
|
86
|
+
* @returns either a HeapItem<T> object or null.
|
|
90
87
|
*/
|
|
91
|
-
poll() {
|
|
92
|
-
|
|
88
|
+
Heap.prototype.poll = function () {
|
|
89
|
+
var top = this._pq.poll();
|
|
93
90
|
if (!top) {
|
|
94
91
|
return null;
|
|
95
92
|
}
|
|
96
93
|
return top;
|
|
97
|
-
}
|
|
94
|
+
};
|
|
98
95
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
101
|
-
* @returns {array}
|
|
96
|
+
* The `toArray` function returns an array of `HeapItem<T>` objects.
|
|
97
|
+
* @returns An array of HeapItem<T> objects.Returns a sorted list of elements
|
|
102
98
|
*/
|
|
103
|
-
toArray() {
|
|
99
|
+
Heap.prototype.toArray = function () {
|
|
104
100
|
return this._pq.toArray();
|
|
105
|
-
}
|
|
101
|
+
};
|
|
106
102
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @public
|
|
103
|
+
* The clear function clears the priority queue.
|
|
109
104
|
*/
|
|
110
|
-
clear() {
|
|
105
|
+
Heap.prototype.clear = function () {
|
|
111
106
|
this._pq.clear();
|
|
112
|
-
}
|
|
113
|
-
|
|
107
|
+
};
|
|
108
|
+
return Heap;
|
|
109
|
+
}());
|
|
114
110
|
exports.Heap = Heap;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @copyright
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
|
-
import { Heap
|
|
5
|
+
import { Heap } from './heap';
|
|
6
6
|
import { PriorityQueue } from '../priority-queue';
|
|
7
|
+
import type { HeapItem, HeapOptions } from '../types';
|
|
7
8
|
/**
|
|
8
9
|
* @class MaxHeap
|
|
9
10
|
* @extends Heap
|
|
10
11
|
*/
|
|
11
12
|
export declare class MaxHeap<T> extends Heap<T> {
|
|
12
13
|
protected _pq: PriorityQueue<HeapItem<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
16
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
17
|
+
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
18
|
+
*/
|
|
13
19
|
constructor(options?: HeapOptions<T>);
|
|
14
20
|
}
|
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* @copyright
|
|
3
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
+
var __extends = (this && this.__extends) || (function () {
|
|
7
|
+
var extendStatics = function (d, b) {
|
|
8
|
+
extendStatics = Object.setPrototypeOf ||
|
|
9
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
11
|
+
return extendStatics(d, b);
|
|
12
|
+
};
|
|
13
|
+
return function (d, b) {
|
|
14
|
+
if (typeof b !== "function" && b !== null)
|
|
15
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
+
extendStatics(d, b);
|
|
17
|
+
function __() { this.constructor = d; }
|
|
18
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
6
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
22
|
exports.MaxHeap = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
23
|
+
var heap_1 = require("./heap");
|
|
24
|
+
var priority_queue_1 = require("../priority-queue");
|
|
10
25
|
/**
|
|
11
26
|
* @class MaxHeap
|
|
12
27
|
* @extends Heap
|
|
13
28
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
var MaxHeap = /** @class */ (function (_super) {
|
|
30
|
+
__extends(MaxHeap, _super);
|
|
31
|
+
/**
|
|
32
|
+
* The constructor initializes a PriorityQueue with a custom comparator function.
|
|
33
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
34
|
+
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
35
|
+
*/
|
|
36
|
+
function MaxHeap(options) {
|
|
37
|
+
var _this = _super.call(this, options) || this;
|
|
38
|
+
_this._pq = new priority_queue_1.PriorityQueue({
|
|
39
|
+
comparator: function (a, b) { return b.priority - a.priority; }
|
|
19
40
|
});
|
|
41
|
+
return _this;
|
|
20
42
|
}
|
|
21
|
-
|
|
43
|
+
return MaxHeap;
|
|
44
|
+
}(heap_1.Heap));
|
|
22
45
|
exports.MaxHeap = MaxHeap;
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @copyright
|
|
2
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
3
3
|
* @license MIT
|
|
4
4
|
*/
|
|
5
|
-
import { Heap
|
|
5
|
+
import { Heap } from './heap';
|
|
6
6
|
import { PriorityQueue } from '../priority-queue';
|
|
7
|
+
import type { HeapItem, HeapOptions } from '../types';
|
|
7
8
|
/**
|
|
8
9
|
* @class MinHeap
|
|
9
10
|
* @extends Heap
|
|
10
11
|
*/
|
|
11
12
|
export declare class MinHeap<T> extends Heap<T> {
|
|
12
13
|
protected _pq: PriorityQueue<HeapItem<T>>;
|
|
14
|
+
/**
|
|
15
|
+
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
16
|
+
* objects.
|
|
17
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
18
|
+
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
19
|
+
*/
|
|
13
20
|
constructor(options?: HeapOptions<T>);
|
|
14
21
|
}
|
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* @copyright
|
|
3
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
+
var __extends = (this && this.__extends) || (function () {
|
|
7
|
+
var extendStatics = function (d, b) {
|
|
8
|
+
extendStatics = Object.setPrototypeOf ||
|
|
9
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
10
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
11
|
+
return extendStatics(d, b);
|
|
12
|
+
};
|
|
13
|
+
return function (d, b) {
|
|
14
|
+
if (typeof b !== "function" && b !== null)
|
|
15
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
+
extendStatics(d, b);
|
|
17
|
+
function __() { this.constructor = d; }
|
|
18
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
6
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
22
|
exports.MinHeap = void 0;
|
|
8
|
-
|
|
9
|
-
|
|
23
|
+
var heap_1 = require("./heap");
|
|
24
|
+
var priority_queue_1 = require("../priority-queue");
|
|
10
25
|
/**
|
|
11
26
|
* @class MinHeap
|
|
12
27
|
* @extends Heap
|
|
13
28
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
var MinHeap = /** @class */ (function (_super) {
|
|
30
|
+
__extends(MinHeap, _super);
|
|
31
|
+
/**
|
|
32
|
+
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
|
|
33
|
+
* objects.
|
|
34
|
+
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
|
|
35
|
+
* type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
|
|
36
|
+
*/
|
|
37
|
+
function MinHeap(options) {
|
|
38
|
+
var _this = _super.call(this, options) || this;
|
|
39
|
+
_this._pq = new priority_queue_1.PriorityQueue({
|
|
40
|
+
comparator: function (a, b) { return a.priority - b.priority; }
|
|
19
41
|
});
|
|
42
|
+
return _this;
|
|
20
43
|
}
|
|
21
|
-
|
|
44
|
+
return MinHeap;
|
|
45
|
+
}(heap_1.Heap));
|
|
22
46
|
exports.MinHeap = MinHeap;
|
|
@@ -4,7 +4,6 @@ export declare class DoublyLinkedListNode<T> {
|
|
|
4
4
|
prev: DoublyLinkedListNode<T> | null;
|
|
5
5
|
constructor(nodeValue: T);
|
|
6
6
|
}
|
|
7
|
-
export type DoublyLinkedListGetBy = 'node' | 'val';
|
|
8
7
|
export declare class DoublyLinkedList<T> {
|
|
9
8
|
private _first;
|
|
10
9
|
private _last;
|
|
@@ -12,13 +11,17 @@ export declare class DoublyLinkedList<T> {
|
|
|
12
11
|
get size(): number;
|
|
13
12
|
set size(v: number);
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @param val
|
|
14
|
+
* The function adds a new node with a given value to the beginning of a doubly linked list.
|
|
15
|
+
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
|
|
16
|
+
* the doubly linked list.
|
|
17
|
+
* @returns A boolean value is being returned.
|
|
17
18
|
*/
|
|
18
19
|
offerFirst(val: T): boolean;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param val
|
|
21
|
+
* The function adds a new node with a given value to the end of a doubly linked list.
|
|
22
|
+
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
|
|
23
|
+
* doubly linked list.
|
|
24
|
+
* @returns a boolean value, which is always true.
|
|
22
25
|
*/
|
|
23
26
|
offerLast(val: T): boolean;
|
|
24
27
|
peekFirst(): T | null;
|
|
@@ -52,8 +55,12 @@ export declare class DoublyLinkedList<T> {
|
|
|
52
55
|
*/
|
|
53
56
|
insert(index: number, val: T): boolean;
|
|
54
57
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
58
|
+
* The `remove` function removes an element at a specified index from a data structure, updating the links between
|
|
59
|
+
* nodes accordingly.
|
|
60
|
+
* @param {number} index - The index parameter represents the position of the element to be removed in the data
|
|
61
|
+
* structure. It is of type number.
|
|
62
|
+
* @returns The `remove` method returns the value of the removed element (`T`) if the removal is successful, or `null`
|
|
63
|
+
* if the index is out of bounds.
|
|
57
64
|
*/
|
|
58
65
|
remove(index: number): T | null;
|
|
59
66
|
}
|