data-structure-typed 2.0.4 → 2.1.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 (261) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/COMMANDS.md +17 -0
  3. package/README.md +11 -11
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +158 -190
  6. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  7. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  8. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  9. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  11. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  12. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  13. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  14. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  20. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  23. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js +608 -875
  26. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  28. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  29. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  32. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  35. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  38. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  40. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  41. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  43. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  44. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  46. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  47. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  48. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  49. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  50. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  51. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  52. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  53. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  54. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  55. package/dist/cjs/data-structures/heap/heap.js +340 -349
  56. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  57. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  58. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  59. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  60. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  61. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  62. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  65. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  68. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  71. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  74. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  77. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  80. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  81. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  82. package/dist/cjs/data-structures/queue/deque.js +309 -348
  83. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  84. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  85. package/dist/cjs/data-structures/queue/queue.js +265 -248
  86. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  87. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  88. package/dist/cjs/data-structures/stack/stack.js +181 -125
  89. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  90. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  91. package/dist/cjs/data-structures/trie/trie.js +189 -172
  92. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  93. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  94. package/dist/cjs/interfaces/graph.d.ts +16 -0
  95. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  96. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  97. package/dist/cjs/types/utils/utils.d.ts +6 -6
  98. package/dist/cjs/utils/utils.d.ts +110 -49
  99. package/dist/cjs/utils/utils.js +148 -73
  100. package/dist/cjs/utils/utils.js.map +1 -1
  101. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  102. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  103. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  104. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  105. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  106. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  107. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  108. package/dist/esm/data-structures/base/linear-base.js +137 -274
  109. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  112. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  115. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  116. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  118. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  119. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js +613 -885
  121. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  122. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  123. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  124. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  127. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  128. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  130. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  133. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  134. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  135. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  136. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  137. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  138. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  139. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  140. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  141. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  142. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  143. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  144. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  145. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  146. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  147. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  148. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  149. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  150. package/dist/esm/data-structures/heap/heap.js +329 -349
  151. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  152. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  153. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  154. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  155. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  156. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  157. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  160. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  163. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  166. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  169. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  172. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  173. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  175. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  176. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  177. package/dist/esm/data-structures/queue/deque.js +313 -348
  178. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  179. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  180. package/dist/esm/data-structures/queue/queue.js +263 -248
  181. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  182. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  183. package/dist/esm/data-structures/stack/stack.js +181 -125
  184. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  185. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  186. package/dist/esm/data-structures/trie/trie.js +193 -172
  187. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  188. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  189. package/dist/esm/interfaces/graph.d.ts +16 -0
  190. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  191. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  192. package/dist/esm/types/utils/utils.d.ts +6 -6
  193. package/dist/esm/utils/utils.d.ts +110 -49
  194. package/dist/esm/utils/utils.js +139 -68
  195. package/dist/esm/utils/utils.js.map +1 -1
  196. package/dist/umd/data-structure-typed.js +4737 -6525
  197. package/dist/umd/data-structure-typed.min.js +8 -6
  198. package/dist/umd/data-structure-typed.min.js.map +1 -1
  199. package/package.json +3 -4
  200. package/src/data-structures/base/iterable-element-base.ts +238 -115
  201. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  202. package/src/data-structures/base/linear-base.ts +271 -277
  203. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  204. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  205. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  206. package/src/data-structures/binary-tree/binary-tree.ts +677 -901
  207. package/src/data-structures/binary-tree/bst.ts +568 -570
  208. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  209. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  210. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  211. package/src/data-structures/graph/abstract-graph.ts +339 -264
  212. package/src/data-structures/graph/directed-graph.ts +146 -236
  213. package/src/data-structures/graph/map-graph.ts +63 -60
  214. package/src/data-structures/graph/undirected-graph.ts +129 -152
  215. package/src/data-structures/hash/hash-map.ts +274 -496
  216. package/src/data-structures/heap/heap.ts +389 -402
  217. package/src/data-structures/heap/max-heap.ts +12 -76
  218. package/src/data-structures/heap/min-heap.ts +13 -76
  219. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  220. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  221. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  222. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  223. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  224. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  225. package/src/data-structures/queue/deque.ts +381 -357
  226. package/src/data-structures/queue/queue.ts +310 -264
  227. package/src/data-structures/stack/stack.ts +217 -131
  228. package/src/data-structures/trie/trie.ts +240 -175
  229. package/src/interfaces/binary-tree.ts +240 -6
  230. package/src/interfaces/graph.ts +37 -0
  231. package/src/types/data-structures/base/base.ts +5 -5
  232. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  233. package/src/types/utils/utils.ts +9 -5
  234. package/src/utils/utils.ts +152 -86
  235. package/test/integration/index.html +1 -1
  236. package/test/performance/benchmark-runner.ts +528 -0
  237. package/test/performance/reportor.mjs +43 -43
  238. package/test/performance/runner-config.json +39 -0
  239. package/test/performance/single-suite-runner.ts +69 -0
  240. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  241. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  242. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  243. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  244. package/test/unit/data-structures/binary-tree/bst.test.ts +84 -5
  245. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  246. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  247. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  248. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  249. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  250. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  251. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  252. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  253. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  254. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  255. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  256. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  258. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  259. package/test/unit/utils/utils.test.ts +0 -1
  260. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  261. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -1,6 +1,17 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import { SinglyLinkedList } from '../linked-list';
2
9
  import { LinearBase } from '../base/linear-base';
3
10
  /**
11
+ * Array-backed queue with amortized O(1) enqueue/dequeue via an offset pointer and optional auto-compaction.
12
+ * @remarks Time O(1), Space O(1)
13
+ * @template E
14
+ * @template R
4
15
  * 1. First In, First Out (FIFO): The core feature of a queue is its first in, first out nature. The element added to the queue first will be the one to be removed first.
5
16
  * 2. Operations: The main operations include enqueue (adding an element to the end of the queue) and dequeue (removing and returning the element at the front of the queue). Typically, there is also a peek operation (looking at the front element without removing it).
6
17
  * 3. Uses: Queues are commonly used to manage a series of tasks or elements that need to be processed in order. For example, managing task queues in a multi-threaded environment, or in algorithms for data structures like trees and graphs for breadth-first search.
@@ -17,7 +28,7 @@ import { LinearBase } from '../base/linear-base';
17
28
  * let maxSum = 0;
18
29
  * let currentSum = 0;
19
30
  *
20
- * nums.forEach((num) => {
31
+ * nums.forEach(num => {
21
32
  * queue.push(num);
22
33
  * currentSum += num;
23
34
  *
@@ -57,6 +68,13 @@ import { LinearBase } from '../base/linear-base';
57
68
  * console.log(visited); // [1, 2, 3, 4, 5]
58
69
  */
59
70
  export class Queue extends LinearBase {
71
+ /**
72
+ * Create a Queue and optionally bulk-insert elements.
73
+ * @remarks Time O(N), Space O(N)
74
+ * @param [elements] - Iterable of elements (or raw records if toElementFn is set).
75
+ * @param [options] - Options such as toElementFn, maxLen, and autoCompactRatio.
76
+ * @returns New Queue instance.
77
+ */
60
78
  constructor(elements = [], options) {
61
79
  super(options);
62
80
  if (options) {
@@ -66,65 +84,88 @@ export class Queue extends LinearBase {
66
84
  this.pushMany(elements);
67
85
  }
68
86
  _elements = [];
87
+ /**
88
+ * Get the underlying array buffer.
89
+ * @remarks Time O(1), Space O(1)
90
+ * @returns Backing array of elements.
91
+ */
69
92
  get elements() {
70
93
  return this._elements;
71
94
  }
72
95
  _offset = 0;
96
+ /**
97
+ * Get the current start offset into the array.
98
+ * @remarks Time O(1), Space O(1)
99
+ * @returns Zero-based offset.
100
+ */
73
101
  get offset() {
74
102
  return this._offset;
75
103
  }
76
- get length() {
77
- return this.elements.length - this.offset;
78
- }
79
104
  _autoCompactRatio = 0.5;
105
+ /**
106
+ * Get the compaction threshold (offset/size).
107
+ * @remarks Time O(1), Space O(1)
108
+ * @returns Auto-compaction ratio in (0,1].
109
+ */
80
110
  get autoCompactRatio() {
81
111
  return this._autoCompactRatio;
82
112
  }
83
- set autoCompactRatio(v) {
84
- this._autoCompactRatio = v;
113
+ /**
114
+ * Set the compaction threshold.
115
+ * @remarks Time O(1), Space O(1)
116
+ * @param value - New ratio; compacts when offset/size exceeds this value.
117
+ * @returns void
118
+ */
119
+ set autoCompactRatio(value) {
120
+ this._autoCompactRatio = value;
85
121
  }
86
122
  /**
87
- * Time Complexity: O(1)
88
- * Space Complexity: O(1)
89
- *
90
- * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
91
- * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
92
- * the `_offset` index. If the data structure is empty (length is 0), it returns `undefined`.
123
+ * Get the number of elements currently in the queue.
124
+ * @remarks Time O(1), Space O(1)
125
+ * @returns Current length.
126
+ */
127
+ get length() {
128
+ return this.elements.length - this._offset;
129
+ }
130
+ /**
131
+ * Get the first element (front) without removing it.
132
+ * @remarks Time O(1), Space O(1)
133
+ * @returns Front element or undefined.
93
134
  */
94
135
  get first() {
95
- return this.length > 0 ? this.elements[this.offset] : undefined;
136
+ return this.length > 0 ? this.elements[this._offset] : undefined;
96
137
  }
97
138
  /**
98
- * Time Complexity: O(1)
99
- * Space Complexity: O(1)
100
- *
101
- * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
102
- * @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
103
- * array is empty, it returns `undefined`.
139
+ * Get the last element (back) without removing it.
140
+ * @remarks Time O(1), Space O(1)
141
+ * @returns Back element or undefined.
104
142
  */
105
143
  get last() {
106
144
  return this.length > 0 ? this.elements[this.elements.length - 1] : undefined;
107
145
  }
108
146
  /**
109
- * Time Complexity: O(n)
110
- * Space Complexity: O(n)
111
- *
112
- * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
113
- * @public
114
- * @param {E[]} elements - The "elements" parameter is an array of elements of type E.
115
- * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
116
- * array.
147
+ * Create a queue from an array of elements.
148
+ * @remarks Time O(N), Space O(N)
149
+ * @template E
150
+ * @param elements - Array of elements to enqueue in order.
151
+ * @returns A new queue populated from the array.
117
152
  */
118
153
  static fromArray(elements) {
119
154
  return new Queue(elements);
120
155
  }
121
156
  /**
122
- * Time Complexity: O(1)
123
- * Space Complexity: O(1)
124
- *
125
- * The push function adds an element to the end of the queue and returns true. Adds an element at the back of the queue.
126
- * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
127
- * @returns Always returns true, indicating the element was successfully added.
157
+ * Check whether the queue is empty.
158
+ * @remarks Time O(1), Space O(1)
159
+ * @returns True if length is 0.
160
+ */
161
+ isEmpty() {
162
+ return this.length === 0;
163
+ }
164
+ /**
165
+ * Enqueue one element at the back.
166
+ * @remarks Time O(1), Space O(1)
167
+ * @param element - Element to enqueue.
168
+ * @returns True on success.
128
169
  */
129
170
  push(element) {
130
171
  this.elements.push(element);
@@ -133,15 +174,10 @@ export class Queue extends LinearBase {
133
174
  return true;
134
175
  }
135
176
  /**
136
- * Time Complexity: O(k)
137
- * Space Complexity: O(k)
138
- *
139
- * The `pushMany` function iterates over elements and pushes them into an array after applying a
140
- * transformation function if provided.
141
- * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
142
- * is an iterable containing elements of type `E` or `R`.
143
- * @returns The `pushMany` function is returning an array of boolean values indicating whether each
144
- * element was successfully pushed into the data structure.
177
+ * Enqueue many elements from an iterable.
178
+ * @remarks Time O(N), Space O(1)
179
+ * @param elements - Iterable of elements (or raw records if toElementFn is set).
180
+ * @returns Array of per-element success flags.
145
181
  */
146
182
  pushMany(elements) {
147
183
  const ans = [];
@@ -154,299 +190,278 @@ export class Queue extends LinearBase {
154
190
  return ans;
155
191
  }
156
192
  /**
157
- * Time Complexity: O(1)
158
- * Space Complexity: O(1)
159
- *
160
- * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
161
- * necessary to optimize performance.
162
- * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
193
+ * Dequeue one element from the front (amortized via offset).
194
+ * @remarks Time O(1) amortized, Space O(1)
195
+ * @returns Removed element or undefined.
163
196
  */
164
197
  shift() {
165
198
  if (this.length === 0)
166
199
  return undefined;
167
200
  const first = this.first;
168
201
  this._offset += 1;
169
- if (this.offset / this.elements.length > this.autoCompactRatio)
202
+ if (this.elements.length > 0 && this.offset / this.elements.length > this.autoCompactRatio)
170
203
  this.compact();
171
204
  return first;
172
205
  }
173
206
  /**
174
- * Time Complexity: O(n)
175
- * Space Complexity: O(1)
176
- *
177
- * The delete function removes an element from the list.
178
- * @param {E} element - Specify the element to be deleted
179
- * @return A boolean value indicating whether the element was successfully deleted or not
207
+ * Delete the first occurrence of a specific element.
208
+ * @remarks Time O(N), Space O(1)
209
+ * @param element - Element to remove (strict equality via Object.is).
210
+ * @returns True if an element was removed.
180
211
  */
181
212
  delete(element) {
182
- const index = this.elements.indexOf(element);
183
- return !!this.deleteAt(index);
184
- }
185
- /**
186
- * Time Complexity: O(n)
187
- * Space Complexity: O(1)
188
- *
189
- * The deleteAt function deletes the element at a given index.
190
- * @param {number} index - Determine the index of the element to be deleted
191
- * @return A boolean value
192
- */
193
- deleteAt(index) {
194
- const deleted = this.elements[index];
195
- this.elements.splice(index, 1);
196
- return deleted;
213
+ for (let i = this._offset; i < this.elements.length; i++) {
214
+ if (Object.is(this.elements[i], element)) {
215
+ this.elements.splice(i, 1);
216
+ return true;
217
+ }
218
+ }
219
+ return false;
197
220
  }
198
221
  /**
199
- * Time Complexity: O(1)
200
- * Space Complexity: O(1)
201
- *
202
- * The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
203
- * if the index is out of bounds.
204
- * @param {number} index - The `index` parameter represents the position of the element you want to
205
- * retrieve from the data structure.
206
- * @returns The `at` method is returning the element at the specified index adjusted by the offset
207
- * `_offset`.
222
+ * Get the element at a given logical index.
223
+ * @remarks Time O(1), Space O(1)
224
+ * @param index - Zero-based index from the front.
225
+ * @returns Element or undefined.
208
226
  */
209
227
  at(index) {
210
- return this.elements[index + this._offset];
228
+ if (index < 0 || index >= this.length)
229
+ return undefined;
230
+ return this._elements[this._offset + index];
211
231
  }
212
232
  /**
213
- * Time Complexity: O(n)
214
- * Space Complexity: O(1)
215
- *
216
- * The `reverse` function in TypeScript reverses the elements of an array starting from a specified
217
- * offset.
218
- * @returns The `reverse()` method is returning the modified object itself (`this`) after reversing
219
- * the elements in the array and resetting the offset to 0.
233
+ * Delete the element at a given index.
234
+ * @remarks Time O(N), Space O(1)
235
+ * @param index - Zero-based index from the front.
236
+ * @returns Removed element or undefined.
220
237
  */
221
- reverse() {
222
- this._elements = this.elements.slice(this.offset).reverse();
223
- this._offset = 0;
224
- return this;
238
+ deleteAt(index) {
239
+ if (index < 0 || index >= this.length)
240
+ return undefined;
241
+ const gi = this._offset + index;
242
+ const [deleted] = this.elements.splice(gi, 1);
243
+ return deleted;
225
244
  }
226
245
  /**
227
- * Time Complexity: O(n)
228
- * Space Complexity: O(1)
229
- *
230
- * The function `addAt` inserts a new element at a specified index in an array, returning true if
231
- * successful and false if the index is out of bounds.
232
- * @param {number} index - The `index` parameter represents the position at which the `newElement`
233
- * should be added in the array.
234
- * @param {E} newElement - The `newElement` parameter represents the element that you want to insert
235
- * into the array at the specified index.
236
- * @returns The `addAt` method returns a boolean value - `true` if the new element was successfully
237
- * added at the specified index, and `false` if the index is out of bounds (less than 0 or greater
238
- * than the length of the array).
246
+ * Insert a new element at a given index.
247
+ * @remarks Time O(N), Space O(1)
248
+ * @param index - Zero-based index from the front.
249
+ * @param newElement - Element to insert.
250
+ * @returns True if inserted.
239
251
  */
240
252
  addAt(index, newElement) {
241
253
  if (index < 0 || index > this.length)
242
254
  return false;
243
- this._elements.splice(this.offset + index, 0, newElement);
255
+ this._elements.splice(this._offset + index, 0, newElement);
244
256
  return true;
245
257
  }
246
258
  /**
247
- * Time Complexity: O(1)
248
- * Space Complexity: O(1)
249
- *
250
- * The function `setAt` updates an element at a specified index in an array-like data structure.
251
- * @param {number} index - The `index` parameter is a number that represents the position in the
252
- * array where the new element will be set.
253
- * @param {E} newElement - The `newElement` parameter represents the new value that you want to set
254
- * at the specified index in the array.
255
- * @returns The `setAt` method returns a boolean value - `true` if the element was successfully set
256
- * at the specified index, and `false` if the index is out of bounds (less than 0 or greater than the
257
- * length of the array).
259
+ * Replace the element at a given index.
260
+ * @remarks Time O(1), Space O(1)
261
+ * @param index - Zero-based index from the front.
262
+ * @param newElement - New element to set.
263
+ * @returns True if updated.
258
264
  */
259
265
  setAt(index, newElement) {
260
- if (index < 0 || index > this.length)
266
+ if (index < 0 || index >= this.length)
261
267
  return false;
262
- this._elements[this.offset + index] = newElement;
268
+ this._elements[this._offset + index] = newElement;
263
269
  return true;
264
270
  }
265
271
  /**
266
- * Time Complexity: O(1)
267
- * Space Complexity: O(1)
268
- *
269
- * The function checks if a data structure is empty by comparing its length to zero.
270
- * @returns {boolean} A boolean value indicating whether the length of the object is 0 or not.
272
+ * Reverse the queue in-place by compacting then reversing.
273
+ * @remarks Time O(N), Space O(N)
274
+ * @returns This queue.
271
275
  */
272
- isEmpty() {
273
- return this.length === 0;
276
+ reverse() {
277
+ this._elements = this.elements.slice(this._offset).reverse();
278
+ this._offset = 0;
279
+ return this;
274
280
  }
275
281
  /**
276
- * Time Complexity: O(1)
277
- * Space Complexity: O(1)
278
- *
279
- * The clear function resets the elements array and offset to their initial values.
282
+ * Remove all elements and reset offset.
283
+ * @remarks Time O(1), Space O(1)
284
+ * @returns void
280
285
  */
281
286
  clear() {
282
287
  this._elements = [];
283
288
  this._offset = 0;
284
289
  }
285
290
  /**
286
- * Time Complexity: O(n)
287
- * Space Complexity: O(1)
288
- *
289
- * The `compact` function in TypeScript slices the elements array based on the offset and resets the
290
- * offset to zero.
291
- * @returns The `compact()` method is returning a boolean value of `true`.
291
+ * Compact storage by discarding consumed head elements.
292
+ * @remarks Time O(N), Space O(N)
293
+ * @returns True when compaction performed.
292
294
  */
293
295
  compact() {
294
- this._elements = this.elements.slice(this.offset);
296
+ this._elements = this.elements.slice(this._offset);
295
297
  this._offset = 0;
296
298
  return true;
297
299
  }
298
300
  /**
299
- * Time Complexity: O(n)
300
- * Space Complexity: O(n)
301
- *
302
- * The function overrides the splice method to remove and insert elements in a queue-like data
303
- * structure.
304
- * @param {number} start - The `start` parameter in the `splice` method specifies the index at which
305
- * to start changing the array. Items will be added or removed starting from this index.
306
- * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
307
- * number of elements to remove from the array starting at the specified `start` index. If
308
- * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
309
- * elements can still be inserted at
310
- * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
311
- * will be added to the array at the specified `start` index. These elements will replace the
312
- * existing elements starting from the `start` index for the `deleteCount` number of elements.
313
- * @returns The `splice` method is returning the `removedQueue`, which is an instance of the same
314
- * class as the original object.
301
+ * Remove and/or insert elements at a position (array-like).
302
+ * @remarks Time O(N + M), Space O(M)
303
+ * @param start - Start index (clamped to [0, length]).
304
+ * @param [deleteCount] - Number of elements to remove (default 0).
305
+ * @param [items] - Elements to insert after `start`.
306
+ * @returns A new queue containing the removed elements (typed as `this`).
315
307
  */
316
308
  splice(start, deleteCount = 0, ...items) {
317
- const removedQueue = this._createInstance();
318
309
  start = Math.max(0, Math.min(start, this.length));
319
310
  deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
320
- const globalStartIndex = this.offset + start;
321
- const removedElements = this._elements.splice(globalStartIndex, deleteCount, ...items);
322
- removedQueue.pushMany(removedElements);
323
- this.compact();
324
- return removedQueue;
311
+ const gi = this._offset + start;
312
+ const removedArray = this._elements.splice(gi, deleteCount, ...items);
313
+ if (this.elements.length > 0 && this.offset / this.elements.length > this.autoCompactRatio)
314
+ this.compact();
315
+ const removed = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
316
+ removed._setAutoCompactRatio(this._autoCompactRatio);
317
+ removed.pushMany(removedArray);
318
+ return removed;
325
319
  }
326
320
  /**
327
- * Time Complexity: O(n)
328
- * Space Complexity: O(n)
329
- *
330
- * The `clone()` function returns a new Queue object with the same elements as the original Queue.
331
- * @returns The `clone()` method is returning a new instance of the `Queue` class.
321
+ * Deep clone this queue and its parameters.
322
+ * @remarks Time O(N), Space O(N)
323
+ * @returns A new queue with the same content and options.
332
324
  */
333
325
  clone() {
334
- return new Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn, maxLen: this._maxLen });
335
- }
336
- /**
337
- * Time Complexity: O(n)
338
- * Space Complexity: O(n)
339
- *
340
- * The `filter` function creates a new `Queue` object containing elements from the original `Queue`
341
- * that satisfy a given predicate function.
342
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
343
- * the current element being iterated over, the index of the current element, and the queue itself.
344
- * It should return a boolean value indicating whether the element should be included in the filtered
345
- * queue or not.
346
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
347
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
348
- * passed as the `this` value to the `predicate` function. If `thisArg` is
349
- * @returns The `filter` method is returning a new `Queue` object that contains the elements that
350
- * satisfy the given predicate function.
326
+ const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
327
+ out._setAutoCompactRatio(this._autoCompactRatio);
328
+ for (let i = this._offset; i < this.elements.length; i++)
329
+ out.push(this.elements[i]);
330
+ return out;
331
+ }
332
+ /**
333
+ * Filter elements into a new queue of the same class.
334
+ * @remarks Time O(N), Space O(N)
335
+ * @param predicate - Predicate (element, index, queue) boolean to keep element.
336
+ * @param [thisArg] - Value for `this` inside the predicate.
337
+ * @returns A new queue with kept elements.
351
338
  */
352
339
  filter(predicate, thisArg) {
353
- const newDeque = this._createInstance({
354
- toElementFn: this._toElementFn,
355
- autoCompactRatio: this._autoCompactRatio,
356
- maxLen: this._maxLen
357
- });
340
+ const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
341
+ out._setAutoCompactRatio(this._autoCompactRatio);
358
342
  let index = 0;
359
- for (const el of this) {
360
- if (predicate.call(thisArg, el, index, this)) {
361
- newDeque.push(el);
362
- }
343
+ for (const v of this) {
344
+ if (predicate.call(thisArg, v, index, this))
345
+ out.push(v);
363
346
  index++;
364
347
  }
365
- return newDeque;
366
- }
367
- /**
368
- * Time Complexity: O(n)
369
- * Space Complexity: O(n)
370
- *
371
- * The `map` function in TypeScript creates a new Queue by applying a callback function to each
372
- * element in the original Queue.
373
- * @param callback - The `callback` parameter is a function that will be applied to each element in
374
- * the queue. It takes the current element, its index, and the queue itself as arguments, and returns
375
- * a new element.
376
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
377
- * convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
378
- * `map` method to transform each raw element before passing it to the `callback` function. If
379
- * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
380
- * value of `this` when executing the `callback` function. It allows you to set the context (the
381
- * value of `this`) within the callback function. If `thisArg` is provided, it will be
382
- * @returns A new Queue object containing elements of type EM, which are the result of applying the
383
- * callback function to each element in the original Queue object.
384
- */
385
- map(callback, toElementFn, thisArg) {
386
- const newDeque = new Queue([], {
387
- toElementFn,
388
- autoCompactRatio: this._autoCompactRatio,
389
- maxLen: this._maxLen
348
+ return out;
349
+ }
350
+ /**
351
+ * Map each element to a new element in a possibly different-typed queue.
352
+ * @remarks Time O(N), Space O(N)
353
+ * @template EM
354
+ * @template RM
355
+ * @param callback - Mapping function (element, index, queue) newElement.
356
+ * @param [options] - Options for the output queue (e.g., toElementFn, maxLen, autoCompactRatio).
357
+ * @param [thisArg] - Value for `this` inside the callback.
358
+ * @returns A new Queue with mapped elements.
359
+ */
360
+ map(callback, options, thisArg) {
361
+ const out = new this.constructor([], {
362
+ toElementFn: options?.toElementFn,
363
+ maxLen: options?.maxLen ?? this._maxLen,
364
+ autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
390
365
  });
391
366
  let index = 0;
392
- for (const el of this) {
393
- newDeque.push(callback.call(thisArg, el, index, this));
394
- index++;
395
- }
396
- return newDeque;
367
+ for (const v of this)
368
+ out.push(thisArg === undefined ? callback(v, index++, this) : callback.call(thisArg, v, index++, this));
369
+ return out;
397
370
  }
398
371
  /**
399
- * Time Complexity: O(n)
400
- * Space Complexity: O(n)
401
- *
402
- * The function `_getIterator` returns an iterable iterator for the elements in the class.
372
+ * Map each element to a new value of the same type.
373
+ * @remarks Time O(N), Space O(N)
374
+ * @param callback - Mapping function (element, index, queue) → element.
375
+ * @param [thisArg] - Value for `this` inside the callback.
376
+ * @returns A new queue with mapped elements (same element type).
403
377
  */
404
- *_getIterator() {
405
- for (const item of this.elements.slice(this.offset)) {
406
- yield item;
378
+ mapSame(callback, thisArg) {
379
+ const Ctor = this.constructor;
380
+ const out = new Ctor([], {
381
+ toElementFn: this.toElementFn,
382
+ maxLen: this._maxLen,
383
+ autoCompactRatio: this._autoCompactRatio
384
+ });
385
+ out._setAutoCompactRatio?.(this._autoCompactRatio);
386
+ let index = 0;
387
+ for (const v of this) {
388
+ const mv = thisArg === undefined ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
389
+ out.push(mv);
407
390
  }
391
+ return out;
408
392
  }
409
393
  /**
410
- * The function `_createInstance` returns a new instance of the `Queue` class with the specified
411
- * options.
412
- * @param [options] - The `options` parameter in the `_createInstance` method is of type
413
- * `QueueOptions<E, R>`, which is used to configure the behavior of the queue being created. It
414
- * allows you to specify settings or properties that can influence how the queue operates.
415
- * @returns An instance of the `Queue` class with an empty array and the provided options is being
416
- * returned.
394
+ * (Protected) Set the internal auto-compaction ratio.
395
+ * @remarks Time O(1), Space O(1)
396
+ * @param value - New ratio to assign.
397
+ * @returns void
417
398
  */
418
- _createInstance(options) {
419
- return new Queue([], options);
399
+ _setAutoCompactRatio(value) {
400
+ this._autoCompactRatio = value;
420
401
  }
421
402
  /**
422
- * The function `_getReverseIterator` returns an iterator that iterates over elements in reverse
423
- * order.
403
+ * (Protected) Iterate elements from front to back.
404
+ * @remarks Time O(N), Space O(1)
405
+ * @returns Iterator of E.
406
+ */
407
+ *_getIterator() {
408
+ for (let i = this._offset; i < this.elements.length; i++)
409
+ yield this.elements[i];
410
+ }
411
+ /**
412
+ * (Protected) Iterate elements from back to front.
413
+ * @remarks Time O(N), Space O(1)
414
+ * @returns Iterator of E.
424
415
  */
425
416
  *_getReverseIterator() {
426
417
  for (let i = this.length - 1; i >= 0; i--) {
427
- const cur = this.at(i); // `at()` handles the offset.
418
+ const cur = this.at(i);
428
419
  if (cur !== undefined)
429
420
  yield cur;
430
421
  }
431
422
  }
423
+ /**
424
+ * (Protected) Create an empty instance of the same concrete class.
425
+ * @remarks Time O(1), Space O(1)
426
+ * @param [options] - Options forwarded to the constructor.
427
+ * @returns An empty like-kind queue instance.
428
+ */
429
+ _createInstance(options) {
430
+ const Ctor = this.constructor;
431
+ return new Ctor([], options);
432
+ }
433
+ /**
434
+ * (Protected) Create a like-kind queue and seed it from an iterable.
435
+ * @remarks Time O(N), Space O(N)
436
+ * @template EM
437
+ * @template RM
438
+ * @param [elements] - Iterable used to seed the new queue.
439
+ * @param [options] - Options forwarded to the constructor.
440
+ * @returns A like-kind Queue instance.
441
+ */
442
+ _createLike(elements = [], options) {
443
+ const Ctor = this.constructor;
444
+ return new Ctor(elements, options);
445
+ }
432
446
  }
433
447
  /**
434
- * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
435
- * 2. Based on Linked List: LinkedListQueue uses a linked list to store elements. Each node in the linked list contains data and a pointer to the next node.
436
- * 3. Memory Usage: Since each element requires additional space to store a pointer to the next element, linked lists may use more memory compared to arrays.
437
- * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
448
+ * Queue implemented over a singly linked list; preserves head/tail operations with linear scans for queries.
449
+ * @remarks Time O(1), Space O(1)
450
+ * @template E
451
+ * @template R
452
+ * @example examples will be generated by unit test
438
453
  */
439
454
  export class LinkedListQueue extends SinglyLinkedList {
440
455
  /**
441
- * Time Complexity: O(n)
442
- * Space Complexity: O(n)
443
- * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
444
- * the current instance.
445
- * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
446
- * values as the original `LinkedListQueue`.
456
+ * Deep clone this linked-list-based queue.
457
+ * @remarks Time O(N), Space O(N)
458
+ * @returns A new queue with the same sequence of elements.
447
459
  */
448
460
  clone() {
449
- return new LinkedListQueue(this, { toElementFn: this.toElementFn, maxLen: this._maxLen });
461
+ const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
462
+ for (const v of this)
463
+ out.push(v);
464
+ return out;
450
465
  }
451
466
  }
452
467
  //# sourceMappingURL=queue.js.map