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,37 +1,24 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
19
- var linked_list_1 = require("../linked-list");
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ const linked_list_1 = require("../linked-list");
20
12
  // O(n) time complexity of obtaining the value
21
13
  // O(1) time complexity of adding at the beginning and the end
22
- var Deque = /** @class */ (function (_super) {
23
- __extends(Deque, _super);
24
- function Deque() {
25
- return _super !== null && _super.apply(this, arguments) || this;
26
- }
27
- return Deque;
28
- }(linked_list_1.DoublyLinkedList));
14
+ class Deque extends linked_list_1.DoublyLinkedList {
15
+ }
29
16
  exports.Deque = Deque;
30
17
  // O(1) time complexity of obtaining the value
31
18
  // O(n) time complexity of adding at the beginning and the end
32
19
  // todo tested slowest one
33
- var ObjectDeque = /** @class */ (function () {
34
- function ObjectDeque(capacity) {
20
+ class ObjectDeque {
21
+ constructor(capacity) {
35
22
  this._nodes = {};
36
23
  this._capacity = Number.MAX_SAFE_INTEGER;
37
24
  this._first = -1;
@@ -40,12 +27,38 @@ var ObjectDeque = /** @class */ (function () {
40
27
  if (capacity !== undefined)
41
28
  this._capacity = capacity;
42
29
  }
43
- ObjectDeque.prototype.size = function () {
30
+ get nodes() {
31
+ return this._nodes;
32
+ }
33
+ get capacity() {
34
+ return this._capacity;
35
+ }
36
+ set capacity(value) {
37
+ this._capacity = value;
38
+ }
39
+ get first() {
40
+ return this._first;
41
+ }
42
+ set first(value) {
43
+ this._first = value;
44
+ }
45
+ get last() {
46
+ return this._last;
47
+ }
48
+ set last(value) {
49
+ this._last = value;
50
+ }
51
+ get size() {
44
52
  return this._size;
45
- };
46
- ObjectDeque.prototype.offerFirst = function (value) {
53
+ }
54
+ /**
55
+ * The "addFirst" function adds a value to the beginning of an array-like data structure.
56
+ * @param {T} value - The `value` parameter represents the value that you want to add to the beginning of the data
57
+ * structure.
58
+ */
59
+ addFirst(value) {
47
60
  if (this._size === 0) {
48
- var mid = Math.floor(this._capacity / 2);
61
+ const mid = Math.floor(this._capacity / 2);
49
62
  this._first = mid;
50
63
  this._last = mid;
51
64
  }
@@ -54,10 +67,14 @@ var ObjectDeque = /** @class */ (function () {
54
67
  }
55
68
  this._nodes[this._first] = value;
56
69
  this._size++;
57
- };
58
- ObjectDeque.prototype.offerLast = function (value) {
70
+ }
71
+ /**
72
+ * The addLast function adds a value to the end of an array-like data structure.
73
+ * @param {T} value - The `value` parameter represents the value that you want to add to the end of the data structure.
74
+ */
75
+ addLast(value) {
59
76
  if (this._size === 0) {
60
- var mid = Math.floor(this._capacity / 2);
77
+ const mid = Math.floor(this._capacity / 2);
61
78
  this._first = mid;
62
79
  this._last = mid;
63
80
  }
@@ -66,93 +83,194 @@ var ObjectDeque = /** @class */ (function () {
66
83
  }
67
84
  this._nodes[this._last] = value;
68
85
  this._size++;
69
- };
70
- ObjectDeque.prototype.pollFirst = function () {
86
+ }
87
+ /**
88
+ * The function `pollFirst()` removes and returns the first element in a data structure.
89
+ * @returns The value of the first element in the data structure.
90
+ */
91
+ pollFirst() {
71
92
  if (!this._size)
72
93
  return;
73
- var value = this.peekFirst();
94
+ const value = this.peekFirst();
74
95
  delete this._nodes[this._first];
75
96
  this._first++;
76
97
  this._size--;
77
98
  return value;
78
- };
79
- ObjectDeque.prototype.peekFirst = function () {
99
+ }
100
+ /**
101
+ * The `peekFirst` function returns the first element in an array-like data structure if it exists.
102
+ * @returns The element at the first position of the `_nodes` array.
103
+ */
104
+ peekFirst() {
80
105
  if (this._size)
81
106
  return this._nodes[this._first];
82
- };
83
- ObjectDeque.prototype.pollLast = function () {
107
+ }
108
+ /**
109
+ * The `pollLast()` function removes and returns the last element in a data structure.
110
+ * @returns The value that was removed from the data structure.
111
+ */
112
+ pollLast() {
84
113
  if (!this._size)
85
114
  return;
86
- var value = this.peekLast();
115
+ const value = this.peekLast();
87
116
  delete this._nodes[this._last];
88
117
  this._last--;
89
118
  this._size--;
90
119
  return value;
91
- };
92
- ObjectDeque.prototype.peekLast = function () {
120
+ }
121
+ /**
122
+ * The `peekLast()` function returns the last element in an array-like data structure.
123
+ * @returns The last element in the array "_nodes" is being returned.
124
+ */
125
+ peekLast() {
93
126
  if (this._size)
94
127
  return this._nodes[this._last];
95
- };
96
- ObjectDeque.prototype.get = function (index) {
128
+ }
129
+ /**
130
+ * The get function returns the element at the specified index in an array-like data structure.
131
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
132
+ * retrieve from the array.
133
+ * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
134
+ * index, `null` is returned.
135
+ */
136
+ get(index) {
97
137
  return this._nodes[this._first + index] || null;
98
- };
99
- ObjectDeque.prototype.isEmpty = function () {
138
+ }
139
+ /**
140
+ * The function checks if the size of a data structure is less than or equal to zero.
141
+ * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
142
+ */
143
+ isEmpty() {
100
144
  return this._size <= 0;
101
- };
102
- return ObjectDeque;
103
- }());
145
+ }
146
+ _seNodes(value) {
147
+ this._nodes = value;
148
+ }
149
+ _setSize(value) {
150
+ this._size = value;
151
+ }
152
+ }
104
153
  exports.ObjectDeque = ObjectDeque;
105
154
  // O(1) time complexity of obtaining the value
106
155
  // O(n) time complexity of adding at the beginning and the end
107
- var ArrayDeque = /** @class */ (function () {
108
- function ArrayDeque() {
156
+ class ArrayDeque {
157
+ constructor() {
109
158
  this._nodes = [];
110
159
  }
111
- Object.defineProperty(ArrayDeque.prototype, "size", {
112
- get: function () {
113
- return this._nodes.length;
114
- },
115
- enumerable: false,
116
- configurable: true
117
- });
118
- ArrayDeque.prototype.offerLast = function (value) {
160
+ get size() {
161
+ return this._nodes.length;
162
+ }
163
+ /**
164
+ * O(n) time complexity of adding at the beginning and the end
165
+ */
166
+ /**
167
+ * The function "addLast" adds a value to the end of an array.
168
+ * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
169
+ * @returns The return value is the new length of the array after the value has been added.
170
+ */
171
+ addLast(value) {
119
172
  return this._nodes.push(value);
120
- };
121
- ArrayDeque.prototype.pollLast = function () {
173
+ }
174
+ /**
175
+ * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
176
+ * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
177
+ */
178
+ pollLast() {
122
179
  var _a;
123
180
  return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
124
- };
125
- ArrayDeque.prototype.pollFirst = function () {
181
+ }
182
+ /**
183
+ * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
184
+ * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
185
+ * empty.
186
+ */
187
+ pollFirst() {
126
188
  var _a;
127
189
  return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
128
- };
129
- ArrayDeque.prototype.offerFirst = function (value) {
190
+ }
191
+ /**
192
+ * O(n) time complexity of adding at the beginning and the end
193
+ */
194
+ /**
195
+ * The function "addFirst" adds a value to the beginning of an array.
196
+ * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
197
+ * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
198
+ * `value` at the beginning.
199
+ */
200
+ addFirst(value) {
130
201
  return this._nodes.unshift(value);
131
- };
132
- ArrayDeque.prototype.peekFirst = function () {
202
+ }
203
+ /**
204
+ * The `peekFirst` function returns the first element of an array or null if the array is empty.
205
+ * @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
206
+ * empty, it will return `null`.
207
+ */
208
+ peekFirst() {
133
209
  var _a;
134
210
  return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
135
- };
136
- ArrayDeque.prototype.peekLast = function () {
211
+ }
212
+ /**
213
+ * The `peekLast` function returns the last element of an array or null if the array is empty.
214
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
215
+ */
216
+ peekLast() {
137
217
  var _a;
138
218
  return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
139
- };
140
- ArrayDeque.prototype.get = function (index) {
219
+ }
220
+ /**
221
+ * O(1) time complexity of obtaining the value
222
+ */
223
+ /**
224
+ * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
225
+ * @param {number} index - The index parameter is a number that represents the position of the element you want to
226
+ * retrieve from the array.
227
+ * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
228
+ * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
229
+ */
230
+ get(index) {
141
231
  var _a;
142
232
  return (_a = this._nodes[index]) !== null && _a !== void 0 ? _a : null;
143
- };
144
- ArrayDeque.prototype.set = function (index, value) {
233
+ }
234
+ /**
235
+ * The set function assigns a value to a specific index in an array.
236
+ * @param {number} index - The index parameter is a number that represents the position of the element in the array
237
+ * that you want to set a new value for.
238
+ * @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
239
+ * _nodes array.
240
+ * @returns The value that is being set at the specified index in the `_nodes` array.
241
+ */
242
+ set(index, value) {
145
243
  return this._nodes[index] = value;
146
- };
147
- ArrayDeque.prototype.insert = function (index, value) {
244
+ }
245
+ /**
246
+ * The insert function adds a value at a specified index in an array.
247
+ * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
248
+ * array. It is a number that represents the index of the array where the value should be inserted. The index starts
249
+ * from 0, so the first element of the array has an index of 0, the second element has
250
+ * @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
251
+ * index.
252
+ * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
253
+ * are being removed, an empty array will be returned.
254
+ */
255
+ insert(index, value) {
148
256
  return this._nodes.splice(index, 0, value);
149
- };
150
- ArrayDeque.prototype.remove = function (index) {
257
+ }
258
+ /**
259
+ * The remove function removes an element from an array at a specified index.
260
+ * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
261
+ * is a number that represents the index of the element to be removed.
262
+ * @returns The method is returning an array containing the removed element.
263
+ */
264
+ remove(index) {
151
265
  return this._nodes.splice(index, 1);
152
- };
153
- ArrayDeque.prototype.isEmpty = function () {
266
+ }
267
+ /**
268
+ * The function checks if an array called "_nodes" is empty.
269
+ * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
270
+ * is 0, indicating that the array is empty. Otherwise, it returns `false`.
271
+ */
272
+ isEmpty() {
154
273
  return this._nodes.length === 0;
155
- };
156
- return ArrayDeque;
157
- }());
274
+ }
275
+ }
158
276
  exports.ArrayDeque = ArrayDeque;
@@ -1,75 +1,102 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright 2020 Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
- export declare class Queue<T> {
6
+ import { SinglyLinkedList } from '../linked-list';
7
+ export declare class Queue<T = any> extends SinglyLinkedList<T> {
8
+ /**
9
+ * The enqueue function adds a value to the end of an array.
10
+ * @param {T} value - The value parameter represents the value that you want to add to the queue.
11
+ */
12
+ enqueue(value: T): void;
13
+ /**
14
+ * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
15
+ * @returns The method is returning the element at the front of the queue, or null if the queue is empty.
16
+ */
17
+ dequeue(): T | undefined;
18
+ /**
19
+ * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
20
+ * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
21
+ */
22
+ peek(): T | undefined;
23
+ [Symbol.iterator](): Generator<T, void, unknown>;
24
+ }
25
+ export declare class ArrayQueue<T = number> {
7
26
  protected _nodes: T[];
8
27
  protected _offset: number;
9
28
  /**
10
- * Creates a queue.
11
- * @param {array} [elements]
29
+ * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
30
+ * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
31
+ * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
32
+ * initialized as an empty array.
12
33
  */
13
34
  constructor(elements?: T[]);
14
35
  /**
15
- * Creates a queue from an existing array.
36
+ * The size function returns the number of elements in an array.
37
+ * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
38
+ */
39
+ get size(): number;
40
+ /**
41
+ * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
16
42
  * @public
17
43
  * @static
18
- * @param {array} elements
19
- * @return {Queue}
44
+ * @param {T[]} elements - The "elements" parameter is an array of elements of type T.
45
+ * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
46
+ * array.
20
47
  */
21
- static fromArray<T>(elements: T[]): Queue<T>;
48
+ static fromArray<T>(elements: T[]): ArrayQueue<T>;
22
49
  /**
23
- * Adds an element at the back of the queue.
24
- * @public
25
- * @param {any} element
50
+ * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
51
+ * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
52
+ * @returns The `add` method is returning a `Queue<T>` object.
26
53
  */
27
- offer(element: T): Queue<T>;
54
+ push(element: T): ArrayQueue<T>;
28
55
  /**
29
- * Dequeues the front element in the queue.
30
- * @public
31
- * @returns {any}
56
+ * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
57
+ * necessary to optimize performance.
58
+ * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
32
59
  */
33
- poll(): T | null;
60
+ shift(): T | null;
34
61
  /**
35
- * Returns the front element of the queue.
36
- * @public
37
- * @returns {any}
62
+ * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
63
+ * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
64
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
38
65
  */
39
66
  peek(): T | null;
40
67
  /**
41
- * Returns the back element of the queue.
42
- * @public
43
- * @returns {any}
68
+ * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
69
+ * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
70
+ * array is empty, it returns `null`.
44
71
  */
45
72
  peekLast(): T | null;
46
73
  /**
47
- * Returns the number of elements in the queue.
48
- * @public
49
- * @returns {number}
74
+ * The enqueue function adds a value to the end of a queue.
75
+ * @param {T} value - The value parameter represents the value that you want to add to the queue.
50
76
  */
51
- size(): number;
77
+ enqueue(value: T): void;
52
78
  /**
53
- * Checks if the queue is empty.
54
- * @public
55
- * @returns {boolean}
79
+ * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
80
+ * @returns The method is returning a value of type T or null.
81
+ */
82
+ dequeue(): T | null;
83
+ /**
84
+ * The function checks if a data structure is empty by comparing its size to zero.
85
+ * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
56
86
  */
57
87
  isEmpty(): boolean;
58
88
  /**
59
- * Returns the remaining elements in the queue as an array.
60
- * @public
61
- * @returns {array}
89
+ * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
90
+ * @returns An array of type T is being returned.
62
91
  */
63
92
  toArray(): T[];
64
93
  /**
65
- * Clears the queue.
66
- * @public
94
+ * The clear function resets the nodes array and offset to their initial values.
67
95
  */
68
96
  clear(): void;
69
97
  /**
70
- * Creates a shallow copy of the queue.
71
- * @public
72
- * @return {Queue}
98
+ * The `clone()` function returns a new Queue object with the same elements as the original Queue.
99
+ * @returns The `clone()` method is returning a new instance of the `Queue` class.
73
100
  */
74
- clone(): Queue<T>;
101
+ clone(): ArrayQueue<T>;
75
102
  }