data-structure-typed 2.0.5 → 2.1.1

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 (785) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/COMMANDS.md +27 -0
  3. package/README.md +5 -34
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +152 -184
  6. package/dist/cjs/index.cjs +13062 -0
  7. package/dist/cjs/index.cjs.map +1 -0
  8. package/dist/esm/index.mjs +12984 -0
  9. package/dist/esm/index.mjs.map +1 -0
  10. package/dist/index.cjs +13091 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.js +13013 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  15. package/dist/types/data-structures/base/iterable-entry-base.d.ts +144 -0
  16. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  17. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -0
  18. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -0
  19. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -0
  20. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -0
  21. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -0
  22. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -0
  23. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -0
  24. package/dist/{esm → types}/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  25. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  26. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -0
  27. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  28. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -0
  29. package/dist/types/data-structures/hash/hash-map.d.ts +345 -0
  30. package/dist/types/data-structures/heap/heap.d.ts +503 -0
  31. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  32. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -0
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -0
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +431 -0
  40. package/dist/types/data-structures/queue/queue.d.ts +308 -0
  41. package/dist/{cjs → types}/data-structures/stack/stack.d.ts +124 -102
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -0
  43. package/dist/types/interfaces/binary-tree.d.ts +59 -0
  44. package/dist/types/interfaces/graph.d.ts +21 -0
  45. package/dist/{cjs → types}/types/data-structures/base/base.d.ts +1 -1
  46. package/dist/{esm → types}/types/data-structures/graph/abstract-graph.d.ts +4 -0
  47. package/dist/{cjs → types}/types/utils/utils.d.ts +1 -0
  48. package/dist/{esm → types}/utils/utils.d.ts +1 -1
  49. package/dist/umd/data-structure-typed.js +4693 -6484
  50. package/dist/umd/data-structure-typed.js.map +1 -0
  51. package/dist/umd/data-structure-typed.min.js +8 -6
  52. package/dist/umd/data-structure-typed.min.js.map +1 -1
  53. package/jest.integration.config.js +3 -0
  54. package/package.json +13 -12
  55. package/src/data-structures/base/iterable-element-base.ts +238 -115
  56. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  57. package/src/data-structures/base/linear-base.ts +271 -277
  58. package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
  59. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  60. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  61. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  62. package/src/data-structures/binary-tree/bst.ts +565 -572
  63. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  64. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  65. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  66. package/src/data-structures/graph/abstract-graph.ts +339 -264
  67. package/src/data-structures/graph/directed-graph.ts +146 -236
  68. package/src/data-structures/graph/map-graph.ts +63 -60
  69. package/src/data-structures/graph/undirected-graph.ts +129 -152
  70. package/src/data-structures/hash/hash-map.ts +274 -496
  71. package/src/data-structures/heap/heap.ts +389 -402
  72. package/src/data-structures/heap/max-heap.ts +12 -76
  73. package/src/data-structures/heap/min-heap.ts +13 -76
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  75. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  76. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  78. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  79. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  80. package/src/data-structures/queue/deque.ts +381 -357
  81. package/src/data-structures/queue/queue.ts +310 -264
  82. package/src/data-structures/stack/stack.ts +217 -131
  83. package/src/data-structures/trie/trie.ts +240 -175
  84. package/src/interfaces/binary-tree.ts +240 -6
  85. package/src/interfaces/graph.ts +37 -0
  86. package/src/types/data-structures/base/base.ts +5 -5
  87. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  88. package/src/types/utils/utils.ts +2 -0
  89. package/src/utils/utils.ts +9 -14
  90. package/test/integration/all-in-one.test.ts +1 -1
  91. package/test/integration/index.html +1 -1
  92. package/test/performance/benchmark-runner.ts +528 -0
  93. package/test/performance/data-structures/comparison/comparison.test.ts +27 -57
  94. package/test/performance/reportor.mjs +43 -43
  95. package/test/performance/runner-config.json +39 -0
  96. package/test/performance/single-suite-runner.ts +69 -0
  97. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  98. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  99. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  100. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  101. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  102. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  103. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  104. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +112 -4
  105. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  106. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  107. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  108. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  109. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  110. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  111. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  112. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  113. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  114. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  115. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  116. package/test/unit/utils/utils.test.ts +0 -1
  117. package/tsconfig-base.json +20 -20
  118. package/tsconfig-types.json +17 -0
  119. package/tsconfig.test.json +8 -0
  120. package/tsup.config.js +11 -22
  121. package/tsup.node.config.ts +37 -0
  122. package/dist/cjs/common/index.js +0 -29
  123. package/dist/cjs/common/index.js.map +0 -1
  124. package/dist/cjs/data-structures/base/index.js +0 -19
  125. package/dist/cjs/data-structures/base/index.js.map +0 -1
  126. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +0 -116
  127. package/dist/cjs/data-structures/base/iterable-element-base.js +0 -202
  128. package/dist/cjs/data-structures/base/iterable-element-base.js.map +0 -1
  129. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +0 -168
  130. package/dist/cjs/data-structures/base/iterable-entry-base.js +0 -241
  131. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +0 -1
  132. package/dist/cjs/data-structures/base/linear-base.d.ts +0 -277
  133. package/dist/cjs/data-structures/base/linear-base.js +0 -553
  134. package/dist/cjs/data-structures/base/linear-base.js.map +0 -1
  135. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  136. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +0 -409
  137. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  138. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  139. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +0 -203
  140. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  141. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -302
  142. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -599
  143. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +0 -1
  144. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +0 -295
  145. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  146. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -910
  147. package/dist/cjs/data-structures/binary-tree/binary-tree.js +0 -2197
  148. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +0 -1
  149. package/dist/cjs/data-structures/binary-tree/bst.d.ts +0 -461
  150. package/dist/cjs/data-structures/binary-tree/bst.js +0 -880
  151. package/dist/cjs/data-structures/binary-tree/bst.js.map +0 -1
  152. package/dist/cjs/data-structures/binary-tree/index.js +0 -27
  153. package/dist/cjs/data-structures/binary-tree/index.js.map +0 -1
  154. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  155. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +0 -642
  156. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
  157. package/dist/cjs/data-structures/binary-tree/segment-tree.js +0 -298
  158. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +0 -1
  159. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +0 -212
  160. package/dist/cjs/data-structures/binary-tree/tree-counter.js +0 -445
  161. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +0 -1
  162. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -267
  163. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +0 -365
  164. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  165. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -335
  166. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -867
  167. package/dist/cjs/data-structures/graph/abstract-graph.js.map +0 -1
  168. package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -323
  169. package/dist/cjs/data-structures/graph/directed-graph.js +0 -613
  170. package/dist/cjs/data-structures/graph/directed-graph.js.map +0 -1
  171. package/dist/cjs/data-structures/graph/index.js +0 -21
  172. package/dist/cjs/data-structures/graph/index.js.map +0 -1
  173. package/dist/cjs/data-structures/graph/map-graph.d.ts +0 -84
  174. package/dist/cjs/data-structures/graph/map-graph.js +0 -111
  175. package/dist/cjs/data-structures/graph/map-graph.js.map +0 -1
  176. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -231
  177. package/dist/cjs/data-structures/graph/undirected-graph.js +0 -445
  178. package/dist/cjs/data-structures/graph/undirected-graph.js.map +0 -1
  179. package/dist/cjs/data-structures/hash/hash-map.d.ts +0 -519
  180. package/dist/cjs/data-structures/hash/hash-map.js +0 -880
  181. package/dist/cjs/data-structures/hash/hash-map.js.map +0 -1
  182. package/dist/cjs/data-structures/hash/index.js +0 -18
  183. package/dist/cjs/data-structures/hash/index.js.map +0 -1
  184. package/dist/cjs/data-structures/heap/heap.d.ts +0 -578
  185. package/dist/cjs/data-structures/heap/heap.js +0 -911
  186. package/dist/cjs/data-structures/heap/heap.js.map +0 -1
  187. package/dist/cjs/data-structures/heap/index.js +0 -20
  188. package/dist/cjs/data-structures/heap/index.js.map +0 -1
  189. package/dist/cjs/data-structures/heap/max-heap.d.ts +0 -68
  190. package/dist/cjs/data-structures/heap/max-heap.js +0 -96
  191. package/dist/cjs/data-structures/heap/max-heap.js.map +0 -1
  192. package/dist/cjs/data-structures/heap/min-heap.d.ts +0 -68
  193. package/dist/cjs/data-structures/heap/min-heap.js +0 -87
  194. package/dist/cjs/data-structures/heap/min-heap.js.map +0 -1
  195. package/dist/cjs/data-structures/index.js +0 -29
  196. package/dist/cjs/data-structures/index.js.map +0 -1
  197. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  198. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +0 -1238
  199. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  200. package/dist/cjs/data-structures/linked-list/index.js +0 -20
  201. package/dist/cjs/data-structures/linked-list/index.js.map +0 -1
  202. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  203. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -870
  204. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
  205. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  206. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -245
  207. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
  208. package/dist/cjs/data-structures/matrix/index.js +0 -19
  209. package/dist/cjs/data-structures/matrix/index.js.map +0 -1
  210. package/dist/cjs/data-structures/matrix/matrix.js +0 -449
  211. package/dist/cjs/data-structures/matrix/matrix.js.map +0 -1
  212. package/dist/cjs/data-structures/matrix/navigator.js +0 -112
  213. package/dist/cjs/data-structures/matrix/navigator.js.map +0 -1
  214. package/dist/cjs/data-structures/priority-queue/index.js +0 -20
  215. package/dist/cjs/data-structures/priority-queue/index.js.map +0 -1
  216. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  217. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -102
  218. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  219. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  220. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -94
  221. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  222. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +0 -74
  223. package/dist/cjs/data-structures/priority-queue/priority-queue.js +0 -96
  224. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +0 -1
  225. package/dist/cjs/data-structures/queue/deque.d.ts +0 -458
  226. package/dist/cjs/data-structures/queue/deque.js +0 -919
  227. package/dist/cjs/data-structures/queue/deque.js.map +0 -1
  228. package/dist/cjs/data-structures/queue/index.js +0 -19
  229. package/dist/cjs/data-structures/queue/index.js.map +0 -1
  230. package/dist/cjs/data-structures/queue/queue.d.ts +0 -329
  231. package/dist/cjs/data-structures/queue/queue.js +0 -457
  232. package/dist/cjs/data-structures/queue/queue.js.map +0 -1
  233. package/dist/cjs/data-structures/stack/index.js +0 -18
  234. package/dist/cjs/data-structures/stack/index.js.map +0 -1
  235. package/dist/cjs/data-structures/stack/stack.js +0 -346
  236. package/dist/cjs/data-structures/stack/stack.js.map +0 -1
  237. package/dist/cjs/data-structures/tree/index.js +0 -18
  238. package/dist/cjs/data-structures/tree/index.js.map +0 -1
  239. package/dist/cjs/data-structures/tree/tree.js +0 -108
  240. package/dist/cjs/data-structures/tree/tree.js.map +0 -1
  241. package/dist/cjs/data-structures/trie/index.js +0 -18
  242. package/dist/cjs/data-structures/trie/index.js.map +0 -1
  243. package/dist/cjs/data-structures/trie/trie.d.ts +0 -351
  244. package/dist/cjs/data-structures/trie/trie.js +0 -594
  245. package/dist/cjs/data-structures/trie/trie.js.map +0 -1
  246. package/dist/cjs/index.js +0 -22
  247. package/dist/cjs/index.js.map +0 -1
  248. package/dist/cjs/interfaces/binary-tree.d.ts +0 -9
  249. package/dist/cjs/interfaces/binary-tree.js +0 -3
  250. package/dist/cjs/interfaces/binary-tree.js.map +0 -1
  251. package/dist/cjs/interfaces/doubly-linked-list.js +0 -3
  252. package/dist/cjs/interfaces/doubly-linked-list.js.map +0 -1
  253. package/dist/cjs/interfaces/graph.d.ts +0 -5
  254. package/dist/cjs/interfaces/graph.js +0 -3
  255. package/dist/cjs/interfaces/graph.js.map +0 -1
  256. package/dist/cjs/interfaces/heap.js +0 -3
  257. package/dist/cjs/interfaces/heap.js.map +0 -1
  258. package/dist/cjs/interfaces/index.js +0 -25
  259. package/dist/cjs/interfaces/index.js.map +0 -1
  260. package/dist/cjs/interfaces/navigator.js +0 -3
  261. package/dist/cjs/interfaces/navigator.js.map +0 -1
  262. package/dist/cjs/interfaces/priority-queue.js +0 -3
  263. package/dist/cjs/interfaces/priority-queue.js.map +0 -1
  264. package/dist/cjs/interfaces/segment-tree.js +0 -3
  265. package/dist/cjs/interfaces/segment-tree.js.map +0 -1
  266. package/dist/cjs/interfaces/singly-linked-list.js +0 -3
  267. package/dist/cjs/interfaces/singly-linked-list.js.map +0 -1
  268. package/dist/cjs/types/common.js +0 -3
  269. package/dist/cjs/types/common.js.map +0 -1
  270. package/dist/cjs/types/data-structures/base/base.js +0 -3
  271. package/dist/cjs/types/data-structures/base/base.js.map +0 -1
  272. package/dist/cjs/types/data-structures/base/index.js +0 -18
  273. package/dist/cjs/types/data-structures/base/index.js.map +0 -1
  274. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +0 -3
  275. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  276. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -3
  277. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  278. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js +0 -3
  279. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  280. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +0 -3
  281. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  282. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -3
  283. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  284. package/dist/cjs/types/data-structures/binary-tree/bst.js +0 -3
  285. package/dist/cjs/types/data-structures/binary-tree/bst.js.map +0 -1
  286. package/dist/cjs/types/data-structures/binary-tree/index.js +0 -26
  287. package/dist/cjs/types/data-structures/binary-tree/index.js.map +0 -1
  288. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +0 -3
  289. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  290. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js +0 -3
  291. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  292. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +0 -3
  293. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  294. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js +0 -3
  295. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  296. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +0 -10
  297. package/dist/cjs/types/data-structures/graph/abstract-graph.js +0 -3
  298. package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +0 -1
  299. package/dist/cjs/types/data-structures/graph/directed-graph.js +0 -3
  300. package/dist/cjs/types/data-structures/graph/directed-graph.js.map +0 -1
  301. package/dist/cjs/types/data-structures/graph/index.js +0 -20
  302. package/dist/cjs/types/data-structures/graph/index.js.map +0 -1
  303. package/dist/cjs/types/data-structures/graph/map-graph.js +0 -3
  304. package/dist/cjs/types/data-structures/graph/map-graph.js.map +0 -1
  305. package/dist/cjs/types/data-structures/graph/undirected-graph.js +0 -3
  306. package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +0 -1
  307. package/dist/cjs/types/data-structures/hash/hash-map.js +0 -3
  308. package/dist/cjs/types/data-structures/hash/hash-map.js.map +0 -1
  309. package/dist/cjs/types/data-structures/hash/index.js +0 -18
  310. package/dist/cjs/types/data-structures/hash/index.js.map +0 -1
  311. package/dist/cjs/types/data-structures/heap/heap.js +0 -3
  312. package/dist/cjs/types/data-structures/heap/heap.js.map +0 -1
  313. package/dist/cjs/types/data-structures/heap/index.js +0 -18
  314. package/dist/cjs/types/data-structures/heap/index.js.map +0 -1
  315. package/dist/cjs/types/data-structures/heap/max-heap.js +0 -3
  316. package/dist/cjs/types/data-structures/heap/max-heap.js.map +0 -1
  317. package/dist/cjs/types/data-structures/heap/min-heap.js +0 -3
  318. package/dist/cjs/types/data-structures/heap/min-heap.js.map +0 -1
  319. package/dist/cjs/types/data-structures/index.js +0 -29
  320. package/dist/cjs/types/data-structures/index.js.map +0 -1
  321. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js +0 -3
  322. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  323. package/dist/cjs/types/data-structures/linked-list/index.js +0 -20
  324. package/dist/cjs/types/data-structures/linked-list/index.js.map +0 -1
  325. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js +0 -3
  326. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  327. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +0 -3
  328. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  329. package/dist/cjs/types/data-structures/matrix/index.js +0 -19
  330. package/dist/cjs/types/data-structures/matrix/index.js.map +0 -1
  331. package/dist/cjs/types/data-structures/matrix/matrix.js +0 -3
  332. package/dist/cjs/types/data-structures/matrix/matrix.js.map +0 -1
  333. package/dist/cjs/types/data-structures/matrix/navigator.js +0 -3
  334. package/dist/cjs/types/data-structures/matrix/navigator.js.map +0 -1
  335. package/dist/cjs/types/data-structures/priority-queue/index.js +0 -20
  336. package/dist/cjs/types/data-structures/priority-queue/index.js.map +0 -1
  337. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +0 -3
  338. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  339. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +0 -3
  340. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  341. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js +0 -3
  342. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  343. package/dist/cjs/types/data-structures/queue/deque.js +0 -3
  344. package/dist/cjs/types/data-structures/queue/deque.js.map +0 -1
  345. package/dist/cjs/types/data-structures/queue/index.js +0 -19
  346. package/dist/cjs/types/data-structures/queue/index.js.map +0 -1
  347. package/dist/cjs/types/data-structures/queue/queue.js +0 -3
  348. package/dist/cjs/types/data-structures/queue/queue.js.map +0 -1
  349. package/dist/cjs/types/data-structures/stack/index.js +0 -18
  350. package/dist/cjs/types/data-structures/stack/index.js.map +0 -1
  351. package/dist/cjs/types/data-structures/stack/stack.js +0 -3
  352. package/dist/cjs/types/data-structures/stack/stack.js.map +0 -1
  353. package/dist/cjs/types/data-structures/tree/index.js +0 -18
  354. package/dist/cjs/types/data-structures/tree/index.js.map +0 -1
  355. package/dist/cjs/types/data-structures/tree/tree.js +0 -3
  356. package/dist/cjs/types/data-structures/tree/tree.js.map +0 -1
  357. package/dist/cjs/types/data-structures/trie/index.js +0 -18
  358. package/dist/cjs/types/data-structures/trie/index.js.map +0 -1
  359. package/dist/cjs/types/data-structures/trie/trie.js +0 -3
  360. package/dist/cjs/types/data-structures/trie/trie.js.map +0 -1
  361. package/dist/cjs/types/index.js +0 -20
  362. package/dist/cjs/types/index.js.map +0 -1
  363. package/dist/cjs/types/utils/index.js +0 -19
  364. package/dist/cjs/types/utils/index.js.map +0 -1
  365. package/dist/cjs/types/utils/utils.js +0 -3
  366. package/dist/cjs/types/utils/utils.js.map +0 -1
  367. package/dist/cjs/types/utils/validate-type.js +0 -3
  368. package/dist/cjs/types/utils/validate-type.js.map +0 -1
  369. package/dist/cjs/utils/index.js +0 -19
  370. package/dist/cjs/utils/index.js.map +0 -1
  371. package/dist/cjs/utils/number.js +0 -24
  372. package/dist/cjs/utils/number.js.map +0 -1
  373. package/dist/cjs/utils/utils.d.ts +0 -209
  374. package/dist/cjs/utils/utils.js +0 -353
  375. package/dist/cjs/utils/utils.js.map +0 -1
  376. package/dist/esm/common/index.d.ts +0 -12
  377. package/dist/esm/common/index.js +0 -29
  378. package/dist/esm/common/index.js.map +0 -1
  379. package/dist/esm/data-structures/base/index.d.ts +0 -2
  380. package/dist/esm/data-structures/base/index.js +0 -3
  381. package/dist/esm/data-structures/base/index.js.map +0 -1
  382. package/dist/esm/data-structures/base/iterable-element-base.d.ts +0 -116
  383. package/dist/esm/data-structures/base/iterable-element-base.js +0 -199
  384. package/dist/esm/data-structures/base/iterable-element-base.js.map +0 -1
  385. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +0 -168
  386. package/dist/esm/data-structures/base/iterable-entry-base.js +0 -237
  387. package/dist/esm/data-structures/base/iterable-entry-base.js.map +0 -1
  388. package/dist/esm/data-structures/base/linear-base.d.ts +0 -277
  389. package/dist/esm/data-structures/base/linear-base.js +0 -549
  390. package/dist/esm/data-structures/base/linear-base.js.map +0 -1
  391. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  392. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +0 -410
  393. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  394. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  395. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +0 -205
  396. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  397. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +0 -302
  398. package/dist/esm/data-structures/binary-tree/avl-tree.js +0 -601
  399. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +0 -1
  400. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  401. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js +0 -296
  402. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  403. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +0 -910
  404. package/dist/esm/data-structures/binary-tree/binary-tree.js +0 -2198
  405. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +0 -1
  406. package/dist/esm/data-structures/binary-tree/bst.d.ts +0 -461
  407. package/dist/esm/data-structures/binary-tree/bst.js +0 -881
  408. package/dist/esm/data-structures/binary-tree/bst.js.map +0 -1
  409. package/dist/esm/data-structures/binary-tree/index.d.ts +0 -10
  410. package/dist/esm/data-structures/binary-tree/index.js +0 -11
  411. package/dist/esm/data-structures/binary-tree/index.js.map +0 -1
  412. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  413. package/dist/esm/data-structures/binary-tree/red-black-tree.js +0 -641
  414. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +0 -1
  415. package/dist/esm/data-structures/binary-tree/segment-tree.d.ts +0 -160
  416. package/dist/esm/data-structures/binary-tree/segment-tree.js +0 -295
  417. package/dist/esm/data-structures/binary-tree/segment-tree.js.map +0 -1
  418. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +0 -212
  419. package/dist/esm/data-structures/binary-tree/tree-counter.js +0 -446
  420. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +0 -1
  421. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +0 -367
  422. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  423. package/dist/esm/data-structures/graph/abstract-graph.d.ts +0 -335
  424. package/dist/esm/data-structures/graph/abstract-graph.js +0 -862
  425. package/dist/esm/data-structures/graph/abstract-graph.js.map +0 -1
  426. package/dist/esm/data-structures/graph/directed-graph.d.ts +0 -323
  427. package/dist/esm/data-structures/graph/directed-graph.js +0 -609
  428. package/dist/esm/data-structures/graph/directed-graph.js.map +0 -1
  429. package/dist/esm/data-structures/graph/index.d.ts +0 -4
  430. package/dist/esm/data-structures/graph/index.js +0 -5
  431. package/dist/esm/data-structures/graph/index.js.map +0 -1
  432. package/dist/esm/data-structures/graph/map-graph.d.ts +0 -84
  433. package/dist/esm/data-structures/graph/map-graph.js +0 -108
  434. package/dist/esm/data-structures/graph/map-graph.js.map +0 -1
  435. package/dist/esm/data-structures/graph/undirected-graph.d.ts +0 -231
  436. package/dist/esm/data-structures/graph/undirected-graph.js +0 -439
  437. package/dist/esm/data-structures/graph/undirected-graph.js.map +0 -1
  438. package/dist/esm/data-structures/hash/hash-map.d.ts +0 -519
  439. package/dist/esm/data-structures/hash/hash-map.js +0 -878
  440. package/dist/esm/data-structures/hash/hash-map.js.map +0 -1
  441. package/dist/esm/data-structures/hash/index.d.ts +0 -1
  442. package/dist/esm/data-structures/hash/index.js +0 -2
  443. package/dist/esm/data-structures/hash/index.js.map +0 -1
  444. package/dist/esm/data-structures/heap/heap.d.ts +0 -578
  445. package/dist/esm/data-structures/heap/heap.js +0 -914
  446. package/dist/esm/data-structures/heap/heap.js.map +0 -1
  447. package/dist/esm/data-structures/heap/index.d.ts +0 -3
  448. package/dist/esm/data-structures/heap/index.js +0 -4
  449. package/dist/esm/data-structures/heap/index.js.map +0 -1
  450. package/dist/esm/data-structures/heap/max-heap.d.ts +0 -68
  451. package/dist/esm/data-structures/heap/max-heap.js +0 -95
  452. package/dist/esm/data-structures/heap/max-heap.js.map +0 -1
  453. package/dist/esm/data-structures/heap/min-heap.d.ts +0 -68
  454. package/dist/esm/data-structures/heap/min-heap.js +0 -83
  455. package/dist/esm/data-structures/heap/min-heap.js.map +0 -1
  456. package/dist/esm/data-structures/index.d.ts +0 -12
  457. package/dist/esm/data-structures/index.js +0 -13
  458. package/dist/esm/data-structures/index.js.map +0 -1
  459. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  460. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +0 -1236
  461. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  462. package/dist/esm/data-structures/linked-list/index.d.ts +0 -3
  463. package/dist/esm/data-structures/linked-list/index.js +0 -4
  464. package/dist/esm/data-structures/linked-list/index.js.map +0 -1
  465. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  466. package/dist/esm/data-structures/linked-list/singly-linked-list.js +0 -866
  467. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +0 -1
  468. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  469. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -243
  470. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +0 -1
  471. package/dist/esm/data-structures/matrix/index.d.ts +0 -2
  472. package/dist/esm/data-structures/matrix/index.js +0 -3
  473. package/dist/esm/data-structures/matrix/index.js.map +0 -1
  474. package/dist/esm/data-structures/matrix/matrix.d.ts +0 -168
  475. package/dist/esm/data-structures/matrix/matrix.js +0 -444
  476. package/dist/esm/data-structures/matrix/matrix.js.map +0 -1
  477. package/dist/esm/data-structures/matrix/navigator.d.ts +0 -55
  478. package/dist/esm/data-structures/matrix/navigator.js +0 -114
  479. package/dist/esm/data-structures/matrix/navigator.js.map +0 -1
  480. package/dist/esm/data-structures/priority-queue/index.d.ts +0 -3
  481. package/dist/esm/data-structures/priority-queue/index.js +0 -4
  482. package/dist/esm/data-structures/priority-queue/index.js.map +0 -1
  483. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  484. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +0 -101
  485. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  486. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  487. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +0 -90
  488. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  489. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +0 -74
  490. package/dist/esm/data-structures/priority-queue/priority-queue.js +0 -92
  491. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +0 -1
  492. package/dist/esm/data-structures/queue/deque.d.ts +0 -458
  493. package/dist/esm/data-structures/queue/deque.js +0 -915
  494. package/dist/esm/data-structures/queue/deque.js.map +0 -1
  495. package/dist/esm/data-structures/queue/index.d.ts +0 -2
  496. package/dist/esm/data-structures/queue/index.js +0 -3
  497. package/dist/esm/data-structures/queue/index.js.map +0 -1
  498. package/dist/esm/data-structures/queue/queue.d.ts +0 -329
  499. package/dist/esm/data-structures/queue/queue.js +0 -452
  500. package/dist/esm/data-structures/queue/queue.js.map +0 -1
  501. package/dist/esm/data-structures/stack/index.d.ts +0 -1
  502. package/dist/esm/data-structures/stack/index.js +0 -2
  503. package/dist/esm/data-structures/stack/index.js.map +0 -1
  504. package/dist/esm/data-structures/stack/stack.d.ts +0 -284
  505. package/dist/esm/data-structures/stack/stack.js +0 -342
  506. package/dist/esm/data-structures/stack/stack.js.map +0 -1
  507. package/dist/esm/data-structures/tree/index.d.ts +0 -1
  508. package/dist/esm/data-structures/tree/index.js +0 -2
  509. package/dist/esm/data-structures/tree/index.js.map +0 -1
  510. package/dist/esm/data-structures/tree/tree.d.ts +0 -62
  511. package/dist/esm/data-structures/tree/tree.js +0 -107
  512. package/dist/esm/data-structures/tree/tree.js.map +0 -1
  513. package/dist/esm/data-structures/trie/index.d.ts +0 -1
  514. package/dist/esm/data-structures/trie/index.js +0 -2
  515. package/dist/esm/data-structures/trie/index.js.map +0 -1
  516. package/dist/esm/data-structures/trie/trie.d.ts +0 -351
  517. package/dist/esm/data-structures/trie/trie.js +0 -592
  518. package/dist/esm/data-structures/trie/trie.js.map +0 -1
  519. package/dist/esm/index.d.ts +0 -5
  520. package/dist/esm/index.js +0 -6
  521. package/dist/esm/index.js.map +0 -1
  522. package/dist/esm/interfaces/binary-tree.d.ts +0 -9
  523. package/dist/esm/interfaces/binary-tree.js +0 -2
  524. package/dist/esm/interfaces/binary-tree.js.map +0 -1
  525. package/dist/esm/interfaces/doubly-linked-list.d.ts +0 -1
  526. package/dist/esm/interfaces/doubly-linked-list.js +0 -2
  527. package/dist/esm/interfaces/doubly-linked-list.js.map +0 -1
  528. package/dist/esm/interfaces/graph.d.ts +0 -5
  529. package/dist/esm/interfaces/graph.js +0 -2
  530. package/dist/esm/interfaces/graph.js.map +0 -1
  531. package/dist/esm/interfaces/heap.d.ts +0 -1
  532. package/dist/esm/interfaces/heap.js +0 -2
  533. package/dist/esm/interfaces/heap.js.map +0 -1
  534. package/dist/esm/interfaces/index.d.ts +0 -8
  535. package/dist/esm/interfaces/index.js +0 -9
  536. package/dist/esm/interfaces/index.js.map +0 -1
  537. package/dist/esm/interfaces/navigator.d.ts +0 -1
  538. package/dist/esm/interfaces/navigator.js +0 -2
  539. package/dist/esm/interfaces/navigator.js.map +0 -1
  540. package/dist/esm/interfaces/priority-queue.d.ts +0 -1
  541. package/dist/esm/interfaces/priority-queue.js +0 -2
  542. package/dist/esm/interfaces/priority-queue.js.map +0 -1
  543. package/dist/esm/interfaces/segment-tree.d.ts +0 -1
  544. package/dist/esm/interfaces/segment-tree.js +0 -2
  545. package/dist/esm/interfaces/segment-tree.js.map +0 -1
  546. package/dist/esm/interfaces/singly-linked-list.d.ts +0 -1
  547. package/dist/esm/interfaces/singly-linked-list.js +0 -2
  548. package/dist/esm/interfaces/singly-linked-list.js.map +0 -1
  549. package/dist/esm/types/common.d.ts +0 -15
  550. package/dist/esm/types/common.js +0 -2
  551. package/dist/esm/types/common.js.map +0 -1
  552. package/dist/esm/types/data-structures/base/base.d.ts +0 -13
  553. package/dist/esm/types/data-structures/base/base.js +0 -2
  554. package/dist/esm/types/data-structures/base/base.js.map +0 -1
  555. package/dist/esm/types/data-structures/base/index.d.ts +0 -1
  556. package/dist/esm/types/data-structures/base/index.js +0 -2
  557. package/dist/esm/types/data-structures/base/index.js.map +0 -1
  558. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
  559. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  560. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  561. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
  562. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  563. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  564. package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
  565. package/dist/esm/types/data-structures/binary-tree/avl-tree.js +0 -2
  566. package/dist/esm/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  567. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -1
  568. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  569. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  570. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +0 -29
  571. package/dist/esm/types/data-structures/binary-tree/binary-tree.js +0 -2
  572. package/dist/esm/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  573. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +0 -12
  574. package/dist/esm/types/data-structures/binary-tree/bst.js +0 -2
  575. package/dist/esm/types/data-structures/binary-tree/bst.js.map +0 -1
  576. package/dist/esm/types/data-structures/binary-tree/index.d.ts +0 -9
  577. package/dist/esm/types/data-structures/binary-tree/index.js +0 -10
  578. package/dist/esm/types/data-structures/binary-tree/index.js.map +0 -1
  579. package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +0 -3
  580. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +0 -2
  581. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  582. package/dist/esm/types/data-structures/binary-tree/segment-tree.d.ts +0 -1
  583. package/dist/esm/types/data-structures/binary-tree/segment-tree.js +0 -2
  584. package/dist/esm/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  585. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
  586. package/dist/esm/types/data-structures/binary-tree/tree-counter.js +0 -2
  587. package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  588. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -2
  589. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  590. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  591. package/dist/esm/types/data-structures/graph/abstract-graph.js +0 -2
  592. package/dist/esm/types/data-structures/graph/abstract-graph.js.map +0 -1
  593. package/dist/esm/types/data-structures/graph/directed-graph.d.ts +0 -1
  594. package/dist/esm/types/data-structures/graph/directed-graph.js +0 -2
  595. package/dist/esm/types/data-structures/graph/directed-graph.js.map +0 -1
  596. package/dist/esm/types/data-structures/graph/index.d.ts +0 -3
  597. package/dist/esm/types/data-structures/graph/index.js +0 -4
  598. package/dist/esm/types/data-structures/graph/index.js.map +0 -1
  599. package/dist/esm/types/data-structures/graph/map-graph.d.ts +0 -1
  600. package/dist/esm/types/data-structures/graph/map-graph.js +0 -2
  601. package/dist/esm/types/data-structures/graph/map-graph.js.map +0 -1
  602. package/dist/esm/types/data-structures/graph/undirected-graph.d.ts +0 -1
  603. package/dist/esm/types/data-structures/graph/undirected-graph.js +0 -2
  604. package/dist/esm/types/data-structures/graph/undirected-graph.js.map +0 -1
  605. package/dist/esm/types/data-structures/hash/hash-map.d.ts +0 -19
  606. package/dist/esm/types/data-structures/hash/hash-map.js +0 -2
  607. package/dist/esm/types/data-structures/hash/hash-map.js.map +0 -1
  608. package/dist/esm/types/data-structures/hash/index.d.ts +0 -2
  609. package/dist/esm/types/data-structures/hash/index.js +0 -2
  610. package/dist/esm/types/data-structures/hash/index.js.map +0 -1
  611. package/dist/esm/types/data-structures/heap/heap.d.ts +0 -5
  612. package/dist/esm/types/data-structures/heap/heap.js +0 -2
  613. package/dist/esm/types/data-structures/heap/heap.js.map +0 -1
  614. package/dist/esm/types/data-structures/heap/index.d.ts +0 -1
  615. package/dist/esm/types/data-structures/heap/index.js +0 -2
  616. package/dist/esm/types/data-structures/heap/index.js.map +0 -1
  617. package/dist/esm/types/data-structures/heap/max-heap.d.ts +0 -1
  618. package/dist/esm/types/data-structures/heap/max-heap.js +0 -2
  619. package/dist/esm/types/data-structures/heap/max-heap.js.map +0 -1
  620. package/dist/esm/types/data-structures/heap/min-heap.d.ts +0 -1
  621. package/dist/esm/types/data-structures/heap/min-heap.js +0 -2
  622. package/dist/esm/types/data-structures/heap/min-heap.js.map +0 -1
  623. package/dist/esm/types/data-structures/index.d.ts +0 -12
  624. package/dist/esm/types/data-structures/index.js +0 -13
  625. package/dist/esm/types/data-structures/index.js.map +0 -1
  626. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
  627. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  628. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  629. package/dist/esm/types/data-structures/linked-list/index.d.ts +0 -3
  630. package/dist/esm/types/data-structures/linked-list/index.js +0 -4
  631. package/dist/esm/types/data-structures/linked-list/index.js.map +0 -1
  632. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +0 -2
  633. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js +0 -2
  634. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  635. package/dist/esm/types/data-structures/linked-list/skip-linked-list.d.ts +0 -4
  636. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js +0 -2
  637. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  638. package/dist/esm/types/data-structures/matrix/index.d.ts +0 -2
  639. package/dist/esm/types/data-structures/matrix/index.js +0 -3
  640. package/dist/esm/types/data-structures/matrix/index.js.map +0 -1
  641. package/dist/esm/types/data-structures/matrix/matrix.d.ts +0 -7
  642. package/dist/esm/types/data-structures/matrix/matrix.js +0 -2
  643. package/dist/esm/types/data-structures/matrix/matrix.js.map +0 -1
  644. package/dist/esm/types/data-structures/matrix/navigator.d.ts +0 -14
  645. package/dist/esm/types/data-structures/matrix/navigator.js +0 -2
  646. package/dist/esm/types/data-structures/matrix/navigator.js.map +0 -1
  647. package/dist/esm/types/data-structures/priority-queue/index.d.ts +0 -3
  648. package/dist/esm/types/data-structures/priority-queue/index.js +0 -4
  649. package/dist/esm/types/data-structures/priority-queue/index.js.map +0 -1
  650. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -1
  651. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  652. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  653. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -1
  654. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  655. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  656. package/dist/esm/types/data-structures/priority-queue/priority-queue.d.ts +0 -2
  657. package/dist/esm/types/data-structures/priority-queue/priority-queue.js +0 -2
  658. package/dist/esm/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  659. package/dist/esm/types/data-structures/queue/deque.d.ts +0 -4
  660. package/dist/esm/types/data-structures/queue/deque.js +0 -2
  661. package/dist/esm/types/data-structures/queue/deque.js.map +0 -1
  662. package/dist/esm/types/data-structures/queue/index.d.ts +0 -2
  663. package/dist/esm/types/data-structures/queue/index.js +0 -3
  664. package/dist/esm/types/data-structures/queue/index.js.map +0 -1
  665. package/dist/esm/types/data-structures/queue/queue.d.ts +0 -4
  666. package/dist/esm/types/data-structures/queue/queue.js +0 -2
  667. package/dist/esm/types/data-structures/queue/queue.js.map +0 -1
  668. package/dist/esm/types/data-structures/stack/index.d.ts +0 -1
  669. package/dist/esm/types/data-structures/stack/index.js +0 -2
  670. package/dist/esm/types/data-structures/stack/index.js.map +0 -1
  671. package/dist/esm/types/data-structures/stack/stack.d.ts +0 -2
  672. package/dist/esm/types/data-structures/stack/stack.js +0 -2
  673. package/dist/esm/types/data-structures/stack/stack.js.map +0 -1
  674. package/dist/esm/types/data-structures/tree/index.d.ts +0 -1
  675. package/dist/esm/types/data-structures/tree/index.js +0 -2
  676. package/dist/esm/types/data-structures/tree/index.js.map +0 -1
  677. package/dist/esm/types/data-structures/tree/tree.d.ts +0 -1
  678. package/dist/esm/types/data-structures/tree/tree.js +0 -2
  679. package/dist/esm/types/data-structures/tree/tree.js.map +0 -1
  680. package/dist/esm/types/data-structures/trie/index.d.ts +0 -1
  681. package/dist/esm/types/data-structures/trie/index.js +0 -2
  682. package/dist/esm/types/data-structures/trie/index.js.map +0 -1
  683. package/dist/esm/types/data-structures/trie/trie.d.ts +0 -4
  684. package/dist/esm/types/data-structures/trie/trie.js +0 -2
  685. package/dist/esm/types/data-structures/trie/trie.js.map +0 -1
  686. package/dist/esm/types/index.d.ts +0 -3
  687. package/dist/esm/types/index.js +0 -4
  688. package/dist/esm/types/index.js.map +0 -1
  689. package/dist/esm/types/utils/index.d.ts +0 -2
  690. package/dist/esm/types/utils/index.js +0 -3
  691. package/dist/esm/types/utils/index.js.map +0 -1
  692. package/dist/esm/types/utils/utils.d.ts +0 -21
  693. package/dist/esm/types/utils/utils.js +0 -2
  694. package/dist/esm/types/utils/utils.js.map +0 -1
  695. package/dist/esm/types/utils/validate-type.d.ts +0 -19
  696. package/dist/esm/types/utils/validate-type.js +0 -2
  697. package/dist/esm/types/utils/validate-type.js.map +0 -1
  698. package/dist/esm/utils/index.d.ts +0 -2
  699. package/dist/esm/utils/index.js +0 -3
  700. package/dist/esm/utils/index.js.map +0 -1
  701. package/dist/esm/utils/number.d.ts +0 -14
  702. package/dist/esm/utils/number.js +0 -21
  703. package/dist/esm/utils/number.js.map +0 -1
  704. package/dist/esm/utils/utils.js +0 -324
  705. package/dist/esm/utils/utils.js.map +0 -1
  706. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  707. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
  708. package/tsconfig-cjs.json +0 -14
  709. package/tsconfig-esm.json +0 -14
  710. /package/dist/{cjs → types}/common/index.d.ts +0 -0
  711. /package/dist/{cjs → types}/data-structures/base/index.d.ts +0 -0
  712. /package/dist/{cjs → types}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  713. /package/dist/{cjs → types}/data-structures/binary-tree/index.d.ts +0 -0
  714. /package/dist/{cjs → types}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  715. /package/dist/{cjs → types}/data-structures/graph/index.d.ts +0 -0
  716. /package/dist/{cjs → types}/data-structures/hash/index.d.ts +0 -0
  717. /package/dist/{cjs → types}/data-structures/heap/index.d.ts +0 -0
  718. /package/dist/{cjs → types}/data-structures/index.d.ts +0 -0
  719. /package/dist/{cjs → types}/data-structures/linked-list/index.d.ts +0 -0
  720. /package/dist/{cjs → types}/data-structures/matrix/index.d.ts +0 -0
  721. /package/dist/{cjs → types}/data-structures/matrix/matrix.d.ts +0 -0
  722. /package/dist/{cjs → types}/data-structures/matrix/navigator.d.ts +0 -0
  723. /package/dist/{cjs → types}/data-structures/priority-queue/index.d.ts +0 -0
  724. /package/dist/{cjs → types}/data-structures/queue/index.d.ts +0 -0
  725. /package/dist/{cjs → types}/data-structures/stack/index.d.ts +0 -0
  726. /package/dist/{cjs → types}/data-structures/tree/index.d.ts +0 -0
  727. /package/dist/{cjs → types}/data-structures/tree/tree.d.ts +0 -0
  728. /package/dist/{cjs → types}/data-structures/trie/index.d.ts +0 -0
  729. /package/dist/{cjs → types}/index.d.ts +0 -0
  730. /package/dist/{cjs → types}/interfaces/doubly-linked-list.d.ts +0 -0
  731. /package/dist/{cjs → types}/interfaces/heap.d.ts +0 -0
  732. /package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
  733. /package/dist/{cjs → types}/interfaces/navigator.d.ts +0 -0
  734. /package/dist/{cjs → types}/interfaces/priority-queue.d.ts +0 -0
  735. /package/dist/{cjs → types}/interfaces/segment-tree.d.ts +0 -0
  736. /package/dist/{cjs → types}/interfaces/singly-linked-list.d.ts +0 -0
  737. /package/dist/{cjs → types}/types/common.d.ts +0 -0
  738. /package/dist/{cjs → types}/types/data-structures/base/index.d.ts +0 -0
  739. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -0
  740. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -0
  741. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree.d.ts +0 -0
  742. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  743. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-tree.d.ts +0 -0
  744. /package/dist/{cjs → types}/types/data-structures/binary-tree/bst.d.ts +0 -0
  745. /package/dist/{cjs → types}/types/data-structures/binary-tree/index.d.ts +0 -0
  746. /package/dist/{cjs → types}/types/data-structures/binary-tree/red-black-tree.d.ts +0 -0
  747. /package/dist/{cjs → types}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
  748. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-counter.d.ts +0 -0
  749. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -0
  750. /package/dist/{cjs → types}/types/data-structures/graph/directed-graph.d.ts +0 -0
  751. /package/dist/{cjs → types}/types/data-structures/graph/index.d.ts +0 -0
  752. /package/dist/{cjs → types}/types/data-structures/graph/map-graph.d.ts +0 -0
  753. /package/dist/{cjs → types}/types/data-structures/graph/undirected-graph.d.ts +0 -0
  754. /package/dist/{cjs → types}/types/data-structures/hash/hash-map.d.ts +0 -0
  755. /package/dist/{cjs → types}/types/data-structures/hash/index.d.ts +0 -0
  756. /package/dist/{cjs → types}/types/data-structures/heap/heap.d.ts +0 -0
  757. /package/dist/{cjs → types}/types/data-structures/heap/index.d.ts +0 -0
  758. /package/dist/{cjs → types}/types/data-structures/heap/max-heap.d.ts +0 -0
  759. /package/dist/{cjs → types}/types/data-structures/heap/min-heap.d.ts +0 -0
  760. /package/dist/{cjs → types}/types/data-structures/index.d.ts +0 -0
  761. /package/dist/{cjs → types}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  762. /package/dist/{cjs → types}/types/data-structures/linked-list/index.d.ts +0 -0
  763. /package/dist/{cjs → types}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
  764. /package/dist/{cjs → types}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  765. /package/dist/{cjs → types}/types/data-structures/matrix/index.d.ts +0 -0
  766. /package/dist/{cjs → types}/types/data-structures/matrix/matrix.d.ts +0 -0
  767. /package/dist/{cjs → types}/types/data-structures/matrix/navigator.d.ts +0 -0
  768. /package/dist/{cjs → types}/types/data-structures/priority-queue/index.d.ts +0 -0
  769. /package/dist/{cjs → types}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  770. /package/dist/{cjs → types}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  771. /package/dist/{cjs → types}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
  772. /package/dist/{cjs → types}/types/data-structures/queue/deque.d.ts +0 -0
  773. /package/dist/{cjs → types}/types/data-structures/queue/index.d.ts +0 -0
  774. /package/dist/{cjs → types}/types/data-structures/queue/queue.d.ts +0 -0
  775. /package/dist/{cjs → types}/types/data-structures/stack/index.d.ts +0 -0
  776. /package/dist/{cjs → types}/types/data-structures/stack/stack.d.ts +0 -0
  777. /package/dist/{cjs → types}/types/data-structures/tree/index.d.ts +0 -0
  778. /package/dist/{cjs → types}/types/data-structures/tree/tree.d.ts +0 -0
  779. /package/dist/{cjs → types}/types/data-structures/trie/index.d.ts +0 -0
  780. /package/dist/{cjs → types}/types/data-structures/trie/trie.d.ts +0 -0
  781. /package/dist/{cjs → types}/types/index.d.ts +0 -0
  782. /package/dist/{cjs → types}/types/utils/index.d.ts +0 -0
  783. /package/dist/{cjs → types}/types/utils/validate-type.d.ts +0 -0
  784. /package/dist/{cjs → types}/utils/index.d.ts +0 -0
  785. /package/dist/{cjs → types}/utils/number.d.ts +0 -0
@@ -1,1238 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
4
- const linear_base_1 = require("../base/linear-base");
5
- class DoublyLinkedListNode extends linear_base_1.LinkedListNode {
6
- /**
7
- * The constructor function initializes the value, next, and previous properties of an object.
8
- * @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
9
- * is defined as a generic type "E".
10
- */
11
- constructor(value) {
12
- super(value);
13
- this._value = value;
14
- this._next = undefined;
15
- this._prev = undefined;
16
- }
17
- get next() {
18
- return this._next;
19
- }
20
- set next(value) {
21
- this._next = value;
22
- }
23
- get prev() {
24
- return this._prev;
25
- }
26
- set prev(value) {
27
- this._prev = value;
28
- }
29
- }
30
- exports.DoublyLinkedListNode = DoublyLinkedListNode;
31
- /**
32
- * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
33
- * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
34
- * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
35
- * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
36
- * Caution: Although our linked list classes provide methods such as at, setAt, addAt, and indexOf that are based on array indices, their time complexity, like that of the native Array.lastIndexOf, is 𝑂(𝑛). If you need to use these methods frequently, you might want to consider other data structures, such as Deque or Queue (designed for random access). Similarly, since the native Array.shift method has a time complexity of 𝑂(𝑛), using an array to simulate a queue can be inefficient. In such cases, you should use Queue or Deque, as these data structures leverage deferred array rearrangement, effectively reducing the average time complexity to 𝑂(1).
37
- * @example
38
- * // text editor operation history
39
- * const actions = [
40
- * { type: 'insert', content: 'first line of text' },
41
- * { type: 'insert', content: 'second line of text' },
42
- * { type: 'delete', content: 'delete the first line' }
43
- * ];
44
- * const editorHistory = new DoublyLinkedList<{ type: string; content: string }>(actions);
45
- *
46
- * console.log(editorHistory.last?.type); // 'delete'
47
- * console.log(editorHistory.pop()?.content); // 'delete the first line'
48
- * console.log(editorHistory.last?.type); // 'insert'
49
- * @example
50
- * // Browser history
51
- * const browserHistory = new DoublyLinkedList<string>();
52
- *
53
- * browserHistory.push('home page');
54
- * browserHistory.push('search page');
55
- * browserHistory.push('details page');
56
- *
57
- * console.log(browserHistory.last); // 'details page'
58
- * console.log(browserHistory.pop()); // 'details page'
59
- * console.log(browserHistory.last); // 'search page'
60
- * @example
61
- * // Use DoublyLinkedList to implement music player
62
- * // Define the Song interface
63
- * interface Song {
64
- * title: string;
65
- * artist: string;
66
- * duration: number; // duration in seconds
67
- * }
68
- *
69
- * class Player {
70
- * private playlist: DoublyLinkedList<Song>;
71
- * private currentSong: ReturnType<typeof this.playlist.getNodeAt> | undefined;
72
- *
73
- * constructor(songs: Song[]) {
74
- * this.playlist = new DoublyLinkedList<Song>();
75
- * songs.forEach(song => this.playlist.push(song));
76
- * this.currentSong = this.playlist.head;
77
- * }
78
- *
79
- * // Play the next song in the playlist
80
- * playNext(): Song | undefined {
81
- * if (!this.currentSong?.next) {
82
- * this.currentSong = this.playlist.head; // Loop to the first song
83
- * } else {
84
- * this.currentSong = this.currentSong.next;
85
- * }
86
- * return this.currentSong?.value;
87
- * }
88
- *
89
- * // Play the previous song in the playlist
90
- * playPrevious(): Song | undefined {
91
- * if (!this.currentSong?.prev) {
92
- * this.currentSong = this.playlist.tail; // Loop to the last song
93
- * } else {
94
- * this.currentSong = this.currentSong.prev;
95
- * }
96
- * return this.currentSong?.value;
97
- * }
98
- *
99
- * // Get the current song
100
- * getCurrentSong(): Song | undefined {
101
- * return this.currentSong?.value;
102
- * }
103
- *
104
- * // Loop through the playlist twice
105
- * loopThroughPlaylist(): Song[] {
106
- * const playedSongs: Song[] = [];
107
- * const initialNode = this.currentSong;
108
- *
109
- * // Loop through the playlist twice
110
- * for (let i = 0; i < this.playlist.length * 2; i++) {
111
- * playedSongs.push(this.currentSong!.value);
112
- * this.currentSong = this.currentSong!.next || this.playlist.head; // Loop back to the start if needed
113
- * }
114
- *
115
- * // Reset the current song to the initial song
116
- * this.currentSong = initialNode;
117
- * return playedSongs;
118
- * }
119
- * }
120
- *
121
- * const songs = [
122
- * { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
123
- * { title: 'Hotel California', artist: 'Eagles', duration: 391 },
124
- * { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
125
- * { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
126
- * ];
127
- * let player = new Player(songs);
128
- * // should play the next song
129
- * player = new Player(songs);
130
- * const firstSong = player.getCurrentSong();
131
- * const nextSong = player.playNext();
132
- *
133
- * // Expect the next song to be "Hotel California by Eagles"
134
- * console.log(nextSong); // { title: 'Hotel California', artist: 'Eagles', duration: 391 }
135
- * console.log(firstSong); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
136
- *
137
- * // should play the previous song
138
- * player = new Player(songs);
139
- * player.playNext(); // Move to the second song
140
- * const currentSong = player.getCurrentSong();
141
- * const previousSong = player.playPrevious();
142
- *
143
- * // Expect the previous song to be "Bohemian Rhapsody by Queen"
144
- * console.log(previousSong); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
145
- * console.log(currentSong); // { title: 'Hotel California', artist: 'Eagles', duration: 391 }
146
- *
147
- * // should loop to the first song when playing next from the last song
148
- * player = new Player(songs);
149
- * player.playNext(); // Move to the second song
150
- * player.playNext(); // Move to the third song
151
- * player.playNext(); // Move to the fourth song
152
- *
153
- * const nextSongToFirst = player.playNext(); // Should loop to the first song
154
- *
155
- * // Expect the next song to be "Bohemian Rhapsody by Queen"
156
- * console.log(nextSongToFirst); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
157
- *
158
- * // should loop to the last song when playing previous from the first song
159
- * player = new Player(songs);
160
- * player.playNext(); // Move to the first song
161
- * player.playNext(); // Move to the second song
162
- * player.playNext(); // Move to the third song
163
- * player.playNext(); // Move to the fourth song
164
- *
165
- * const previousToLast = player.playPrevious(); // Should loop to the last song
166
- *
167
- * // Expect the previous song to be "Billie Jean by Michael Jackson"
168
- * console.log(previousToLast); // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
169
- *
170
- * // should loop through the entire playlist
171
- * player = new Player(songs);
172
- * const playedSongs = player.loopThroughPlaylist();
173
- *
174
- * // The expected order of songs for two loops
175
- * console.log(playedSongs); // [
176
- * // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
177
- * // { title: 'Hotel California', artist: 'Eagles', duration: 391 },
178
- * // { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
179
- * // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 },
180
- * // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
181
- * // { title: 'Hotel California', artist: 'Eagles', duration: 391 },
182
- * // { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
183
- * // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
184
- * // ]
185
- * @example
186
- * // Use DoublyLinkedList to implement LRU cache
187
- * interface CacheEntry<K, V> {
188
- * key: K;
189
- * value: V;
190
- * }
191
- *
192
- * class LRUCache<K = string, V = any> {
193
- * private readonly capacity: number;
194
- * private list: DoublyLinkedList<CacheEntry<K, V>>;
195
- * private map: Map<K, DoublyLinkedListNode<CacheEntry<K, V>>>;
196
- *
197
- * constructor(capacity: number) {
198
- * if (capacity <= 0) {
199
- * throw new Error('lru cache capacity must be greater than 0');
200
- * }
201
- * this.capacity = capacity;
202
- * this.list = new DoublyLinkedList<CacheEntry<K, V>>();
203
- * this.map = new Map<K, DoublyLinkedListNode<CacheEntry<K, V>>>();
204
- * }
205
- *
206
- * // Get cached value
207
- * get(key: K): V | undefined {
208
- * const node = this.map.get(key);
209
- *
210
- * if (!node) return undefined;
211
- *
212
- * // Move the visited node to the head of the linked list (most recently used)
213
- * this.moveToFront(node);
214
- *
215
- * return node.value.value;
216
- * }
217
- *
218
- * // Set cache value
219
- * set(key: K, value: V): void {
220
- * // Check if it already exists
221
- * const node = this.map.get(key);
222
- *
223
- * if (node) {
224
- * // Update value and move to head
225
- * node.value.value = value;
226
- * this.moveToFront(node);
227
- * return;
228
- * }
229
- *
230
- * // Check capacity
231
- * if (this.list.length >= this.capacity) {
232
- * // Delete the least recently used element (the tail of the linked list)
233
- * const removedNode = this.list.tail;
234
- * if (removedNode) {
235
- * this.map.delete(removedNode.value.key);
236
- * this.list.pop();
237
- * }
238
- * }
239
- *
240
- * // Create new node and add to head
241
- * const newEntry: CacheEntry<K, V> = { key, value };
242
- * this.list.unshift(newEntry);
243
- *
244
- * // Save node reference in map
245
- * const newNode = this.list.head;
246
- * if (newNode) {
247
- * this.map.set(key, newNode);
248
- * }
249
- * }
250
- *
251
- * // Move the node to the head of the linked list
252
- * private moveToFront(node: DoublyLinkedListNode<CacheEntry<K, V>>): void {
253
- * this.list.delete(node);
254
- * this.list.unshift(node.value);
255
- * }
256
- *
257
- * // Delete specific key
258
- * delete(key: K): boolean {
259
- * const node = this.map.get(key);
260
- * if (!node) return false;
261
- *
262
- * // Remove from linked list
263
- * this.list.delete(node);
264
- * // Remove from map
265
- * this.map.delete(key);
266
- *
267
- * return true;
268
- * }
269
- *
270
- * // Clear cache
271
- * clear(): void {
272
- * this.list.clear();
273
- * this.map.clear();
274
- * }
275
- *
276
- * // Get the current cache length
277
- * get length(): number {
278
- * return this.list.length;
279
- * }
280
- *
281
- * // Check if it is empty
282
- * get isEmpty(): boolean {
283
- * return this.list.isEmpty();
284
- * }
285
- * }
286
- *
287
- * // should set and get values correctly
288
- * const cache = new LRUCache<string, number>(3);
289
- * cache.set('a', 1);
290
- * cache.set('b', 2);
291
- * cache.set('c', 3);
292
- *
293
- * console.log(cache.get('a')); // 1
294
- * console.log(cache.get('b')); // 2
295
- * console.log(cache.get('c')); // 3
296
- *
297
- * // The least recently used element should be evicted when capacity is exceeded
298
- * cache.clear();
299
- * cache.set('a', 1);
300
- * cache.set('b', 2);
301
- * cache.set('c', 3);
302
- * cache.set('d', 4); // This will eliminate 'a'
303
- *
304
- * console.log(cache.get('a')); // undefined
305
- * console.log(cache.get('b')); // 2
306
- * console.log(cache.get('c')); // 3
307
- * console.log(cache.get('d')); // 4
308
- *
309
- * // The priority of an element should be updated when it is accessed
310
- * cache.clear();
311
- * cache.set('a', 1);
312
- * cache.set('b', 2);
313
- * cache.set('c', 3);
314
- *
315
- * cache.get('a'); // access 'a'
316
- * cache.set('d', 4); // This will eliminate 'b'
317
- *
318
- * console.log(cache.get('a')); // 1
319
- * console.log(cache.get('b')); // undefined
320
- * console.log(cache.get('c')); // 3
321
- * console.log(cache.get('d')); // 4
322
- *
323
- * // Should support updating existing keys
324
- * cache.clear();
325
- * cache.set('a', 1);
326
- * cache.set('a', 10);
327
- *
328
- * console.log(cache.get('a')); // 10
329
- *
330
- * // Should support deleting specified keys
331
- * cache.clear();
332
- * cache.set('a', 1);
333
- * cache.set('b', 2);
334
- *
335
- * console.log(cache.delete('a')); // true
336
- * console.log(cache.get('a')); // undefined
337
- * console.log(cache.length); // 1
338
- *
339
- * // Should support clearing cache
340
- * cache.clear();
341
- * cache.set('a', 1);
342
- * cache.set('b', 2);
343
- * cache.clear();
344
- *
345
- * console.log(cache.length); // 0
346
- * console.log(cache.isEmpty); // true
347
- * @example
348
- * // finding lyrics by timestamp in Coldplay's "Fix You"
349
- * // Create a DoublyLinkedList to store song lyrics with timestamps
350
- * const lyricsList = new DoublyLinkedList<{ time: number; text: string }>();
351
- *
352
- * // Detailed lyrics with precise timestamps (in milliseconds)
353
- * const lyrics = [
354
- * { time: 0, text: "When you try your best, but you don't succeed" },
355
- * { time: 4000, text: 'When you get what you want, but not what you need' },
356
- * { time: 8000, text: "When you feel so tired, but you can't sleep" },
357
- * { time: 12000, text: 'Stuck in reverse' },
358
- * { time: 16000, text: 'And the tears come streaming down your face' },
359
- * { time: 20000, text: "When you lose something you can't replace" },
360
- * { time: 24000, text: 'When you love someone, but it goes to waste' },
361
- * { time: 28000, text: 'Could it be worse?' },
362
- * { time: 32000, text: 'Lights will guide you home' },
363
- * { time: 36000, text: 'And ignite your bones' },
364
- * { time: 40000, text: 'And I will try to fix you' }
365
- * ];
366
- *
367
- * // Populate the DoublyLinkedList with lyrics
368
- * lyrics.forEach(lyric => lyricsList.push(lyric));
369
- *
370
- * // Test different scenarios of lyric synchronization
371
- *
372
- * // 1. Find lyric at exact timestamp
373
- * const exactTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 36000);
374
- * console.log(exactTimeLyric?.text); // 'And ignite your bones'
375
- *
376
- * // 2. Find lyric between timestamps
377
- * const betweenTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 22000);
378
- * console.log(betweenTimeLyric?.text); // "When you lose something you can't replace"
379
- *
380
- * // 3. Find first lyric when timestamp is less than first entry
381
- * const earlyTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= -1000);
382
- * console.log(earlyTimeLyric); // undefined
383
- *
384
- * // 4. Find last lyric when timestamp is after last entry
385
- * const lateTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 50000);
386
- * console.log(lateTimeLyric?.text); // 'And I will try to fix you'
387
- * @example
388
- * // cpu process schedules
389
- * class Process {
390
- * constructor(
391
- * public id: number,
392
- * public priority: number
393
- * ) {}
394
- *
395
- * execute(): string {
396
- * return `Process ${this.id} executed.`;
397
- * }
398
- * }
399
- *
400
- * class Scheduler {
401
- * private queue: DoublyLinkedList<Process>;
402
- *
403
- * constructor() {
404
- * this.queue = new DoublyLinkedList<Process>();
405
- * }
406
- *
407
- * addProcess(process: Process): void {
408
- * // Insert processes into a queue based on priority, keeping priority in descending order
409
- * let current = this.queue.head;
410
- * while (current && current.value.priority >= process.priority) {
411
- * current = current.next;
412
- * }
413
- *
414
- * if (!current) {
415
- * this.queue.push(process);
416
- * } else {
417
- * this.queue.addBefore(current, process);
418
- * }
419
- * }
420
- *
421
- * executeNext(): string | undefined {
422
- * // Execute tasks at the head of the queue in order
423
- * const process = this.queue.shift();
424
- * return process ? process.execute() : undefined;
425
- * }
426
- *
427
- * listProcesses(): string[] {
428
- * return this.queue.toArray().map(process => `Process ${process.id} (Priority: ${process.priority})`);
429
- * }
430
- *
431
- * clear(): void {
432
- * this.queue.clear();
433
- * }
434
- * }
435
- *
436
- * // should add processes based on priority
437
- * let scheduler = new Scheduler();
438
- * scheduler.addProcess(new Process(1, 10));
439
- * scheduler.addProcess(new Process(2, 20));
440
- * scheduler.addProcess(new Process(3, 15));
441
- *
442
- * console.log(scheduler.listProcesses()); // [
443
- * // 'Process 2 (Priority: 20)',
444
- * // 'Process 3 (Priority: 15)',
445
- * // 'Process 1 (Priority: 10)'
446
- * // ]
447
- *
448
- * // should execute the highest priority process
449
- * scheduler = new Scheduler();
450
- * scheduler.addProcess(new Process(1, 10));
451
- * scheduler.addProcess(new Process(2, 20));
452
- *
453
- * console.log(scheduler.executeNext()); // 'Process 2 executed.'
454
- * console.log(scheduler.listProcesses()); // ['Process 1 (Priority: 10)']
455
- *
456
- * // should clear all processes
457
- * scheduler = new Scheduler();
458
- * scheduler.addProcess(new Process(1, 10));
459
- * scheduler.addProcess(new Process(2, 20));
460
- *
461
- * scheduler.clear();
462
- * console.log(scheduler.listProcesses()); // []
463
- */
464
- class DoublyLinkedList extends linear_base_1.LinearLinkedBase {
465
- /**
466
- * This TypeScript constructor initializes a DoublyLinkedList with optional elements and options.
467
- * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the constructor is an
468
- * iterable collection of elements of type `E` or `R`. It is used to initialize the DoublyLinkedList
469
- * with the elements provided in the iterable. If no elements are provided, the default value is an
470
- * empty iterable.
471
- * @param [options] - The `options` parameter in the constructor is of type
472
- * `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
473
- * configuration options to customize the behavior of the DoublyLinkedList.
474
- */
475
- constructor(elements = [], options) {
476
- super(options);
477
- this._head = undefined;
478
- this._tail = undefined;
479
- this._length = 0;
480
- if (options) {
481
- const { maxLen } = options;
482
- if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
483
- this._maxLen = maxLen;
484
- }
485
- this.pushMany(elements);
486
- }
487
- get head() {
488
- return this._head;
489
- }
490
- get tail() {
491
- return this._tail;
492
- }
493
- get length() {
494
- return this._length;
495
- }
496
- /**
497
- * Time Complexity: O(1)
498
- * Space Complexity: O(1)
499
- *
500
- * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
501
- * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
502
- */
503
- get first() {
504
- var _a;
505
- return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
506
- }
507
- /**
508
- * Time Complexity: O(1)
509
- * Space Complexity: O(1)
510
- *
511
- * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
512
- * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
513
- */
514
- get last() {
515
- var _a;
516
- return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
517
- }
518
- /**
519
- * Time Complexity: O(n)
520
- * Space Complexity: O(n)
521
- *
522
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
523
- * given array.
524
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
525
- * @returns The `fromArray` function returns a DoublyLinkedList object.
526
- */
527
- static fromArray(data) {
528
- return new DoublyLinkedList(data);
529
- }
530
- /**
531
- * Time Complexity: O(1)
532
- * Space Complexity: O(1)
533
- *
534
- * The function `isNode` in TypeScript checks if a given input is an instance of
535
- * `DoublyLinkedListNode`.
536
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
537
- * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `isNode` function can
538
- * be one of the following types:
539
- * @returns The `isNode` function is checking if the `elementNodeOrPredicate` parameter is an
540
- * instance of `DoublyLinkedListNode<E>`. If it is, the function returns `true`, indicating that the
541
- * parameter is a `DoublyLinkedListNode<E>`. If it is not an instance of `DoublyLinkedListNode<E>`,
542
- * the function returns `false`.
543
- */
544
- isNode(elementNodeOrPredicate) {
545
- return elementNodeOrPredicate instanceof DoublyLinkedListNode;
546
- }
547
- /**
548
- * Time Complexity: O(1)
549
- * Space Complexity: O(1)
550
- *
551
- * The `push` function adds a new element or node to the end of a doubly linked list.
552
- * @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the `push`
553
- * method can accept either an element of type `E` or a `DoublyLinkedListNode<E>` object.
554
- * @returns The `push` method is returning a boolean value, specifically `true`.
555
- */
556
- push(elementOrNode) {
557
- const newNode = this._ensureNode(elementOrNode);
558
- if (!this.head) {
559
- this._head = newNode;
560
- this._tail = newNode;
561
- }
562
- else {
563
- newNode.prev = this.tail;
564
- this.tail.next = newNode;
565
- this._tail = newNode;
566
- }
567
- this._length++;
568
- if (this._maxLen > 0 && this.length > this._maxLen)
569
- this.shift();
570
- return true;
571
- }
572
- /**
573
- * Time Complexity: O(1)
574
- * Space Complexity: O(1)
575
- *
576
- * The `pop()` function removes and returns the value of the last element in a linked list.
577
- * @returns The method is returning the value of the removed node.
578
- */
579
- pop() {
580
- if (!this.tail)
581
- return undefined;
582
- const removedNode = this.tail;
583
- if (this.head === this.tail) {
584
- this._head = undefined;
585
- this._tail = undefined;
586
- }
587
- else {
588
- this._tail = removedNode.prev;
589
- this.tail.next = undefined;
590
- }
591
- this._length--;
592
- return removedNode.value;
593
- }
594
- /**
595
- * Time Complexity: O(1)
596
- * Space Complexity: O(1)
597
- *
598
- * The `shift()` function removes and returns the value of the first element in a doubly linked list.
599
- * @returns The value of the removed node.
600
- */
601
- shift() {
602
- if (!this.head)
603
- return undefined;
604
- const removedNode = this.head;
605
- if (this.head === this.tail) {
606
- this._head = undefined;
607
- this._tail = undefined;
608
- }
609
- else {
610
- this._head = removedNode.next;
611
- this.head.prev = undefined;
612
- }
613
- this._length--;
614
- return removedNode.value;
615
- }
616
- /**
617
- * Time Complexity: O(1)
618
- * Space Complexity: O(1)
619
- *
620
- * The unshift function adds a new element or node to the beginning of a doubly linked list.
621
- * @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the
622
- * `unshift` method can be either an element of type `E` or a `DoublyLinkedListNode` containing an
623
- * element of type `E`.
624
- * @returns The `unshift` method is returning a boolean value, specifically `true`.
625
- */
626
- unshift(elementOrNode) {
627
- const newNode = this._ensureNode(elementOrNode);
628
- if (!this.head) {
629
- this._head = newNode;
630
- this._tail = newNode;
631
- }
632
- else {
633
- newNode.next = this.head;
634
- this.head.prev = newNode;
635
- this._head = newNode;
636
- }
637
- this._length++;
638
- if (this._maxLen > 0 && this._length > this._maxLen)
639
- this.pop();
640
- return true;
641
- }
642
- /**
643
- * Time Complexity: O(k)
644
- * Space Complexity: O(k)
645
- *
646
- * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
647
- * transformation function if provided.
648
- * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
649
- * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
650
- * or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
651
- * it onto the linked list. If a transformation function `to
652
- * @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
653
- * the success or failure of pushing each element into the data structure.
654
- */
655
- pushMany(elements) {
656
- const ans = [];
657
- for (const el of elements) {
658
- if (this.toElementFn) {
659
- ans.push(this.push(this.toElementFn(el)));
660
- continue;
661
- }
662
- ans.push(this.push(el));
663
- }
664
- return ans;
665
- }
666
- /**
667
- * Time Complexity: O(k)
668
- * Space Complexity: O(k)
669
- *
670
- * The function `unshiftMany` iterates through a collection of elements and adds them to the
671
- * beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
672
- * each insertion.
673
- * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
674
- * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
675
- * `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
676
- * performs an `unshift` operation on the doubly linked list
677
- * @returns The `unshiftMany` function returns an array of boolean values indicating the success of
678
- * each unshift operation performed on the elements passed as input.
679
- */
680
- unshiftMany(elements) {
681
- const ans = [];
682
- for (const el of elements) {
683
- if (this.toElementFn) {
684
- ans.push(this.unshift(this.toElementFn(el)));
685
- continue;
686
- }
687
- ans.push(this.unshift(el));
688
- }
689
- return ans;
690
- }
691
- /**
692
- * Time Complexity: O(n)
693
- * Space Complexity: O(1)
694
- *
695
- * The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
696
- * @param {number} index - The index parameter is a number that represents the position of the element we want to
697
- * retrieve from the list.
698
- * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
699
- * or the linked list is empty, it will return undefined.
700
- */
701
- at(index) {
702
- if (index < 0 || index >= this._length)
703
- return undefined;
704
- let current = this.head;
705
- for (let i = 0; i < index; i++) {
706
- current = current.next;
707
- }
708
- return current.value;
709
- }
710
- /**
711
- * Time Complexity: O(n)
712
- * Space Complexity: O(1)
713
- *
714
- * The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
715
- * range.
716
- * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
717
- * retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
718
- * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode<E>` object if the index is within the
719
- * valid range of the linked list, otherwise it returns `undefined`.
720
- */
721
- getNodeAt(index) {
722
- if (index < 0 || index >= this._length)
723
- return undefined;
724
- let current = this.head;
725
- for (let i = 0; i < index; i++) {
726
- current = current.next;
727
- }
728
- return current;
729
- }
730
- /**
731
- * Time Complexity: O(n)
732
- * Space Complexity: O(1)
733
- *
734
- * This TypeScript function searches for a node in a doubly linked list based on a given element node
735
- * or predicate.
736
- * @param {| E
737
- * | DoublyLinkedListNode<E>
738
- * | ((node: DoublyLinkedListNode<E>) => boolean)
739
- * | undefined} elementNodeOrPredicate - The `getNode` method you provided is used to find a
740
- * node in a doubly linked list based on a given element, node, or predicate function. The
741
- * `elementNodeOrPredicate` parameter can be one of the following:
742
- * @returns The `getNode` method returns a `DoublyLinkedListNode<E>` or `undefined` based on the
743
- * input `elementNodeOrPredicate`. If the input is `undefined`, the method returns `undefined`.
744
- * Otherwise, it iterates through the linked list starting from the head node and applies the
745
- * provided predicate function to each node. If a node satisfies the predicate, that node is
746
- * returned. If
747
- */
748
- getNode(elementNodeOrPredicate) {
749
- if (elementNodeOrPredicate === undefined)
750
- return;
751
- if (this.isNode(elementNodeOrPredicate))
752
- return elementNodeOrPredicate;
753
- const predicate = this._ensurePredicate(elementNodeOrPredicate);
754
- let current = this.head;
755
- while (current) {
756
- if (predicate(current)) {
757
- return current;
758
- }
759
- current = current.next;
760
- }
761
- return undefined;
762
- }
763
- /**
764
- * Time Complexity: O(n)
765
- * Space Complexity: O(1)
766
- *
767
- * The `addAt` function inserts a new element or node at a specified index in a doubly linked list.
768
- * @param {number} index - The `index` parameter in the `addAt` method represents the position at
769
- * which you want to add a new element or node in the doubly linked list. It indicates the location
770
- * where the new element or node should be inserted.
771
- * @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
772
- * `addAt` method can be either a value of type `E` or a `DoublyLinkedListNode<E>` object.
773
- * @returns The `addAt` method returns a boolean value. It returns `true` if the element or node was
774
- * successfully added at the specified index, and `false` if the index is out of bounds (less than 0
775
- * or greater than the length of the list).
776
- */
777
- addAt(index, newElementOrNode) {
778
- if (index < 0 || index > this._length)
779
- return false;
780
- if (index === 0) {
781
- this.unshift(newElementOrNode);
782
- return true;
783
- }
784
- if (index === this._length) {
785
- this.push(newElementOrNode);
786
- return true;
787
- }
788
- const newNode = this._ensureNode(newElementOrNode);
789
- const prevNode = this.getNodeAt(index - 1);
790
- const nextNode = prevNode.next;
791
- newNode.prev = prevNode;
792
- newNode.next = nextNode;
793
- prevNode.next = newNode;
794
- nextNode.prev = newNode;
795
- this._length++;
796
- return true;
797
- }
798
- /**
799
- * Time Complexity: O(1) or O(n)
800
- * Space Complexity: O(1)
801
- *
802
- * The `addBefore` function in TypeScript adds a new element or node before an existing element or
803
- * node in a doubly linked list.
804
- * @param {E | DoublyLinkedListNode<E>} existingElementOrNode - The `existingElementOrNode` parameter
805
- * in the `addBefore` method can be either an element of type `E` or a `DoublyLinkedListNode<E>`.
806
- * @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter
807
- * represents the element or node that you want to add before the `existingElementOrNode` in a doubly
808
- * linked list.
809
- * @returns The `addBefore` method returns a boolean value - `true` if the new element or node was
810
- * successfully added before the existing element or node, and `false` if the existing element or
811
- * node was not found.
812
- */
813
- addBefore(existingElementOrNode, newElementOrNode) {
814
- const existingNode = this.isNode(existingElementOrNode)
815
- ? existingElementOrNode
816
- : this.getNode(existingElementOrNode);
817
- if (existingNode) {
818
- const newNode = this._ensureNode(newElementOrNode);
819
- newNode.prev = existingNode.prev;
820
- if (existingNode.prev) {
821
- existingNode.prev.next = newNode;
822
- }
823
- newNode.next = existingNode;
824
- existingNode.prev = newNode;
825
- if (existingNode === this.head) {
826
- this._head = newNode;
827
- }
828
- this._length++;
829
- return true;
830
- }
831
- return false;
832
- }
833
- /**
834
- * Time Complexity: O(1) or O(n)
835
- * Space Complexity: O(1)
836
- *
837
- * The `addAfter` function in TypeScript adds a new element or node after an existing element or node
838
- * in a doubly linked list.
839
- * @param {E | DoublyLinkedListNode<E>} existingElementOrNode - existingElementOrNode represents the
840
- * element or node in the doubly linked list after which you want to add a new element or node.
841
- * @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
842
- * `addAfter` method represents the element or node that you want to add after the existing element
843
- * or node in a doubly linked list. This parameter can be either an element value or a
844
- * `DoublyLinkedListNode` object that you want to insert
845
- * @returns The `addAfter` method returns a boolean value - `true` if the new element or node was
846
- * successfully added after the existing element or node, and `false` if the existing element or node
847
- * was not found in the linked list.
848
- */
849
- addAfter(existingElementOrNode, newElementOrNode) {
850
- const existingNode = this.isNode(existingElementOrNode)
851
- ? existingElementOrNode
852
- : this.getNode(existingElementOrNode);
853
- if (existingNode) {
854
- const newNode = this._ensureNode(newElementOrNode);
855
- newNode.next = existingNode.next;
856
- if (existingNode.next) {
857
- existingNode.next.prev = newNode;
858
- }
859
- newNode.prev = existingNode;
860
- existingNode.next = newNode;
861
- if (existingNode === this.tail) {
862
- this._tail = newNode;
863
- }
864
- this._length++;
865
- return true;
866
- }
867
- return false;
868
- }
869
- /**
870
- * Time Complexity: O(n)
871
- * Space Complexity: O(1)
872
- *
873
- * The function `setAt` updates the value at a specified index in a data structure if the index
874
- * exists.
875
- * @param {number} index - The `index` parameter in the `setAt` method refers to the position in the
876
- * data structure where you want to set a new value.
877
- * @param {E} value - The `value` parameter in the `setAt` method represents the new value that you
878
- * want to set at the specified index in the data structure.
879
- * @returns The `setAt` method returns a boolean value - `true` if the value at the specified index
880
- * is successfully updated, and `false` if the index is out of bounds.
881
- */
882
- setAt(index, value) {
883
- const node = this.getNodeAt(index);
884
- if (node) {
885
- node.value = value;
886
- return true;
887
- }
888
- return false;
889
- }
890
- /**
891
- * Time Complexity: O(n)
892
- * Space Complexity: O(1)
893
- *
894
- * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
895
- * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
896
- * data structure. It is of type number.
897
- * @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
898
- * bounds.
899
- */
900
- deleteAt(index) {
901
- if (index < 0 || index >= this._length)
902
- return;
903
- let deleted;
904
- if (index === 0) {
905
- deleted = this.first;
906
- this.shift();
907
- return deleted;
908
- }
909
- if (index === this._length - 1) {
910
- deleted = this.last;
911
- this.pop();
912
- return deleted;
913
- }
914
- const removedNode = this.getNodeAt(index);
915
- const prevNode = removedNode.prev;
916
- const nextNode = removedNode.next;
917
- prevNode.next = nextNode;
918
- nextNode.prev = prevNode;
919
- this._length--;
920
- return removedNode === null || removedNode === void 0 ? void 0 : removedNode.value;
921
- }
922
- /**
923
- * Time Complexity: O(1) or O(n)
924
- * Space Complexity: O(1)
925
- *
926
- * The `delete` function removes a specified element or node from a doubly linked list if it exists.
927
- * @param {E | DoublyLinkedListNode<E> | undefined} elementOrNode - The `elementOrNode` parameter in
928
- * the `delete` method can accept an element of type `E`, a `DoublyLinkedListNode` of type `E`, or it
929
- * can be `undefined`. This parameter is used to identify the node that needs to be deleted from the
930
- * doubly linked list
931
- * @returns The `delete` method returns a boolean value - `true` if the element or node was
932
- * successfully deleted from the doubly linked list, and `false` if the element or node was not found
933
- * in the list.
934
- */
935
- delete(elementOrNode) {
936
- const node = this.getNode(elementOrNode);
937
- if (node) {
938
- if (node === this.head) {
939
- this.shift();
940
- }
941
- else if (node === this.tail) {
942
- this.pop();
943
- }
944
- else {
945
- const prevNode = node.prev;
946
- const nextNode = node.next;
947
- if (prevNode)
948
- prevNode.next = nextNode;
949
- if (nextNode)
950
- nextNode.prev = prevNode;
951
- this._length--;
952
- }
953
- return true;
954
- }
955
- return false;
956
- }
957
- /**
958
- * Time Complexity: O(1)
959
- * Space Complexity: O(1)
960
- *
961
- * The function checks if a variable has a length greater than zero and returns a boolean value.
962
- * @returns A boolean value is being returned.
963
- */
964
- isEmpty() {
965
- return this._length === 0;
966
- }
967
- /**
968
- * Time Complexity: O(1)
969
- * Space Complexity: O(1)
970
- *
971
- * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
972
- */
973
- clear() {
974
- this._head = undefined;
975
- this._tail = undefined;
976
- this._length = 0;
977
- }
978
- /**
979
- * Time Complexity: O(n)
980
- * Space Complexity: O(1)
981
- *
982
- * This function retrieves an element from a doubly linked list based on a given element
983
- * node or predicate.
984
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
985
- * elementNodeOrPredicate - The `get` method takes in a parameter called `elementNodeOrPredicate`,
986
- * which can be one of the following types:
987
- * @returns The `get` method returns the value of the first node in the doubly linked list that
988
- * satisfies the provided predicate function. If no such node is found, it returns `undefined`.
989
- */
990
- search(elementNodeOrPredicate) {
991
- const predicate = this._ensurePredicate(elementNodeOrPredicate);
992
- let current = this.head;
993
- while (current) {
994
- if (predicate(current))
995
- return current.value;
996
- current = current.next;
997
- }
998
- return undefined;
999
- }
1000
- /**
1001
- * Time Complexity: O(n)
1002
- * Space Complexity: O(1)
1003
- *
1004
- * The `getBackward` function searches for a specific element in a doubly linked list starting from
1005
- * the tail and moving backwards.
1006
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
1007
- * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `getBackward`
1008
- * function can be one of the following types:
1009
- * @returns The `getBackward` method returns the value of the element node that matches the provided
1010
- * predicate when traversing the doubly linked list backwards. If no matching element is found, it
1011
- * returns `undefined`.
1012
- */
1013
- getBackward(elementNodeOrPredicate) {
1014
- const predicate = this._ensurePredicate(elementNodeOrPredicate);
1015
- let current = this.tail;
1016
- while (current) {
1017
- if (predicate(current))
1018
- return current.value;
1019
- current = current.prev;
1020
- }
1021
- return undefined;
1022
- }
1023
- /**
1024
- * Time Complexity: O(n)
1025
- * Space Complexity: O(1)
1026
- *
1027
- * The `reverse` function reverses the order of the elements in a doubly linked list.
1028
- */
1029
- reverse() {
1030
- let current = this.head;
1031
- [this._head, this._tail] = [this.tail, this.head];
1032
- while (current) {
1033
- const next = current.next;
1034
- [current.prev, current.next] = [current.next, current.prev];
1035
- current = next;
1036
- }
1037
- return this;
1038
- }
1039
- /**
1040
- * Time Complexity: O(n)
1041
- * Space Complexity: O(n)
1042
- *
1043
- * The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
1044
- * as the original list.
1045
- * @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
1046
- * is a copy of the original list.
1047
- */
1048
- clone() {
1049
- return new DoublyLinkedList(this, { toElementFn: this._toElementFn, maxLen: this._maxLen });
1050
- }
1051
- /**
1052
- * Time Complexity: O(n)
1053
- * Space Complexity: O(n)
1054
- *
1055
- * The `filter` function creates a new DoublyLinkedList by iterating over the elements of the current
1056
- * list and applying a callback function to each element, returning only the elements for which the
1057
- * callback function returns true.
1058
- * @param callback - The `callback` parameter is a function that will be called for each element in
1059
- * the DoublyLinkedList. It takes three arguments: the current element, the index of the current
1060
- * element, and the DoublyLinkedList itself. The callback function should return a boolean value
1061
- * indicating whether the current element should be included
1062
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
1063
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
1064
- * passed as the `this` value to the `callback` function. If `thisArg` is
1065
- * @returns The `filter` method is returning a new `DoublyLinkedList` object that contains the
1066
- * elements that pass the filter condition specified by the `callback` function.
1067
- */
1068
- filter(callback, thisArg) {
1069
- const filteredList = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
1070
- let index = 0;
1071
- for (const current of this) {
1072
- if (callback.call(thisArg, current, index, this)) {
1073
- filteredList.push(current);
1074
- }
1075
- index++;
1076
- }
1077
- return filteredList;
1078
- }
1079
- /**
1080
- * Time Complexity: O(n)
1081
- * Space Complexity: O(n)
1082
- *
1083
- * The `map` function takes a callback function and returns a new DoublyLinkedList with the results
1084
- * of applying the callback to each element in the original list.
1085
- * @param callback - The callback parameter is a function that will be called for each element in the
1086
- * original DoublyLinkedList. It takes three arguments: current (the current element being
1087
- * processed), index (the index of the current element), and this (the original DoublyLinkedList).
1088
- * The callback function should return a value of type
1089
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
1090
- * convert the raw element (`RR`) to the desired element type (`T`). It takes the raw element as
1091
- * input and returns the converted element. If this parameter is not provided, the raw element will
1092
- * be used as is.
1093
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1094
- * specify the value of `this` within the callback function. It is used to set the context or scope
1095
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
1096
- * value of
1097
- * @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
1098
- */
1099
- map(callback, toElementFn, thisArg) {
1100
- const mappedList = new DoublyLinkedList([], { toElementFn, maxLen: this._maxLen });
1101
- let index = 0;
1102
- for (const current of this) {
1103
- mappedList.push(callback.call(thisArg, current, index, this));
1104
- index++;
1105
- }
1106
- return mappedList;
1107
- }
1108
- /**
1109
- * Time Complexity: O(n)
1110
- * Space Complexity: O(1)
1111
- *
1112
- * The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
1113
- * of a specified element or nodes that satisfy a given predicate.
1114
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
1115
- * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
1116
- * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
1117
- * node, or predicate function in the doubly linked list.
1118
- */
1119
- countOccurrences(elementOrNode) {
1120
- const predicate = this._ensurePredicate(elementOrNode);
1121
- let count = 0;
1122
- let current = this.head;
1123
- while (current) {
1124
- if (predicate(current)) {
1125
- count++;
1126
- }
1127
- current = current.next;
1128
- }
1129
- return count;
1130
- }
1131
- /**
1132
- * The function returns an iterator that iterates over the values of a linked list.
1133
- */
1134
- *_getIterator() {
1135
- let current = this.head;
1136
- while (current) {
1137
- yield current.value;
1138
- current = current.next;
1139
- }
1140
- }
1141
- /**
1142
- * The function returns an iterator that iterates over the elements of a data structure in reverse
1143
- * order.
1144
- */
1145
- *_getReverseIterator() {
1146
- let current = this.tail;
1147
- while (current) {
1148
- yield current.value;
1149
- current = current.prev;
1150
- }
1151
- }
1152
- /**
1153
- * The function returns an iterator that iterates over the nodes of a doubly linked list starting
1154
- * from the head.
1155
- */
1156
- *_getNodeIterator() {
1157
- let current = this.head;
1158
- while (current) {
1159
- yield current;
1160
- current = current.next;
1161
- }
1162
- }
1163
- // protected *_getReverseNodeIterator(): IterableIterator<DoublyLinkedListNode<E>> {
1164
- // const reversedArr = [...this._getNodeIterator()].reverse();
1165
- //
1166
- // for (const item of reversedArr) {
1167
- // yield item;
1168
- // }
1169
- // }
1170
- /**
1171
- * The function `_isPredicate` checks if the input is a function that takes a `DoublyLinkedListNode`
1172
- * as an argument and returns a boolean.
1173
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
1174
- * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
1175
- * types:
1176
- * @returns The _isPredicate method is returning a boolean value indicating whether the
1177
- * elementNodeOrPredicate parameter is a function or not. If the elementNodeOrPredicate is a
1178
- * function, the method will return true, indicating that it is a predicate function.
1179
- */
1180
- _isPredicate(elementNodeOrPredicate) {
1181
- return typeof elementNodeOrPredicate === 'function';
1182
- }
1183
- /**
1184
- * The function `_ensureNode` ensures that the input is a valid node in a doubly linked list.
1185
- * @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter can be either
1186
- * an element of type `E` or a `DoublyLinkedListNode` containing an element of type `E`.
1187
- * @returns If the `elementOrNode` parameter is already a `DoublyLinkedListNode`, it will be returned
1188
- * as is. Otherwise, a new `DoublyLinkedListNode` instance will be created with the `elementOrNode`
1189
- * value and returned.
1190
- */
1191
- _ensureNode(elementOrNode) {
1192
- if (this.isNode(elementOrNode))
1193
- return elementOrNode;
1194
- return new DoublyLinkedListNode(elementOrNode);
1195
- }
1196
- /**
1197
- * The function `_ensurePredicate` in TypeScript ensures that the input is either a node, a predicate
1198
- * function, or a value to compare with the node's value.
1199
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
1200
- * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
1201
- * types:
1202
- * @returns A function is being returned that takes a `DoublyLinkedListNode` as a parameter and
1203
- * returns a boolean value based on the conditions specified in the code.
1204
- */
1205
- _ensurePredicate(elementNodeOrPredicate) {
1206
- if (this.isNode(elementNodeOrPredicate))
1207
- return (node) => node === elementNodeOrPredicate;
1208
- if (this._isPredicate(elementNodeOrPredicate))
1209
- return elementNodeOrPredicate;
1210
- return (node) => node.value === elementNodeOrPredicate;
1211
- }
1212
- /**
1213
- * The function `_createInstance` returns a new instance of `DoublyLinkedList` with the specified
1214
- * options.
1215
- * @param [options] - The `options` parameter in the `_createInstance` method is of type
1216
- * `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
1217
- * configuration options when creating a new instance of the `DoublyLinkedList` class.
1218
- * @returns An instance of the `DoublyLinkedList` class with an empty array and the provided options
1219
- * is being returned, cast as the current class type.
1220
- */
1221
- _createInstance(options) {
1222
- return new DoublyLinkedList([], options);
1223
- }
1224
- /**
1225
- * The function `_getPrevNode` returns the previous node of a given node in a doubly linked list.
1226
- * @param node - The parameter `node` in the `_getPrevNode` method is of type
1227
- * `DoublyLinkedListNode<E>`, which represents a node in a doubly linked list containing an element
1228
- * of type `E`.
1229
- * @returns The `_getPrevNode` method is returning the previous node of the input `node` in a doubly
1230
- * linked list. If the input node has a previous node, it will return that node. Otherwise, it will
1231
- * return `undefined`.
1232
- */
1233
- _getPrevNode(node) {
1234
- return node.prev;
1235
- }
1236
- }
1237
- exports.DoublyLinkedList = DoublyLinkedList;
1238
- //# sourceMappingURL=doubly-linked-list.js.map