data-structure-typed 0.9.16 → 1.3.0

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 (264) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +665 -172
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -14
  9. package/dist/data-structures/binary-tree/avl-tree.js +142 -116
  10. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +39 -1
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +54 -13
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -126
  14. package/dist/data-structures/binary-tree/binary-tree.js +31 -1093
  15. package/dist/data-structures/binary-tree/bst.d.ts +117 -23
  16. package/dist/data-structures/binary-tree/bst.js +233 -240
  17. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  18. package/dist/data-structures/binary-tree/index.js +1 -0
  19. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  20. package/dist/data-structures/binary-tree/rb-tree.js +40 -5
  21. package/dist/data-structures/binary-tree/segment-tree.d.ts +61 -11
  22. package/dist/data-structures/binary-tree/segment-tree.js +126 -93
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -6
  25. package/dist/data-structures/binary-tree/tree-multiset.js +687 -34
  26. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  27. package/dist/data-structures/graph/abstract-graph.d.ts +270 -36
  28. package/dist/data-structures/graph/abstract-graph.js +610 -572
  29. package/dist/data-structures/graph/directed-graph.d.ts +173 -16
  30. package/dist/data-structures/graph/directed-graph.js +345 -313
  31. package/dist/data-structures/graph/index.d.ts +1 -0
  32. package/dist/data-structures/graph/index.js +1 -0
  33. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  34. package/dist/data-structures/graph/map-graph.js +111 -0
  35. package/dist/data-structures/graph/undirected-graph.d.ts +111 -9
  36. package/dist/data-structures/graph/undirected-graph.js +203 -178
  37. package/dist/data-structures/hash/coordinate-map.d.ts +38 -1
  38. package/dist/data-structures/hash/coordinate-map.js +59 -36
  39. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  40. package/dist/data-structures/hash/coordinate-set.js +49 -33
  41. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  42. package/dist/data-structures/hash/hash-table.js +4 -0
  43. package/dist/data-structures/hash/pair.d.ts +2 -1
  44. package/dist/data-structures/hash/pair.js +4 -0
  45. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-map.js +4 -0
  47. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  48. package/dist/data-structures/hash/tree-set.js +4 -0
  49. package/dist/data-structures/heap/heap.d.ts +62 -45
  50. package/dist/data-structures/heap/heap.js +124 -86
  51. package/dist/data-structures/heap/max-heap.d.ts +13 -5
  52. package/dist/data-structures/heap/max-heap.js +18 -28
  53. package/dist/data-structures/heap/min-heap.d.ts +14 -5
  54. package/dist/data-structures/heap/min-heap.js +19 -28
  55. package/dist/data-structures/index.d.ts +1 -1
  56. package/dist/data-structures/index.js +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -56
  58. package/dist/data-structures/linked-list/doubly-linked-list.js +484 -220
  59. package/dist/data-structures/linked-list/index.d.ts +1 -0
  60. package/dist/data-structures/linked-list/index.js +1 -0
  61. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -315
  62. package/dist/data-structures/linked-list/singly-linked-list.js +374 -727
  63. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  64. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  65. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  66. package/dist/data-structures/matrix/matrix.js +21 -8
  67. package/dist/data-structures/matrix/matrix2d.d.ts +85 -2
  68. package/dist/data-structures/matrix/matrix2d.js +146 -80
  69. package/dist/data-structures/matrix/navigator.d.ts +36 -1
  70. package/dist/data-structures/matrix/navigator.js +46 -37
  71. package/dist/data-structures/matrix/vector2d.d.ts +142 -15
  72. package/dist/data-structures/matrix/vector2d.js +215 -109
  73. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -2
  74. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -26
  75. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -2
  76. package/dist/data-structures/priority-queue/min-priority-queue.js +34 -26
  77. package/dist/data-structures/priority-queue/priority-queue.d.ts +153 -3
  78. package/dist/data-structures/priority-queue/priority-queue.js +244 -143
  79. package/dist/data-structures/queue/deque.d.ts +141 -13
  80. package/dist/data-structures/queue/deque.js +200 -82
  81. package/dist/data-structures/queue/queue.d.ts +65 -38
  82. package/dist/data-structures/queue/queue.js +110 -66
  83. package/dist/data-structures/stack/stack.d.ts +27 -32
  84. package/dist/data-structures/stack/stack.js +47 -53
  85. package/dist/data-structures/tree/index.d.ts +1 -0
  86. package/dist/data-structures/tree/index.js +17 -0
  87. package/dist/data-structures/tree/tree.d.ts +14 -0
  88. package/dist/data-structures/tree/tree.js +60 -0
  89. package/dist/data-structures/trie/trie.d.ts +33 -10
  90. package/dist/data-structures/trie/trie.js +123 -208
  91. package/dist/index.d.ts +3 -0
  92. package/dist/index.js +3 -0
  93. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  94. package/dist/interfaces/abstract-graph.d.ts +17 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/binary-tree.d.ts +6 -0
  97. package/dist/interfaces/bst.d.ts +17 -0
  98. package/dist/interfaces/directed-graph.d.ts +12 -0
  99. package/{src/data-structures/types/index.ts → dist/interfaces/index.d.ts} +10 -8
  100. package/dist/interfaces/index.js +31 -0
  101. package/{src/data-structures/hash/hash-table.ts → dist/interfaces/priority-queue.d.ts} +1 -1
  102. package/dist/interfaces/rb-tree.d.ts +8 -0
  103. package/dist/interfaces/segment-tree.d.ts +1 -0
  104. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  105. package/dist/interfaces/singly-linked-list.js +2 -0
  106. package/dist/interfaces/tree-multiset.d.ts +7 -0
  107. package/dist/interfaces/tree-multiset.js +2 -0
  108. package/dist/interfaces/undirected-graph.d.ts +5 -0
  109. package/dist/interfaces/undirected-graph.js +2 -0
  110. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  111. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  112. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  113. package/dist/types/data-structures/abstract-graph.js +2 -0
  114. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  115. package/dist/types/data-structures/avl-tree.js +2 -0
  116. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  117. package/dist/types/data-structures/binary-tree.js +2 -0
  118. package/dist/types/data-structures/bst.d.ts +13 -0
  119. package/dist/types/data-structures/bst.js +9 -0
  120. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  121. package/dist/types/data-structures/directed-graph.js +9 -0
  122. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  123. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  124. package/dist/types/data-structures/heap.d.ts +3 -0
  125. package/dist/types/data-structures/heap.js +2 -0
  126. package/dist/{data-structures/types → types/data-structures}/index.d.ts +3 -1
  127. package/dist/{data-structures/types → types/data-structures}/index.js +3 -1
  128. package/dist/types/data-structures/map-graph.d.ts +1 -0
  129. package/dist/types/data-structures/map-graph.js +2 -0
  130. package/dist/{data-structures/types → types/data-structures}/navigator.d.ts +2 -2
  131. package/dist/types/data-structures/navigator.js +2 -0
  132. package/dist/{data-structures/types → types/data-structures}/priority-queue.d.ts +2 -2
  133. package/dist/types/data-structures/priority-queue.js +2 -0
  134. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  135. package/dist/types/data-structures/rb-tree.js +8 -0
  136. package/dist/types/data-structures/segment-tree.js +2 -0
  137. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  138. package/dist/types/data-structures/singly-linked-list.js +2 -0
  139. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  140. package/dist/types/data-structures/tree-multiset.js +2 -0
  141. package/dist/types/helpers.d.ts +1 -0
  142. package/dist/types/helpers.js +2 -0
  143. package/dist/types/index.d.ts +3 -0
  144. package/dist/types/index.js +19 -0
  145. package/dist/types/utils/index.d.ts +2 -0
  146. package/dist/types/utils/index.js +18 -0
  147. package/dist/types/utils/utils.d.ts +7 -0
  148. package/dist/types/utils/utils.js +2 -0
  149. package/dist/types/utils/validate-type.d.ts +19 -0
  150. package/dist/types/utils/validate-type.js +2 -0
  151. package/dist/utils/utils.d.ts +17 -103
  152. package/dist/utils/utils.js +40 -625
  153. package/package.json +96 -23
  154. package/.idea/data-structure-typed.iml +0 -12
  155. package/.idea/modules.xml +0 -8
  156. package/.idea/vcs.xml +0 -6
  157. package/dist/data-structures/trampoline.d.ts +0 -16
  158. package/dist/data-structures/trampoline.js +0 -130
  159. package/dist/data-structures/types/abstract-graph.d.ts +0 -29
  160. package/dist/data-structures/types/avl-tree.d.ts +0 -5
  161. package/dist/data-structures/types/binary-tree.d.ts +0 -16
  162. package/dist/data-structures/types/bst.d.ts +0 -7
  163. package/dist/data-structures/types/directed-graph.d.ts +0 -10
  164. package/dist/data-structures/types/doubly-linked-list.d.ts +0 -1
  165. package/dist/data-structures/types/heap.d.ts +0 -7
  166. package/dist/data-structures/types/singly-linked-list.d.ts +0 -5
  167. package/dist/data-structures/types/tree-multiset.d.ts +0 -5
  168. package/dist/data-structures/types/utils.d.ts +0 -52
  169. package/dist/data-structures/types/utils.js +0 -54
  170. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  171. package/src/data-structures/binary-tree/avl-tree.ts +0 -227
  172. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  173. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  174. package/src/data-structures/binary-tree/binary-tree.ts +0 -1133
  175. package/src/data-structures/binary-tree/bst.ts +0 -395
  176. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  177. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  178. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  179. package/src/data-structures/binary-tree/index.ts +0 -11
  180. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  181. package/src/data-structures/binary-tree/segment-tree.ts +0 -172
  182. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  183. package/src/data-structures/binary-tree/tree-multiset.ts +0 -18
  184. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  185. package/src/data-structures/diagrams/README.md +0 -7
  186. package/src/data-structures/graph/abstract-graph.ts +0 -753
  187. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
  188. package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
  189. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
  190. package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
  191. package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
  192. package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
  193. package/src/data-structures/graph/diagrams/edge-list.png +0 -0
  194. package/src/data-structures/graph/diagrams/max-flow.png +0 -0
  195. package/src/data-structures/graph/diagrams/mst.png +0 -0
  196. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  197. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  198. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  199. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  200. package/src/data-structures/graph/directed-graph.ts +0 -306
  201. package/src/data-structures/graph/index.ts +0 -3
  202. package/src/data-structures/graph/undirected-graph.ts +0 -155
  203. package/src/data-structures/hash/coordinate-map.ts +0 -24
  204. package/src/data-structures/hash/coordinate-set.ts +0 -20
  205. package/src/data-structures/hash/index.ts +0 -6
  206. package/src/data-structures/heap/heap.ts +0 -127
  207. package/src/data-structures/heap/index.ts +0 -3
  208. package/src/data-structures/heap/max-heap.ts +0 -23
  209. package/src/data-structures/heap/min-heap.ts +0 -25
  210. package/src/data-structures/index.ts +0 -12
  211. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -250
  212. package/src/data-structures/linked-list/index.ts +0 -2
  213. package/src/data-structures/linked-list/singly-linked-list.ts +0 -736
  214. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  215. package/src/data-structures/matrix/index.ts +0 -4
  216. package/src/data-structures/matrix/matrix.ts +0 -13
  217. package/src/data-structures/matrix/matrix2d.ts +0 -125
  218. package/src/data-structures/matrix/navigator.ts +0 -87
  219. package/src/data-structures/matrix/vector2d.ts +0 -189
  220. package/src/data-structures/priority-queue/index.ts +0 -3
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -13
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -13
  223. package/src/data-structures/priority-queue/priority-queue.ts +0 -200
  224. package/src/data-structures/queue/deque.ts +0 -139
  225. package/src/data-structures/queue/index.ts +0 -2
  226. package/src/data-structures/queue/queue.ts +0 -122
  227. package/src/data-structures/stack/index.ts +0 -1
  228. package/src/data-structures/stack/stack.ts +0 -103
  229. package/src/data-structures/trampoline.ts +0 -51
  230. package/src/data-structures/trie/index.ts +0 -1
  231. package/src/data-structures/trie/trie.ts +0 -203
  232. package/src/data-structures/types/abstract-graph.ts +0 -51
  233. package/src/data-structures/types/avl-tree.ts +0 -6
  234. package/src/data-structures/types/binary-tree.ts +0 -15
  235. package/src/data-structures/types/bst.ts +0 -5
  236. package/src/data-structures/types/directed-graph.ts +0 -18
  237. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  238. package/src/data-structures/types/heap.ts +0 -8
  239. package/src/data-structures/types/navigator.ts +0 -12
  240. package/src/data-structures/types/priority-queue.ts +0 -9
  241. package/src/data-structures/types/segment-tree.ts +0 -1
  242. package/src/data-structures/types/singly-linked-list.ts +0 -15
  243. package/src/data-structures/types/tree-multiset.ts +0 -3
  244. package/src/data-structures/types/utils.ts +0 -173
  245. package/src/index.ts +0 -1
  246. package/src/utils/index.ts +0 -1
  247. package/src/utils/utils.ts +0 -505
  248. package/tsconfig.json +0 -56
  249. /package/dist/{data-structures/types/abstract-graph.js → interfaces/abstract-binary-tree.js} +0 -0
  250. /package/dist/{data-structures/types/avl-tree.js → interfaces/abstract-graph.js} +0 -0
  251. /package/dist/{data-structures/types/binary-tree.js → interfaces/avl-tree.js} +0 -0
  252. /package/dist/{data-structures/types/bst.js → interfaces/binary-tree.js} +0 -0
  253. /package/dist/{data-structures/types/directed-graph.js → interfaces/bst.js} +0 -0
  254. /package/dist/{data-structures/types/doubly-linked-list.js → interfaces/directed-graph.js} +0 -0
  255. /package/{src/data-structures/hash/pair.ts → dist/interfaces/doubly-linked-list.d.ts} +0 -0
  256. /package/dist/{data-structures/types/heap.js → interfaces/doubly-linked-list.js} +0 -0
  257. /package/{src/data-structures/hash/tree-map.ts → dist/interfaces/heap.d.ts} +0 -0
  258. /package/dist/{data-structures/types/navigator.js → interfaces/heap.js} +0 -0
  259. /package/{src/data-structures/hash/tree-set.ts → dist/interfaces/navigator.d.ts} +0 -0
  260. /package/dist/{data-structures/types/priority-queue.js → interfaces/navigator.js} +0 -0
  261. /package/dist/{data-structures/types/segment-tree.js → interfaces/priority-queue.js} +0 -0
  262. /package/dist/{data-structures/types/singly-linked-list.js → interfaces/rb-tree.js} +0 -0
  263. /package/dist/{data-structures/types/tree-multiset.js → interfaces/segment-tree.js} +0 -0
  264. /package/dist/{data-structures/types → types/data-structures}/segment-tree.d.ts +0 -0
@@ -1,40 +1,31 @@
1
1
  "use strict";
2
2
  /**
3
- * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
4
- * @license MIT
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
5
8
  */
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
- })();
21
9
  Object.defineProperty(exports, "__esModule", { value: true });
22
10
  exports.MinHeap = void 0;
23
- var heap_1 = require("./heap");
24
- var priority_queue_1 = require("../priority-queue");
11
+ const heap_1 = require("./heap");
12
+ const priority_queue_1 = require("../priority-queue");
25
13
  /**
26
14
  * @class MinHeap
27
15
  * @extends Heap
28
16
  */
29
- var MinHeap = /** @class */ (function (_super) {
30
- __extends(MinHeap, _super);
31
- function MinHeap(options) {
32
- var _this = _super.call(this, options) || this;
33
- _this._pq = new priority_queue_1.PriorityQueue({
34
- comparator: function (a, b) { return a.priority - b.priority; }
17
+ class MinHeap extends heap_1.Heap {
18
+ /**
19
+ * The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
20
+ * objects.
21
+ * @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
22
+ * type `HeapOptions<T>`, which is a generic type that represents the options for the heap.
23
+ */
24
+ constructor(options) {
25
+ super(options);
26
+ this._pq = new priority_queue_1.PriorityQueue({
27
+ comparator: (a, b) => a.priority - b.priority
35
28
  });
36
- return _this;
37
29
  }
38
- return MinHeap;
39
- }(heap_1.Heap));
30
+ }
40
31
  exports.MinHeap = MinHeap;
@@ -4,8 +4,8 @@ export * from './stack';
4
4
  export * from './queue';
5
5
  export * from './graph';
6
6
  export * from './binary-tree';
7
+ export * from './tree';
7
8
  export * from './heap';
8
9
  export * from './priority-queue';
9
10
  export * from './matrix';
10
11
  export * from './trie';
11
- export * from './types';
@@ -20,8 +20,8 @@ __exportStar(require("./stack"), exports);
20
20
  __exportStar(require("./queue"), exports);
21
21
  __exportStar(require("./graph"), exports);
22
22
  __exportStar(require("./binary-tree"), exports);
23
+ __exportStar(require("./tree"), exports);
23
24
  __exportStar(require("./heap"), exports);
24
25
  __exportStar(require("./priority-queue"), exports);
25
26
  __exportStar(require("./matrix"), exports);
26
27
  __exportStar(require("./trie"), exports);
27
- __exportStar(require("./types"), exports);
@@ -1,58 +1,195 @@
1
- export declare class DoublyLinkedListNode<T> {
2
- val: T;
3
- next: DoublyLinkedListNode<T> | null;
4
- prev: DoublyLinkedListNode<T> | null;
5
- constructor(nodeValue: T);
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ export declare class DoublyLinkedListNode<T = number> {
9
+ /**
10
+ * The constructor function initializes the value, next, and previous properties of an object.
11
+ * @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
12
+ * is defined as a generic type "T".
13
+ */
14
+ constructor(val: T);
15
+ private _val;
16
+ get val(): T;
17
+ set val(value: T);
18
+ private _next;
19
+ get next(): DoublyLinkedListNode<T> | null;
20
+ set next(value: DoublyLinkedListNode<T> | null);
21
+ private _prev;
22
+ get prev(): DoublyLinkedListNode<T> | null;
23
+ set prev(value: DoublyLinkedListNode<T> | null);
6
24
  }
7
- export declare class DoublyLinkedList<T> {
8
- private _first;
9
- private _last;
10
- private _size;
11
- get size(): number;
12
- set size(v: number);
13
- /**
14
- * Adds a node at the beginning of the linked list
15
- * @param val Value to be stored at the beginning of the linked list
16
- */
17
- offerFirst(val: T): boolean;
18
- /**
19
- * Adds a node to the end of the linked list
20
- * @param val Value to be stored in the Doubly linked list node
21
- */
22
- offerLast(val: T): boolean;
23
- peekFirst(): T | null;
24
- peekFirst(by: 'val'): T | null;
25
- peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
26
- peekLast(): T | null;
27
- peekLast(by: 'val'): T | null;
28
- peekLast(by: 'node'): DoublyLinkedListNode<T> | null;
29
- pollFirst(): T | null;
30
- pollFirst(by: 'val'): T | null;
31
- pollFirst(by: 'node'): DoublyLinkedListNode<T> | null;
32
- pollLast(): T | null;
33
- pollLast(by: 'val'): T | null;
34
- pollLast(by: 'node'): DoublyLinkedListNode<T> | null;
35
- get(index: number): T | null;
36
- get(index: number, by: 'node'): DoublyLinkedListNode<T> | null;
37
- get(index: number, by: 'val'): T | null;
38
- /**
39
- * Updates the value of the node at the specified index.
40
- * If index = 0; Value of the first element in the list is updated.
41
- * If index = 3; Value of the fourth element in the list is updated.
42
- * @param index Index of the node to be updated
43
- * @param val New value of the node
44
- */
45
- set(index: number, val: T): boolean;
46
- isEmpty(): boolean;
47
- /**
48
- * Inserts a new node at the specified index.
49
- * @param index Index at which the new node has to be inserted
50
- * @param val Value of the new node to be inserted
51
- */
52
- insert(index: number, val: T): boolean;
53
- /**
54
- * Removes a node at the specified index and returns its value.
55
- * @param index Index at which the node has to be removed.
56
- */
57
- remove(index: number): T | null;
25
+ export declare class DoublyLinkedList<T = number> {
26
+ /**
27
+ * The constructor initializes the linked list with an empty head, tail, and length.
28
+ */
29
+ constructor();
30
+ private _head;
31
+ get head(): DoublyLinkedListNode<T> | null;
32
+ set head(value: DoublyLinkedListNode<T> | null);
33
+ private _tail;
34
+ get tail(): DoublyLinkedListNode<T> | null;
35
+ set tail(value: DoublyLinkedListNode<T> | null);
36
+ private _length;
37
+ get length(): number;
38
+ /**
39
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
40
+ * given array.
41
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
42
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
43
+ */
44
+ static fromArray<T>(data: T[]): DoublyLinkedList<T>;
45
+ /**
46
+ * The push function adds a new node with the given value to the end of the doubly linked list.
47
+ * @param {T} val - The value to be added to the linked list.
48
+ */
49
+ push(val: T): void;
50
+ /**
51
+ * The `pop()` function removes and returns the value of the last node in a doubly linked list.
52
+ * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
53
+ * list is empty, it returns null.
54
+ */
55
+ pop(): T | null;
56
+ /**
57
+ * The `shift()` function removes and returns the value of the first node in a doubly linked list.
58
+ * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
59
+ * list.
60
+ */
61
+ shift(): T | null;
62
+ /**
63
+ * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
64
+ * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
65
+ * doubly linked list.
66
+ */
67
+ unshift(val: T): void;
68
+ /**
69
+ * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
70
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
71
+ * retrieve from the list.
72
+ * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
73
+ * or the linked list is empty, it will return null.
74
+ */
75
+ getAt(index: number): T | null;
76
+ /**
77
+ * The function `getNodeAt` returns the node at a given index in a doubly linked list, or null if the index is out of
78
+ * range.
79
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
80
+ * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
81
+ * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<T>` object if the index is within the
82
+ * valid range of the linked list, otherwise it returns `null`.
83
+ */
84
+ getNodeAt(index: number): DoublyLinkedListNode<T> | null;
85
+ /**
86
+ * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
87
+ * node if found, otherwise it returns null.
88
+ * @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
89
+ * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<T>` if a node with the specified value `val`
90
+ * is found in the linked list. If no such node is found, it returns `null`.
91
+ */
92
+ findNode(val: T): DoublyLinkedListNode<T> | null;
93
+ /**
94
+ * The `insert` function inserts a value at a specified index in a doubly linked list.
95
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
96
+ * DoublyLinkedList. It is of type number.
97
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
98
+ * specified index.
99
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
100
+ * if the index is out of bounds.
101
+ */
102
+ insertAt(index: number, val: T): boolean;
103
+ /**
104
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
105
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
106
+ * data structure. It is of type number.
107
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
108
+ * bounds.
109
+ */
110
+ deleteAt(index: number): T | null;
111
+ delete(valOrNode: T): boolean;
112
+ delete(valOrNode: DoublyLinkedListNode<T>): boolean;
113
+ /**
114
+ * The `toArray` function converts a linked list into an array.
115
+ * @returns The `toArray()` method is returning an array of type `T[]`.
116
+ */
117
+ toArray(): T[];
118
+ /**
119
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
120
+ */
121
+ clear(): void;
122
+ /**
123
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
124
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
125
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
126
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
127
+ * the callback function. If no element satisfies the condition, it returns `null`.
128
+ */
129
+ find(callback: (val: T) => boolean): T | null;
130
+ /**
131
+ * The function returns the index of the first occurrence of a given value in a linked list.
132
+ * @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
133
+ * that we are searching for in the linked list.
134
+ * @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
135
+ * list. If the value is not found, it returns -1.
136
+ */
137
+ indexOf(val: T): number;
138
+ /**
139
+ * The `findLast` function iterates through a linked list from the last node to the first node and returns the last
140
+ * value that satisfies the given callback function, or null if no value satisfies the callback.
141
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
142
+ * function is used to determine whether a given value satisfies a certain condition.
143
+ * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
144
+ * the callback function. If no value satisfies the condition, it returns `null`.
145
+ */
146
+ findLast(callback: (val: T) => boolean): T | null;
147
+ /**
148
+ * The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
149
+ * @returns The `toArrayReverse()` function returns an array of type `T[]`.
150
+ */
151
+ toArrayReverse(): T[];
152
+ /**
153
+ * The `reverse` function reverses the order of the elements in a doubly linked list.
154
+ */
155
+ reverse(): void;
156
+ /**
157
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
158
+ * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
159
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
160
+ * current node in the linked list.
161
+ */
162
+ forEach(callback: (val: T, index: number) => void): void;
163
+ /**
164
+ * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
165
+ * DoublyLinkedList with the transformed values.
166
+ * @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
167
+ * the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
168
+ * DoublyLinkedList).
169
+ * @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
170
+ */
171
+ map<U>(callback: (val: T) => U): DoublyLinkedList<U>;
172
+ /**
173
+ * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
174
+ * elements that satisfy the given callback function.
175
+ * @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
176
+ * It is used to determine whether a value should be included in the filtered list or not.
177
+ * @returns The filtered list, which is an instance of the DoublyLinkedList class.
178
+ */
179
+ filter(callback: (val: T) => boolean): DoublyLinkedList<T>;
180
+ /**
181
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
182
+ * single value.
183
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
184
+ * used to perform a specific operation on each element of the linked list.
185
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
186
+ * point for the reduction operation.
187
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
188
+ * elements in the linked list.
189
+ */
190
+ reduce<U>(callback: (accumulator: U, val: T) => U, initialValue: U): U;
191
+ insertAfter(existingValueOrNode: T, newValue: T): boolean;
192
+ insertAfter(existingValueOrNode: DoublyLinkedListNode<T>, newValue: T): boolean;
193
+ insertBefore(existingValueOrNode: T, newValue: T): boolean;
194
+ insertBefore(existingValueOrNode: DoublyLinkedListNode<T>, newValue: T): boolean;
58
195
  }