bst-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 +3413 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +3406 -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 +13 -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/bst-typed.js +3410 -0
  87. package/dist/umd/bst-typed.js.map +1 -0
  88. package/dist/umd/bst-typed.min.js +13 -0
  89. package/dist/umd/bst-typed.min.js.map +1 -0
  90. package/package.json +24 -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 -14
  192. package/dist/index.js +0 -30
  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,384 +0,0 @@
1
- "use strict";
2
- /**
3
- * data-structure-typed
4
- *
5
- * @author Pablo Zeng
6
- * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
7
- * @license MIT License
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.TreeMultiMap = exports.TreeMultiMapNode = void 0;
11
- const red_black_tree_1 = require("./red-black-tree");
12
- /**
13
- * Node used by TreeMultiMap; stores the key with a bucket of values (array).
14
- * @remarks Time O(1), Space O(1)
15
- * @template K
16
- * @template V
17
- */
18
- class TreeMultiMapNode extends red_black_tree_1.RedBlackTreeNode {
19
- /**
20
- * Create a TreeMultiMap node with an optional value bucket.
21
- * @remarks Time O(1), Space O(1)
22
- * @param key - Key of the node.
23
- * @param [value] - Initial array of values.
24
- * @returns New TreeMultiMapNode instance.
25
- */
26
- constructor(key, value) {
27
- super(key, value);
28
- this.parent = undefined;
29
- this._left = undefined;
30
- this._right = undefined;
31
- }
32
- /**
33
- * Get the left child pointer.
34
- * @remarks Time O(1), Space O(1)
35
- * @returns Left child node, or null/undefined.
36
- */
37
- get left() {
38
- return this._left;
39
- }
40
- /**
41
- * Set the left child and update its parent pointer.
42
- * @remarks Time O(1), Space O(1)
43
- * @param v - New left child node, or null/undefined.
44
- * @returns void
45
- */
46
- set left(v) {
47
- if (v) {
48
- v.parent = this;
49
- }
50
- this._left = v;
51
- }
52
- /**
53
- * Get the right child pointer.
54
- * @remarks Time O(1), Space O(1)
55
- * @returns Right child node, or null/undefined.
56
- */
57
- get right() {
58
- return this._right;
59
- }
60
- /**
61
- * Set the right child and update its parent pointer.
62
- * @remarks Time O(1), Space O(1)
63
- * @param v - New right child node, or null/undefined.
64
- * @returns void
65
- */
66
- set right(v) {
67
- if (v) {
68
- v.parent = this;
69
- }
70
- this._right = v;
71
- }
72
- }
73
- exports.TreeMultiMapNode = TreeMultiMapNode;
74
- /**
75
- * Red-Black Tree–based multimap (key → array of values). Preserves O(log N) updates and supports map-like mode.
76
- * @remarks Time O(1), Space O(1)
77
- * @template K
78
- * @template V
79
- * @template R
80
- * @example
81
- * // players ranked by score with their equipment
82
- * type Equipment = {
83
- * name: string; // Equipment name
84
- * quality: 'legendary' | 'epic' | 'rare' | 'common';
85
- * level: number;
86
- * };
87
- *
88
- * type Player = {
89
- * name: string;
90
- * score: number;
91
- * equipments: Equipment[];
92
- * };
93
- *
94
- * // Mock player data with their scores and equipment
95
- * const players: Player[] = [
96
- * {
97
- * name: 'DragonSlayer',
98
- * score: 8750,
99
- * equipments: [
100
- * { name: 'AWM', quality: 'legendary', level: 85 },
101
- * { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
102
- * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
103
- * { name: 'Compensator', quality: 'epic', level: 78 },
104
- * { name: 'Vertical Grip', quality: 'rare', level: 72 }
105
- * ]
106
- * },
107
- * {
108
- * name: 'ShadowNinja',
109
- * score: 7200,
110
- * equipments: [
111
- * { name: 'M416', quality: 'epic', level: 75 },
112
- * { name: 'Ghillie Suit', quality: 'rare', level: 70 },
113
- * { name: 'Red Dot Sight', quality: 'common', level: 65 },
114
- * { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
115
- * ]
116
- * },
117
- * {
118
- * name: 'RuneMaster',
119
- * score: 9100,
120
- * equipments: [
121
- * { name: 'KAR98K', quality: 'legendary', level: 90 },
122
- * { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
123
- * { name: 'Holographic Sight', quality: 'epic', level: 82 },
124
- * { name: 'Suppressor', quality: 'legendary', level: 88 },
125
- * { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
126
- * ]
127
- * },
128
- * {
129
- * name: 'BattleKing',
130
- * score: 8500,
131
- * equipments: [
132
- * { name: 'AUG', quality: 'epic', level: 82 },
133
- * { name: 'Red Dot Sight', quality: 'rare', level: 75 },
134
- * { name: 'Extended Mag', quality: 'common', level: 70 },
135
- * { name: 'Tactical Stock', quality: 'rare', level: 76 }
136
- * ]
137
- * },
138
- * {
139
- * name: 'SniperElite',
140
- * score: 7800,
141
- * equipments: [
142
- * { name: 'M24', quality: 'legendary', level: 88 },
143
- * { name: 'Compensator', quality: 'epic', level: 80 },
144
- * { name: 'Scope 8x', quality: 'legendary', level: 85 },
145
- * { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
146
- * ]
147
- * },
148
- * {
149
- * name: 'RushMaster',
150
- * score: 7500,
151
- * equipments: [
152
- * { name: 'Vector', quality: 'rare', level: 72 },
153
- * { name: 'Level 2 Helmet', quality: 'common', level: 65 },
154
- * { name: 'Quickdraw Mag', quality: 'common', level: 60 },
155
- * { name: 'Laser Sight', quality: 'rare', level: 68 }
156
- * ]
157
- * },
158
- * {
159
- * name: 'GhostWarrior',
160
- * score: 8200,
161
- * equipments: [
162
- * { name: 'SCAR-L', quality: 'epic', level: 78 },
163
- * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
164
- * { name: 'Holographic Sight', quality: 'epic', level: 75 },
165
- * { name: 'Suppressor', quality: 'rare', level: 72 },
166
- * { name: 'Vertical Grip', quality: 'common', level: 65 }
167
- * ]
168
- * },
169
- * {
170
- * name: 'DeathDealer',
171
- * score: 7300,
172
- * equipments: [
173
- * { name: 'SKS', quality: 'epic', level: 76 },
174
- * { name: 'Holographic Sight', quality: 'rare', level: 68 },
175
- * { name: 'Extended Mag', quality: 'common', level: 65 }
176
- * ]
177
- * },
178
- * {
179
- * name: 'StormRider',
180
- * score: 8900,
181
- * equipments: [
182
- * { name: 'MK14', quality: 'legendary', level: 92 },
183
- * { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
184
- * { name: 'Scope 8x', quality: 'epic', level: 80 },
185
- * { name: 'Suppressor', quality: 'legendary', level: 88 },
186
- * { name: 'Tactical Stock', quality: 'rare', level: 75 }
187
- * ]
188
- * },
189
- * {
190
- * name: 'CombatLegend',
191
- * score: 7600,
192
- * equipments: [
193
- * { name: 'UMP45', quality: 'rare', level: 74 },
194
- * { name: 'Level 2 Vest', quality: 'common', level: 67 },
195
- * { name: 'Red Dot Sight', quality: 'common', level: 62 },
196
- * { name: 'Extended Mag', quality: 'rare', level: 70 }
197
- * ]
198
- * }
199
- * ];
200
- *
201
- * // Create a TreeMultiMap for player rankings
202
- * const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
203
- * toEntryFn: ({ score, equipments }) => [score, equipments],
204
- * isMapMode: false
205
- * });
206
- *
207
- * const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
208
- * console.log(topPlayersEquipments); // [
209
- * // [
210
- * // {
211
- * // name: 'MK14',
212
- * // quality: 'legendary',
213
- * // level: 92
214
- * // },
215
- * // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
216
- * // {
217
- * // name: 'Scope 8x',
218
- * // quality: 'epic',
219
- * // level: 80
220
- * // },
221
- * // { name: 'Suppressor', quality: 'legendary', level: 88 },
222
- * // {
223
- * // name: 'Tactical Stock',
224
- * // quality: 'rare',
225
- * // level: 75
226
- * // }
227
- * // ],
228
- * // [
229
- * // { name: 'KAR98K', quality: 'legendary', level: 90 },
230
- * // {
231
- * // name: 'Level 3 Vest',
232
- * // quality: 'legendary',
233
- * // level: 85
234
- * // },
235
- * // { name: 'Holographic Sight', quality: 'epic', level: 82 },
236
- * // {
237
- * // name: 'Suppressor',
238
- * // quality: 'legendary',
239
- * // level: 88
240
- * // },
241
- * // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
242
- * // ]
243
- * // ]
244
- */
245
- class TreeMultiMap extends red_black_tree_1.RedBlackTree {
246
- /**
247
- * Create a TreeMultiMap and optionally bulk-insert items.
248
- * @remarks Time O(N log N), Space O(N)
249
- * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
250
- * @param [options] - Options for TreeMultiMap (comparator, reverse, map mode).
251
- * @returns New TreeMultiMap instance.
252
- */
253
- constructor(keysNodesEntriesOrRaws = [], options) {
254
- super([], Object.assign({}, options));
255
- if (keysNodesEntriesOrRaws) {
256
- this.addMany(keysNodesEntriesOrRaws);
257
- }
258
- }
259
- _createNode(key, value = []) {
260
- return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
261
- }
262
- /**
263
- * Insert a value or a list of values into the multimap. If the key exists, values are appended.
264
- * @remarks Time O(log N + M), Space O(1)
265
- * @param keyNodeOrEntry - Key, node, or [key, values] entry.
266
- * @param [value] - Single value to add when a bare key is provided.
267
- * @returns True if inserted or appended; false if ignored.
268
- */
269
- add(keyNodeOrEntry, value) {
270
- if (this.isRealNode(keyNodeOrEntry))
271
- return super.add(keyNodeOrEntry);
272
- const _commonAdd = (key, values) => {
273
- if (key === undefined || key === null)
274
- return false;
275
- const _addToValues = () => {
276
- const existingValues = this.get(key);
277
- if (existingValues !== undefined && values !== undefined) {
278
- for (const value of values)
279
- existingValues.push(value);
280
- return true;
281
- }
282
- return false;
283
- };
284
- const _addByNode = () => {
285
- const existingNode = this.getNode(key);
286
- if (this.isRealNode(existingNode)) {
287
- const existingValues = this.get(existingNode);
288
- if (existingValues === undefined) {
289
- super.add(key, values);
290
- return true;
291
- }
292
- if (values !== undefined) {
293
- for (const value of values)
294
- existingValues.push(value);
295
- return true;
296
- }
297
- else {
298
- return false;
299
- }
300
- }
301
- else {
302
- return super.add(key, values);
303
- }
304
- };
305
- if (this._isMapMode) {
306
- return _addByNode() || _addToValues();
307
- }
308
- return _addToValues() || _addByNode();
309
- };
310
- if (this.isEntry(keyNodeOrEntry)) {
311
- const [key, values] = keyNodeOrEntry;
312
- return _commonAdd(key, value !== undefined ? [value] : values);
313
- }
314
- return _commonAdd(keyNodeOrEntry, value !== undefined ? [value] : undefined);
315
- }
316
- /**
317
- * Delete a single value from the bucket at a given key. Removes the key if the bucket becomes empty.
318
- * @remarks Time O(log N), Space O(1)
319
- * @param keyNodeOrEntry - Key, node, or [key, values] entry to locate the bucket.
320
- * @param value - Value to remove from the bucket.
321
- * @returns True if the value was removed; false if not found.
322
- */
323
- deleteValue(keyNodeOrEntry, value) {
324
- const values = this.get(keyNodeOrEntry);
325
- if (Array.isArray(values)) {
326
- const index = values.indexOf(value);
327
- if (index === -1)
328
- return false;
329
- values.splice(index, 1);
330
- if (values.length === 0)
331
- this.delete(keyNodeOrEntry);
332
- return true;
333
- }
334
- return false;
335
- }
336
- /**
337
- * Create a new tree by mapping each [key, values] bucket.
338
- * @remarks Time O(N log N), Space O(N)
339
- * @template MK
340
- * @template MV
341
- * @template MR
342
- * @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
343
- * @param [options] - Options for the output tree.
344
- * @param [thisArg] - Value for `this` inside the callback.
345
- * @returns A new RedBlackTree (or TreeMultiMap when mapping to array values; see overloads).
346
- */
347
- map(callback, options, thisArg) {
348
- const out = this._createLike([], options);
349
- let i = 0;
350
- for (const [k, v] of this)
351
- out.add(callback.call(thisArg, k, v, i++, this));
352
- return out;
353
- }
354
- /**
355
- * (Protected) Create an empty instance of the same concrete class.
356
- * @remarks Time O(1), Space O(1)
357
- * @template TK
358
- * @template TV
359
- * @template TR
360
- * @param [options] - Optional constructor options for the like-kind instance.
361
- * @returns An empty like-kind instance.
362
- */
363
- _createInstance(options) {
364
- var _a, _b;
365
- const Ctor = this.constructor;
366
- return new Ctor([], Object.assign(Object.assign({}, ((_b = (_a = this._snapshotOptions) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {})), (options !== null && options !== void 0 ? options : {})));
367
- }
368
- /**
369
- * (Protected) Create a like-kind instance and seed it from an iterable.
370
- * @remarks Time O(N log N), Space O(N)
371
- * @template TK
372
- * @template TV
373
- * @template TR
374
- * @param iter - Iterable used to seed the new tree.
375
- * @param [options] - Options merged with the current snapshot.
376
- * @returns A like-kind RedBlackTree built from the iterable.
377
- */
378
- _createLike(iter = [], options) {
379
- var _a, _b;
380
- const Ctor = this.constructor;
381
- return new Ctor(iter, Object.assign(Object.assign({}, ((_b = (_a = this._snapshotOptions) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {})), (options !== null && options !== void 0 ? options : {})));
382
- }
383
- }
384
- exports.TreeMultiMap = TreeMultiMap;