deque-typed 2.1.0 → 2.1.2

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 (281) hide show
  1. package/dist/cjs/index.cjs +1223 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +1219 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +11 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/deque-typed.js +1232 -0
  87. package/dist/umd/deque-typed.js.map +1 -0
  88. package/dist/umd/deque-typed.min.js +9 -0
  89. package/dist/umd/deque-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +3 -3
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -12
  192. package/dist/index.js +0 -28
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MaxPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- /**
6
- * Max-oriented priority queue (max-heap) built on {@link PriorityQueue}.
7
- * The default comparator orders primitive values in descending order. If you store objects,
8
- * you must provide a custom comparator via {@link PriorityQueueOptions}.
9
- * @template E Element type stored in the queue.
10
- * @template R Extra record/metadata associated with each element.
11
- * @example
12
- */
13
- class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
14
- /**
15
- * Creates a max-priority queue.
16
- * @param elements Optional initial elements to insert.
17
- * @param options Optional configuration (e.g., `comparator`, `toElementFn`).
18
- * @throws {TypeError} Thrown when using the default comparator with object elements (provide a custom comparator).
19
- * @remarks Complexity — Time: O(n log n) when inserting n elements incrementally; Space: O(n).
20
- */
21
- constructor(elements = [], options) {
22
- super(elements, Object.assign({ comparator: (a, b) => {
23
- if (typeof a === 'object' || typeof b === 'object') {
24
- throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
25
- }
26
- if (a < b)
27
- return 1;
28
- if (a > b)
29
- return -1;
30
- return 0;
31
- } }, options));
32
- }
33
- }
34
- exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -1,26 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Kirk Qi
5
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
- * @license MIT License
7
- */
8
- import type { PriorityQueueOptions } from '../../types';
9
- import { PriorityQueue } from './priority-queue';
10
- /**
11
- * Min-oriented priority queue (min-heap) built on {@link PriorityQueue}.
12
- * The queue removes the smallest element first under the provided comparator.
13
- * Provide a custom comparator if you store non-primitive objects.
14
- * @template E Element type stored in the queue.
15
- * @template R Extra record/metadata associated with each element.
16
- * @example
17
- */
18
- export declare class MinPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
19
- /**
20
- * Creates a min-priority queue.
21
- * @param elements Optional initial elements to insert.
22
- * @param options Optional configuration (e.g., `comparator`, `toElementFn`).
23
- * @remarks Complexity — Time: O(n log n) when inserting n elements incrementally; Space: O(n).
24
- */
25
- constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
26
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MinPriorityQueue = void 0;
4
- const priority_queue_1 = require("./priority-queue");
5
- /**
6
- * Min-oriented priority queue (min-heap) built on {@link PriorityQueue}.
7
- * The queue removes the smallest element first under the provided comparator.
8
- * Provide a custom comparator if you store non-primitive objects.
9
- * @template E Element type stored in the queue.
10
- * @template R Extra record/metadata associated with each element.
11
- * @example
12
- */
13
- class MinPriorityQueue extends priority_queue_1.PriorityQueue {
14
- /**
15
- * Creates a min-priority queue.
16
- * @param elements Optional initial elements to insert.
17
- * @param options Optional configuration (e.g., `comparator`, `toElementFn`).
18
- * @remarks Complexity — Time: O(n log n) when inserting n elements incrementally; Space: O(n).
19
- */
20
- constructor(elements = [], options) {
21
- super(elements, options);
22
- }
23
- }
24
- exports.MinPriorityQueue = MinPriorityQueue;
@@ -1,15 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Kirk Qi
5
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
- * @license MIT License
7
- */
8
- import type { PriorityQueueOptions } from '../../types';
9
- import { Heap } from '../heap';
10
- /**
11
- * @example
12
- */
13
- export declare class PriorityQueue<E = any, R = any> extends Heap<E, R> {
14
- constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
15
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Kirk Qi
6
- * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
7
- * @license MIT License
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.PriorityQueue = void 0;
11
- const heap_1 = require("../heap");
12
- /**
13
- * @example
14
- */
15
- class PriorityQueue extends heap_1.Heap {
16
- constructor(elements = [], options) {
17
- super(elements, options);
18
- }
19
- }
20
- exports.PriorityQueue = PriorityQueue;
@@ -1,431 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Pablo Zeng
5
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import type { DequeOptions, ElementCallback, IterableElementBaseOptions, IterableWithSizeOrLength, LinearBaseOptions } from '../../types';
9
- import { LinearBase } from '../base/linear-base';
10
- /**
11
- * Deque implemented with circular buckets allowing O(1) amortized push/pop at both ends.
12
- * @remarks Time O(1), Space O(1)
13
- * @template E
14
- * @template R
15
- * 1. Operations at Both Ends: Supports adding and removing elements at both the front and back of the queue. This allows it to be used as a stack (last in, first out) and a queue (first in, first out).
16
- * 2. Efficient Random Access: Being based on an array, it offers fast random access capability, allowing constant time access to any element.
17
- * 3. Continuous Memory Allocation: Since it is based on an array, all elements are stored contiguously in memory, which can bring cache friendliness and efficient memory access.
18
- * 4. Efficiency: Adding and removing elements at both ends of a deque is usually very fast. However, when the dynamic array needs to expand, it may involve copying the entire array to a larger one, and this operation has a time complexity of O(n).
19
- * 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
20
- * @example
21
- * // prize roulette
22
- * class PrizeRoulette {
23
- * private deque: Deque<string>;
24
- *
25
- * constructor(prizes: string[]) {
26
- * // Initialize the deque with prizes
27
- * this.deque = new Deque<string>(prizes);
28
- * }
29
- *
30
- * // Rotate clockwise to the right (forward)
31
- * rotateClockwise(steps: number): void {
32
- * const n = this.deque.length;
33
- * if (n === 0) return;
34
- *
35
- * for (let i = 0; i < steps; i++) {
36
- * const last = this.deque.pop(); // Remove the last element
37
- * this.deque.unshift(last!); // Add it to the front
38
- * }
39
- * }
40
- *
41
- * // Rotate counterclockwise to the left (backward)
42
- * rotateCounterClockwise(steps: number): void {
43
- * const n = this.deque.length;
44
- * if (n === 0) return;
45
- *
46
- * for (let i = 0; i < steps; i++) {
47
- * const first = this.deque.shift(); // Remove the first element
48
- * this.deque.push(first!); // Add it to the back
49
- * }
50
- * }
51
- *
52
- * // Display the current prize at the head
53
- * display() {
54
- * return this.deque.first;
55
- * }
56
- * }
57
- *
58
- * // Example usage
59
- * const prizes = ['Car', 'Bike', 'Laptop', 'Phone', 'Watch', 'Headphones']; // Initialize the prize list
60
- * const roulette = new PrizeRoulette(prizes);
61
- *
62
- * // Display the initial state
63
- * console.log(roulette.display()); // 'Car' // Car
64
- *
65
- * // Rotate clockwise by 3 steps
66
- * roulette.rotateClockwise(3);
67
- * console.log(roulette.display()); // 'Phone' // Phone
68
- *
69
- * // Rotate counterclockwise by 2 steps
70
- * roulette.rotateCounterClockwise(2);
71
- * console.log(roulette.display()); // 'Headphones'
72
- * @example
73
- * // sliding window
74
- * // Maximum function of sliding window
75
- * function maxSlidingWindow(nums: number[], k: number): number[] {
76
- * const n = nums.length;
77
- * if (n * k === 0) return [];
78
- *
79
- * const deq = new Deque<number>();
80
- * const result: number[] = [];
81
- *
82
- * for (let i = 0; i < n; i++) {
83
- * // Delete indexes in the queue that are not within the window range
84
- * if (deq.length > 0 && deq.first! === i - k) {
85
- * deq.shift();
86
- * }
87
- *
88
- * // Remove all indices less than the current value from the tail of the queue
89
- * while (deq.length > 0 && nums[deq.last!] < nums[i]) {
90
- * deq.pop();
91
- * }
92
- *
93
- * // Add the current index to the end of the queue
94
- * deq.push(i);
95
- *
96
- * // Add the maximum value of the window to the results
97
- * if (i >= k - 1) {
98
- * result.push(nums[deq.first!]);
99
- * }
100
- * }
101
- *
102
- * return result;
103
- * }
104
- *
105
- * const nums = [1, 3, -1, -3, 5, 3, 6, 7];
106
- * const k = 3;
107
- * console.log(maxSlidingWindow(nums, k)); // [3, 3, 5, 5, 6, 7]
108
- */
109
- export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
110
- protected _equals: (a: E, b: E) => boolean;
111
- /**
112
- * Create a Deque and optionally bulk-insert elements.
113
- * @remarks Time O(N), Space O(N)
114
- * @param [elements] - Iterable (or iterable-like) of elements/records to insert.
115
- * @param [options] - Options such as bucketSize, toElementFn, and maxLen.
116
- * @returns New Deque instance.
117
- */
118
- constructor(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>);
119
- protected _bucketSize: number;
120
- /**
121
- * Get the current bucket size.
122
- * @remarks Time O(1), Space O(1)
123
- * @returns Bucket capacity per bucket.
124
- */
125
- get bucketSize(): number;
126
- protected _bucketFirst: number;
127
- /**
128
- * Get the index of the first bucket in use.
129
- * @remarks Time O(1), Space O(1)
130
- * @returns Zero-based bucket index.
131
- */
132
- get bucketFirst(): number;
133
- protected _firstInBucket: number;
134
- /**
135
- * Get the index inside the first bucket.
136
- * @remarks Time O(1), Space O(1)
137
- * @returns Zero-based index within the first bucket.
138
- */
139
- get firstInBucket(): number;
140
- protected _bucketLast: number;
141
- /**
142
- * Get the index of the last bucket in use.
143
- * @remarks Time O(1), Space O(1)
144
- * @returns Zero-based bucket index.
145
- */
146
- get bucketLast(): number;
147
- protected _lastInBucket: number;
148
- /**
149
- * Get the index inside the last bucket.
150
- * @remarks Time O(1), Space O(1)
151
- * @returns Zero-based index within the last bucket.
152
- */
153
- get lastInBucket(): number;
154
- protected _bucketCount: number;
155
- /**
156
- * Get the number of buckets allocated.
157
- * @remarks Time O(1), Space O(1)
158
- * @returns Bucket count.
159
- */
160
- get bucketCount(): number;
161
- protected _buckets: E[][];
162
- /**
163
- * Get the internal buckets array.
164
- * @remarks Time O(1), Space O(1)
165
- * @returns Array of buckets storing values.
166
- */
167
- get buckets(): E[][];
168
- protected _length: number;
169
- /**
170
- * Get the number of elements in the deque.
171
- * @remarks Time O(1), Space O(1)
172
- * @returns Current length.
173
- */
174
- get length(): number;
175
- /**
176
- * Get the first element without removing it.
177
- * @remarks Time O(1), Space O(1)
178
- * @returns First element or undefined.
179
- */
180
- get first(): E | undefined;
181
- /**
182
- * Get the last element without removing it.
183
- * @remarks Time O(1), Space O(1)
184
- * @returns Last element or undefined.
185
- */
186
- get last(): E | undefined;
187
- /**
188
- * Create a Deque from an array of elements.
189
- * @remarks Time O(N), Space O(N)
190
- * @template E
191
- * @template R
192
- * @param this - Constructor (subclass) to instantiate.
193
- * @param data - Array of elements to insert in order.
194
- * @param [options] - Options forwarded to the constructor.
195
- * @returns A new Deque populated from the array.
196
- */
197
- static fromArray<E, R = any>(this: new (elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>, options?: DequeOptions<E, R>) => any, data: E[], options?: DequeOptions<E, R>): any;
198
- /**
199
- * Append one element at the back.
200
- * @remarks Time O(1) amortized, Space O(1)
201
- * @param element - Element to append.
202
- * @returns True when appended.
203
- */
204
- push(element: E): boolean;
205
- /**
206
- * Remove and return the last element.
207
- * @remarks Time O(1), Space O(1)
208
- * @returns Removed element or undefined.
209
- */
210
- pop(): E | undefined;
211
- /**
212
- * Remove and return the first element.
213
- * @remarks Time O(1) amortized, Space O(1)
214
- * @returns Removed element or undefined.
215
- */
216
- shift(): E | undefined;
217
- /**
218
- * Prepend one element at the front.
219
- * @remarks Time O(1) amortized, Space O(1)
220
- * @param element - Element to prepend.
221
- * @returns True when prepended.
222
- */
223
- unshift(element: E): boolean;
224
- /**
225
- * Append a sequence of elements.
226
- * @remarks Time O(N), Space O(1)
227
- * @param elements - Iterable (or iterable-like) of elements/records.
228
- * @returns Array of per-element success flags.
229
- */
230
- pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
231
- /**
232
- * Prepend a sequence of elements.
233
- * @remarks Time O(N), Space O(1)
234
- * @param [elements] - Iterable (or iterable-like) of elements/records.
235
- * @returns Array of per-element success flags.
236
- */
237
- unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
238
- /**
239
- * Check whether the deque is empty.
240
- * @remarks Time O(1), Space O(1)
241
- * @returns True if length is 0.
242
- */
243
- isEmpty(): boolean;
244
- /**
245
- * Remove all elements and reset structure.
246
- * @remarks Time O(1), Space O(1)
247
- * @returns void
248
- */
249
- clear(): void;
250
- /**
251
- * Get the element at a given position.
252
- * @remarks Time O(1), Space O(1)
253
- * @param pos - Zero-based position from the front.
254
- * @returns Element or undefined.
255
- */
256
- at(pos: number): E | undefined;
257
- /**
258
- * Replace the element at a given position.
259
- * @remarks Time O(1), Space O(1)
260
- * @param pos - Zero-based position from the front.
261
- * @param element - New element value.
262
- * @returns True if updated.
263
- */
264
- setAt(pos: number, element: E): boolean;
265
- /**
266
- * Insert repeated copies of an element at a position.
267
- * @remarks Time O(N), Space O(1)
268
- * @param pos - Zero-based position from the front.
269
- * @param element - Element to insert.
270
- * @param [num] - Number of times to insert (default 1).
271
- * @returns True if inserted.
272
- */
273
- addAt(pos: number, element: E, num?: number): boolean;
274
- /**
275
- * Cut the deque to keep items up to index; optionally mutate in-place.
276
- * @remarks Time O(N), Space O(1)
277
- * @param pos - Last index to keep.
278
- * @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
279
- * @returns This deque if in-place; otherwise a new deque of the prefix.
280
- */
281
- cut(pos: number, isCutSelf?: boolean): Deque<E>;
282
- /**
283
- * Remove and/or insert elements at a position (array-like behavior).
284
- * @remarks Time O(N + M), Space O(M)
285
- * @param start - Start index (clamped to [0, length]).
286
- * @param [deleteCount] - Number of elements to remove (default: length - start).
287
- * @param [items] - Elements to insert after `start`.
288
- * @returns A new deque containing the removed elements (typed as `this`).
289
- */
290
- splice(start: number, deleteCount?: number, ...items: E[]): this;
291
- /**
292
- * Cut the deque to keep items from index onward; optionally mutate in-place.
293
- * @remarks Time O(N), Space O(1)
294
- * @param pos - First index to keep.
295
- * @param [isCutSelf] - When true, mutate this deque; otherwise return a new deque.
296
- * @returns This deque if in-place; otherwise a new deque of the suffix.
297
- */
298
- cutRest(pos: number, isCutSelf?: boolean): Deque<E>;
299
- /**
300
- * Delete the element at a given position.
301
- * @remarks Time O(N), Space O(1)
302
- * @param pos - Zero-based position from the front.
303
- * @returns Removed element or undefined.
304
- */
305
- deleteAt(pos: number): E | undefined;
306
- /**
307
- * Delete the first occurrence of a value.
308
- * @remarks Time O(N), Space O(1)
309
- * @param element - Element to remove (using the configured equality).
310
- * @returns True if an element was removed.
311
- */
312
- delete(element: E): boolean;
313
- /**
314
- * Delete the first element matching a predicate.
315
- * @remarks Time O(N), Space O(1)
316
- * @param predicate - Function (value, index, deque) → boolean.
317
- * @returns True if a match was removed.
318
- */
319
- deleteWhere(predicate: (value: E, index: number, deque: this) => boolean): boolean;
320
- /**
321
- * Set the equality comparator used by delete operations.
322
- * @remarks Time O(1), Space O(1)
323
- * @param equals - Equality predicate (a, b) → boolean.
324
- * @returns This deque.
325
- */
326
- setEquality(equals: (a: E, b: E) => boolean): this;
327
- /**
328
- * Reverse the deque by reversing buckets and pointers.
329
- * @remarks Time O(N), Space O(N)
330
- * @returns This deque.
331
- */
332
- reverse(): this;
333
- /**
334
- * Deduplicate consecutive equal elements in-place.
335
- * @remarks Time O(N), Space O(1)
336
- * @returns This deque.
337
- */
338
- unique(): this;
339
- /**
340
- * Trim unused buckets to fit exactly the active range.
341
- * @remarks Time O(N), Space O(1)
342
- * @returns void
343
- */
344
- shrinkToFit(): void;
345
- /**
346
- * Deep clone this deque, preserving options.
347
- * @remarks Time O(N), Space O(N)
348
- * @returns A new deque with the same content and options.
349
- */
350
- clone(): this;
351
- /**
352
- * Filter elements into a new deque of the same class.
353
- * @remarks Time O(N), Space O(N)
354
- * @param predicate - Predicate (value, index, deque) → boolean to keep element.
355
- * @param [thisArg] - Value for `this` inside the predicate.
356
- * @returns A new deque with kept elements.
357
- */
358
- filter(predicate: ElementCallback<E, R, boolean>, thisArg?: any): this;
359
- /**
360
- * Map elements into a new deque of the same element type.
361
- * @remarks Time O(N), Space O(N)
362
- * @param callback - Mapping function (value, index, deque) → newValue.
363
- * @param [thisArg] - Value for `this` inside the callback.
364
- * @returns A new deque with mapped values.
365
- */
366
- mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
367
- /**
368
- * Map elements into a new deque (possibly different element type).
369
- * @remarks Time O(N), Space O(N)
370
- * @template EM
371
- * @template RM
372
- * @param callback - Mapping function (value, index, deque) → newElement.
373
- * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
374
- * @param [thisArg] - Value for `this` inside the callback.
375
- * @returns A new Deque with mapped elements.
376
- */
377
- map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: IterableElementBaseOptions<EM, RM>, thisArg?: any): Deque<EM, RM>;
378
- /**
379
- * (Protected) Set the internal bucket size.
380
- * @remarks Time O(1), Space O(1)
381
- * @param size - Bucket capacity to assign.
382
- * @returns void
383
- */
384
- protected _setBucketSize(size: number): void;
385
- /**
386
- * (Protected) Iterate elements from front to back.
387
- * @remarks Time O(N), Space O(1)
388
- * @returns Iterator of elements.
389
- */
390
- protected _getIterator(): IterableIterator<E>;
391
- /**
392
- * (Protected) Reallocate buckets to make room near the ends.
393
- * @remarks Time O(N), Space O(N)
394
- * @param [needBucketNum] - How many extra buckets to add; defaults to half of current.
395
- * @returns void
396
- */
397
- protected _reallocate(needBucketNum?: number): void;
398
- /**
399
- * (Protected) Translate a logical position to bucket/offset.
400
- * @remarks Time O(1), Space O(1)
401
- * @param pos - Zero-based position.
402
- * @returns An object containing bucketIndex and indexInBucket.
403
- */
404
- protected _getBucketAndPosition(pos: number): {
405
- bucketIndex: number;
406
- indexInBucket: number;
407
- };
408
- /**
409
- * (Protected) Create an empty instance of the same concrete class.
410
- * @remarks Time O(1), Space O(1)
411
- * @param [options] - Options forwarded to the constructor.
412
- * @returns An empty like-kind deque instance.
413
- */
414
- protected _createInstance(options?: LinearBaseOptions<E, R>): this;
415
- /**
416
- * (Protected) Create a like-kind deque seeded by elements.
417
- * @remarks Time O(N), Space O(N)
418
- * @template T
419
- * @template RR
420
- * @param [elements] - Iterable used to seed the new deque.
421
- * @param [options] - Options forwarded to the constructor.
422
- * @returns A like-kind Deque instance.
423
- */
424
- protected _createLike<T = E, RR = R>(elements?: IterableWithSizeOrLength<T> | IterableWithSizeOrLength<RR>, options?: DequeOptions<T, RR>): any;
425
- /**
426
- * (Protected) Iterate elements from back to front.
427
- * @remarks Time O(N), Space O(1)
428
- * @returns Iterator of elements.
429
- */
430
- protected _getReverseIterator(): IterableIterator<E>;
431
- }