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.
Files changed (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -1,15 +1,40 @@
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.MaxPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
6
- constructor(options) {
7
- super({
8
- nodes: options.nodes, comparator: (a, b) => {
9
- const aKey = a, bKey = b;
19
+ /**
20
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
21
+ * @license MIT
22
+ */
23
+ var priority_queue_1 = require("./priority-queue");
24
+ var MaxPriorityQueue = /** @class */ (function (_super) {
25
+ __extends(MaxPriorityQueue, _super);
26
+ /**
27
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
28
+ * @param [options] - An optional object that contains the following properties:
29
+ */
30
+ function MaxPriorityQueue(options) {
31
+ return _super.call(this, {
32
+ nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
33
+ var aKey = a, bKey = b;
10
34
  return bKey - aKey;
11
35
  }
12
- });
36
+ }) || this;
13
37
  }
14
- }
38
+ return MaxPriorityQueue;
39
+ }(priority_queue_1.PriorityQueue));
15
40
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -1,4 +1,13 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import { PriorityQueue } from './priority-queue';
6
+ import type { PriorityQueueOptions } from '../types';
2
7
  export declare class MinPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
8
+ /**
9
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
10
+ * @param [options] - An optional object that contains the following properties:
11
+ */
12
+ constructor(options?: PriorityQueueOptions<T>);
4
13
  }
@@ -1,15 +1,40 @@
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.MinPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- class MinPriorityQueue extends priority_queue_1.PriorityQueue {
6
- constructor(options) {
7
- super({
8
- nodes: options.nodes, comparator: (a, b) => {
9
- const aKey = a, bKey = b;
19
+ /**
20
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
21
+ * @license MIT
22
+ */
23
+ var priority_queue_1 = require("./priority-queue");
24
+ var MinPriorityQueue = /** @class */ (function (_super) {
25
+ __extends(MinPriorityQueue, _super);
26
+ /**
27
+ * The constructor initializes a PriorityQueue with optional nodes and a comparator function.
28
+ * @param [options] - An optional object that contains the following properties:
29
+ */
30
+ function MinPriorityQueue(options) {
31
+ return _super.call(this, {
32
+ nodes: options === null || options === void 0 ? void 0 : options.nodes, comparator: (options === null || options === void 0 ? void 0 : options.comparator) ? options.comparator : function (a, b) {
33
+ var aKey = a, bKey = b;
10
34
  return aKey - bKey;
11
35
  }
12
- });
36
+ }) || this;
13
37
  }
14
- }
38
+ return MinPriorityQueue;
39
+ }(priority_queue_1.PriorityQueue));
15
40
  exports.MinPriorityQueue = MinPriorityQueue;
@@ -1,36 +1,160 @@
1
- export type PriorityQueueComparator<T> = (a: T, b: T) => number;
2
- export interface PriorityQueueOptions<T> {
3
- nodes?: T[];
4
- isFix?: boolean;
5
- comparator: PriorityQueueComparator<T>;
6
- }
7
- export type PriorityQueueDFSOrderPattern = 'pre' | 'in' | 'post';
1
+ /**
2
+ * @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
3
+ * @license MIT
4
+ */
5
+ import type { PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions } from '../types';
8
6
  export declare class PriorityQueue<T = number> {
9
7
  protected nodes: T[];
10
- get size(): number;
11
- protected readonly _comparator: PriorityQueueComparator<T>;
8
+ /**
9
+ * The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
10
+ * function.
11
+ * @param options - The `options` parameter is an object that contains the following properties:
12
+ */
12
13
  constructor(options: PriorityQueueOptions<T>);
13
- protected _compare(a: number, b: number): boolean;
14
- protected _swap(a: number, b: number): void;
15
- protected _isValidIndex(index: number): boolean;
16
- protected _getParent(child: number): number;
17
- protected _getLeft(parent: number): number;
18
- protected _getRight(parent: number): number;
19
- protected _getComparedChild(parent: number): number;
20
- protected _heapifyUp(start: number): void;
21
- protected _heapifyDown(start: number): void;
22
- protected _fix(): void;
14
+ get size(): number;
15
+ /**
16
+ * The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
17
+ * @param options - The "options" parameter is an object that contains the configuration options for the PriorityQueue.
18
+ * It can include properties such as "comparator" which specifies the comparison function used to order the elements in
19
+ * the priority queue, and "initialValues" which is an array of initial values to be added to the priority
20
+ * @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
21
+ */
22
+ static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
23
+ /**
24
+ * The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
25
+ * the isValid method.
26
+ * @param options - An object containing options for creating a priority queue. The options object should have the
27
+ * following properties:
28
+ * @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
29
+ */
30
+ static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
31
+ /**
32
+ * The "offer" function adds a node to the heap and ensures that the heap property is maintained.
33
+ * @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
34
+ * that needs to be added to the heap.
35
+ */
23
36
  offer(node: T): void;
37
+ /**
38
+ * The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
39
+ * @returns The `peek()` function is returning the first element (`T`) of the `nodes` array if the `size` is not zero.
40
+ * Otherwise, it returns `null`.
41
+ */
24
42
  peek(): T | null;
43
+ /**
44
+ * The `poll` function removes and returns the top element from a heap data structure.
45
+ * @returns The `poll()` method returns a value of type `T` or `null`.
46
+ */
25
47
  poll(): T | null;
48
+ /**
49
+ * The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
50
+ * @returns The method `leaf()` is returning the last element (`T`) in the `nodes` array if it exists. If the array is
51
+ * empty or the last element is `null`, then it returns `null`.
52
+ */
26
53
  leaf(): T | null;
54
+ /**
55
+ * The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
56
+ * object is empty or not.
57
+ * @returns The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to
58
+ * 0.
59
+ */
27
60
  isEmpty(): boolean;
61
+ /**
62
+ * The clear function clears the nodes array.
63
+ */
28
64
  clear(): void;
65
+ /**
66
+ * The toArray function returns an array containing all the elements in the nodes property.
67
+ * @returns An array of type T, which is the elements of the nodes property.
68
+ */
29
69
  toArray(): T[];
70
+ /**
71
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
72
+ * original instance.
73
+ * @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
74
+ * `comparator` properties as the original instance.
75
+ */
30
76
  clone(): PriorityQueue<T>;
77
+ /**
78
+ * The `isValid` function recursively checks if a binary tree satisfies a certain condition.
79
+ * @returns The function `isValid()` returns a boolean value.
80
+ */
31
81
  isValid(): boolean;
82
+ /**
83
+ * The function sorts the elements in a data structure and returns them in ascending order.
84
+ * @returns The `sort()` function is returning an array of type `T[]`.
85
+ */
32
86
  sort(): T[];
87
+ /**
88
+ * The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
89
+ * based on the specified traversal order.
90
+ * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
91
+ * the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
92
+ * @returns an array of type `(T | null)[]`.
93
+ */
33
94
  DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[];
34
- static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
35
- static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
95
+ protected readonly _comparator: PriorityQueueComparator<T>;
96
+ /**
97
+ * The function compares two numbers using a custom comparator function.
98
+ * @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
99
+ * @param {number} b - The parameter "b" is a number.
100
+ * @returns the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The
101
+ * comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned,
102
+ * indicating that the element at index `a` is greater than the element at index `b`.
103
+ */
104
+ protected _compare(a: number, b: number): boolean;
105
+ /**
106
+ * The function swaps two elements in an array.
107
+ * @param {number} a - The parameter "a" is a number that represents the index of an element in an array.
108
+ * @param {number} b - The parameter "b" is a number.
109
+ */
110
+ protected _swap(a: number, b: number): void;
111
+ /**
112
+ * The function checks if a given index is valid within an array.
113
+ * @param {number} index - The parameter "index" is of type number and represents the index value that needs to be
114
+ * checked for validity.
115
+ * @returns A boolean value indicating whether the given index is valid or not.
116
+ */
117
+ protected _isValidIndex(index: number): boolean;
118
+ /**
119
+ * The function returns the index of the parent node given the index of a child node in a binary tree.
120
+ * @param {number} child - The "child" parameter is a number representing the index of a child node in a binary tree.
121
+ * @returns the parent of the given child node.
122
+ */
123
+ protected _getParent(child: number): number;
124
+ /**
125
+ * The function returns the index of the left child node in a binary tree given the index of its parent node.
126
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
127
+ * @returns the left child of a given parent node in a binary tree.
128
+ */
129
+ protected _getLeft(parent: number): number;
130
+ /**
131
+ * The function returns the index of the right child node in a binary tree given the index of its parent node.
132
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
133
+ * @returns the right child of a given parent node in a binary tree.
134
+ */
135
+ protected _getRight(parent: number): number;
136
+ /**
137
+ * The function returns the index of the smallest child node of a given parent node.
138
+ * @param {number} parent - The parent parameter is a number that represents the index of the parent node in a binary
139
+ * tree.
140
+ * @returns the minimum value between the parent node and its left and right child nodes.
141
+ */
142
+ protected _getComparedChild(parent: number): number;
143
+ /**
144
+ * The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the
145
+ * correct position.
146
+ * @param {number} start - The start parameter is the index of the element that needs to be moved up in the heap.
147
+ */
148
+ protected _heapifyUp(start: number): void;
149
+ /**
150
+ * The function performs a heapify operation by comparing and swapping elements in a binary heap.
151
+ * @param {number} start - The start parameter is the index of the element in the heap from where the heapifyDown
152
+ * operation should start.
153
+ */
154
+ protected _heapifyDown(start: number): void;
155
+ /**
156
+ * The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving
157
+ * towards the root.
158
+ */
159
+ protected _fix(): void;
36
160
  }