data-structure-typed 1.54.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/LICENSE +2 -2
  3. package/README.md +14 -1
  4. package/README_zh-CN.md +1 -1
  5. package/benchmark/report.html +28 -1
  6. package/benchmark/report.json +327 -18
  7. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +14 -40
  8. package/dist/cjs/data-structures/base/iterable-element-base.js +14 -11
  9. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  10. package/dist/cjs/data-structures/base/linear-base.d.ts +277 -0
  11. package/dist/cjs/data-structures/base/linear-base.js +553 -0
  12. package/dist/cjs/data-structures/base/linear-base.js.map +1 -0
  13. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +8 -7
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +89 -21
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.js +76 -8
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +173 -225
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.js +244 -149
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  25. package/dist/cjs/data-structures/binary-tree/bst.d.ts +62 -56
  26. package/dist/cjs/data-structures/binary-tree/bst.js +89 -133
  27. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  28. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +7 -13
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  31. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +19 -19
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.js +12 -12
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +211 -41
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  37. package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
  38. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/heap.d.ts +3 -11
  40. package/dist/cjs/data-structures/heap/heap.js +0 -10
  41. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -2
  43. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  44. package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -2
  45. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  46. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +131 -146
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  49. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +217 -169
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  52. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  54. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  55. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -2
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.d.ts +130 -91
  59. package/dist/cjs/data-structures/queue/deque.js +269 -169
  60. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  61. package/dist/cjs/data-structures/queue/queue.d.ts +84 -40
  62. package/dist/cjs/data-structures/queue/queue.js +134 -50
  63. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  64. package/dist/cjs/data-structures/stack/stack.d.ts +3 -11
  65. package/dist/cjs/data-structures/stack/stack.js +0 -10
  66. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  67. package/dist/cjs/data-structures/trie/trie.d.ts +4 -3
  68. package/dist/cjs/data-structures/trie/trie.js +3 -0
  69. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  70. package/dist/cjs/types/data-structures/base/base.d.ts +9 -4
  71. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  73. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  74. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  75. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  76. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  77. package/dist/cjs/types/data-structures/queue/deque.d.ts +2 -3
  78. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -2
  79. package/dist/cjs/utils/utils.d.ts +2 -2
  80. package/dist/esm/data-structures/base/iterable-element-base.d.ts +14 -40
  81. package/dist/esm/data-structures/base/iterable-element-base.js +14 -11
  82. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  83. package/dist/esm/data-structures/base/linear-base.d.ts +277 -0
  84. package/dist/esm/data-structures/base/linear-base.js +549 -0
  85. package/dist/esm/data-structures/base/linear-base.js.map +1 -0
  86. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  87. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +9 -8
  88. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  89. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  90. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +52 -38
  91. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  92. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +89 -21
  93. package/dist/esm/data-structures/binary-tree/avl-tree.js +77 -9
  94. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  95. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +173 -225
  96. package/dist/esm/data-structures/binary-tree/binary-tree.js +248 -153
  97. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  98. package/dist/esm/data-structures/binary-tree/bst.d.ts +62 -56
  99. package/dist/esm/data-structures/binary-tree/bst.js +90 -132
  100. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  101. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  102. package/dist/esm/data-structures/binary-tree/red-black-tree.js +8 -14
  103. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  104. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +19 -19
  105. package/dist/esm/data-structures/binary-tree/tree-counter.js +13 -13
  106. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  107. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  108. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +212 -41
  109. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  110. package/dist/esm/data-structures/graph/abstract-graph.js +2 -2
  111. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  112. package/dist/esm/data-structures/heap/heap.d.ts +3 -11
  113. package/dist/esm/data-structures/heap/heap.js +0 -10
  114. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  115. package/dist/esm/data-structures/heap/max-heap.d.ts +2 -2
  116. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  117. package/dist/esm/data-structures/heap/min-heap.d.ts +2 -2
  118. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  119. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  120. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +132 -148
  121. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  122. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  123. package/dist/esm/data-structures/linked-list/singly-linked-list.js +217 -170
  124. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  125. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  126. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  127. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  128. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  129. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -2
  130. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  131. package/dist/esm/data-structures/queue/deque.d.ts +130 -91
  132. package/dist/esm/data-structures/queue/deque.js +269 -169
  133. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  134. package/dist/esm/data-structures/queue/queue.d.ts +84 -40
  135. package/dist/esm/data-structures/queue/queue.js +135 -51
  136. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  137. package/dist/esm/data-structures/stack/stack.d.ts +3 -11
  138. package/dist/esm/data-structures/stack/stack.js +0 -10
  139. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  140. package/dist/esm/data-structures/trie/trie.d.ts +4 -3
  141. package/dist/esm/data-structures/trie/trie.js +3 -0
  142. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  143. package/dist/esm/types/data-structures/base/base.d.ts +9 -4
  144. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  145. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  146. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +1 -1
  147. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  148. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  149. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  150. package/dist/esm/types/data-structures/queue/deque.d.ts +2 -3
  151. package/dist/esm/types/data-structures/queue/queue.d.ts +2 -2
  152. package/dist/esm/utils/utils.d.ts +2 -2
  153. package/dist/umd/data-structure-typed.js +1548 -920
  154. package/dist/umd/data-structure-typed.min.js +5 -12
  155. package/dist/umd/data-structure-typed.min.js.map +1 -1
  156. package/package.json +7 -7
  157. package/src/data-structures/base/iterable-element-base.ts +29 -20
  158. package/src/data-structures/base/linear-base.ts +649 -0
  159. package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
  160. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
  161. package/src/data-structures/binary-tree/avl-tree.ts +99 -29
  162. package/src/data-structures/binary-tree/binary-tree.ts +474 -257
  163. package/src/data-structures/binary-tree/bst.ts +150 -152
  164. package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
  165. package/src/data-structures/binary-tree/tree-counter.ts +33 -27
  166. package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
  167. package/src/data-structures/graph/abstract-graph.ts +2 -2
  168. package/src/data-structures/heap/heap.ts +3 -14
  169. package/src/data-structures/heap/max-heap.ts +2 -2
  170. package/src/data-structures/heap/min-heap.ts +2 -2
  171. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  172. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  173. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  174. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  175. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  176. package/src/data-structures/queue/deque.ts +286 -183
  177. package/src/data-structures/queue/queue.ts +149 -63
  178. package/src/data-structures/stack/stack.ts +3 -18
  179. package/src/data-structures/trie/trie.ts +7 -3
  180. package/src/types/data-structures/base/base.ts +17 -8
  181. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  182. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
  183. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  184. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  185. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  186. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  187. package/src/types/data-structures/queue/deque.ts +2 -3
  188. package/src/types/data-structures/queue/queue.ts +2 -2
  189. package/src/utils/utils.ts +2 -2
  190. package/test/integration/all-in-one.test.ts +1 -1
  191. package/test/integration/avl-tree.test.ts +1 -1
  192. package/test/integration/bst.test.ts +2 -2
  193. package/test/integration/compile.mjs +21 -21
  194. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +71 -0
  195. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +81 -0
  196. package/test/performance/{reportor.js → reportor.mjs} +264 -8
  197. package/test/performance/reportor.ts +1 -1
  198. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +7 -7
  199. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +172 -5
  200. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +72 -4
  201. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +132 -82
  202. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
  203. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +5 -13
  204. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +4 -4
  205. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +168 -10
  206. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +135 -27
  207. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +111 -11
  208. package/test/unit/data-structures/queue/deque.test.ts +241 -60
  209. package/test/unit/data-structures/queue/queue.test.ts +118 -19
  210. package/test/unit/unrestricted-interconversion.test.ts +1 -1
  211. package/test/utils/json2html.ts +0 -154
  212. package/test/performance/data-structures/binary-tree/avl-tree.test.js +0 -45
  213. /package/test/performance/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +0 -0
@@ -5,10 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BTNRep, OptNodeOrNull, TreeMultiMapOptions } from '../../types';
8
+ import type { TreeMultiMapOptions } from '../../types';
9
9
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
12
+ parent?: TreeMultiMapNode<K, V>;
12
13
  /**
13
14
  * This TypeScript constructor initializes an object with a key of type K and an array of values of
14
15
  * type V.
@@ -18,23 +19,180 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
18
19
  * @param {V[]} value - The `value` parameter in the constructor represents an array of values of
19
20
  * type `V`.
20
21
  */
21
- constructor(key: K, value: V[]);
22
- parent?: TreeMultiMapNode<K, V>;
23
- _left?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
24
- get left(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
25
- set left(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
26
- _right?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
27
- get right(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
28
- set right(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
22
+ constructor(key: K, value?: V[]);
23
+ _left?: TreeMultiMapNode<K, V> | null | undefined;
24
+ get left(): TreeMultiMapNode<K, V> | null | undefined;
25
+ set left(v: TreeMultiMapNode<K, V> | null | undefined);
26
+ _right?: TreeMultiMapNode<K, V> | null | undefined;
27
+ get right(): TreeMultiMapNode<K, V> | null | undefined;
28
+ set right(v: TreeMultiMapNode<K, V> | null | undefined);
29
29
  }
30
30
  /**
31
31
  *
32
32
  * @example
33
- * // Find elements in a range
34
- * const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
35
- * console.log(tmm.search(new Range(5, 10))); // [5, 10, 7]
36
- * console.log(tmm.search(new Range(4, 12))); // [5, 10, 12, 7]
37
- * console.log(tmm.search(new Range(15, 20))); // [15, 18]
33
+ * // players ranked by score with their equipment
34
+ * type Equipment = {
35
+ * name: string; // Equipment name
36
+ * quality: 'legendary' | 'epic' | 'rare' | 'common';
37
+ * level: number;
38
+ * };
39
+ *
40
+ * type Player = {
41
+ * name: string;
42
+ * score: number;
43
+ * equipments: Equipment[];
44
+ * };
45
+ *
46
+ * // Mock player data with their scores and equipment
47
+ * const players: Player[] = [
48
+ * {
49
+ * name: 'DragonSlayer',
50
+ * score: 8750,
51
+ * equipments: [
52
+ * { name: 'AWM', quality: 'legendary', level: 85 },
53
+ * { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
54
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
55
+ * { name: 'Compensator', quality: 'epic', level: 78 },
56
+ * { name: 'Vertical Grip', quality: 'rare', level: 72 }
57
+ * ]
58
+ * },
59
+ * {
60
+ * name: 'ShadowNinja',
61
+ * score: 7200,
62
+ * equipments: [
63
+ * { name: 'M416', quality: 'epic', level: 75 },
64
+ * { name: 'Ghillie Suit', quality: 'rare', level: 70 },
65
+ * { name: 'Red Dot Sight', quality: 'common', level: 65 },
66
+ * { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
67
+ * ]
68
+ * },
69
+ * {
70
+ * name: 'RuneMaster',
71
+ * score: 9100,
72
+ * equipments: [
73
+ * { name: 'KAR98K', quality: 'legendary', level: 90 },
74
+ * { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
75
+ * { name: 'Holographic Sight', quality: 'epic', level: 82 },
76
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
77
+ * { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
78
+ * ]
79
+ * },
80
+ * {
81
+ * name: 'BattleKing',
82
+ * score: 8500,
83
+ * equipments: [
84
+ * { name: 'AUG', quality: 'epic', level: 82 },
85
+ * { name: 'Red Dot Sight', quality: 'rare', level: 75 },
86
+ * { name: 'Extended Mag', quality: 'common', level: 70 },
87
+ * { name: 'Tactical Stock', quality: 'rare', level: 76 }
88
+ * ]
89
+ * },
90
+ * {
91
+ * name: 'SniperElite',
92
+ * score: 7800,
93
+ * equipments: [
94
+ * { name: 'M24', quality: 'legendary', level: 88 },
95
+ * { name: 'Compensator', quality: 'epic', level: 80 },
96
+ * { name: 'Scope 8x', quality: 'legendary', level: 85 },
97
+ * { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
98
+ * ]
99
+ * },
100
+ * {
101
+ * name: 'RushMaster',
102
+ * score: 7500,
103
+ * equipments: [
104
+ * { name: 'Vector', quality: 'rare', level: 72 },
105
+ * { name: 'Level 2 Helmet', quality: 'common', level: 65 },
106
+ * { name: 'Quickdraw Mag', quality: 'common', level: 60 },
107
+ * { name: 'Laser Sight', quality: 'rare', level: 68 }
108
+ * ]
109
+ * },
110
+ * {
111
+ * name: 'GhostWarrior',
112
+ * score: 8200,
113
+ * equipments: [
114
+ * { name: 'SCAR-L', quality: 'epic', level: 78 },
115
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
116
+ * { name: 'Holographic Sight', quality: 'epic', level: 75 },
117
+ * { name: 'Suppressor', quality: 'rare', level: 72 },
118
+ * { name: 'Vertical Grip', quality: 'common', level: 65 }
119
+ * ]
120
+ * },
121
+ * {
122
+ * name: 'DeathDealer',
123
+ * score: 7300,
124
+ * equipments: [
125
+ * { name: 'SKS', quality: 'epic', level: 76 },
126
+ * { name: 'Holographic Sight', quality: 'rare', level: 68 },
127
+ * { name: 'Extended Mag', quality: 'common', level: 65 }
128
+ * ]
129
+ * },
130
+ * {
131
+ * name: 'StormRider',
132
+ * score: 8900,
133
+ * equipments: [
134
+ * { name: 'MK14', quality: 'legendary', level: 92 },
135
+ * { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
136
+ * { name: 'Scope 8x', quality: 'epic', level: 80 },
137
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
138
+ * { name: 'Tactical Stock', quality: 'rare', level: 75 }
139
+ * ]
140
+ * },
141
+ * {
142
+ * name: 'CombatLegend',
143
+ * score: 7600,
144
+ * equipments: [
145
+ * { name: 'UMP45', quality: 'rare', level: 74 },
146
+ * { name: 'Level 2 Vest', quality: 'common', level: 67 },
147
+ * { name: 'Red Dot Sight', quality: 'common', level: 62 },
148
+ * { name: 'Extended Mag', quality: 'rare', level: 70 }
149
+ * ]
150
+ * }
151
+ * ];
152
+ *
153
+ * // Create a TreeMultiMap for player rankings
154
+ * const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
155
+ * toEntryFn: ({ score, equipments }) => [score, equipments],
156
+ * isMapMode: false
157
+ * });
158
+ *
159
+ * const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
160
+ * console.log(topPlayersEquipments); // [
161
+ * // [
162
+ * // {
163
+ * // name: 'MK14',
164
+ * // quality: 'legendary',
165
+ * // level: 92
166
+ * // },
167
+ * // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
168
+ * // {
169
+ * // name: 'Scope 8x',
170
+ * // quality: 'epic',
171
+ * // level: 80
172
+ * // },
173
+ * // { name: 'Suppressor', quality: 'legendary', level: 88 },
174
+ * // {
175
+ * // name: 'Tactical Stock',
176
+ * // quality: 'rare',
177
+ * // level: 75
178
+ * // }
179
+ * // ],
180
+ * // [
181
+ * // { name: 'KAR98K', quality: 'legendary', level: 90 },
182
+ * // {
183
+ * // name: 'Level 3 Vest',
184
+ * // quality: 'legendary',
185
+ * // level: 85
186
+ * // },
187
+ * // { name: 'Holographic Sight', quality: 'epic', level: 82 },
188
+ * // {
189
+ * // name: 'Suppressor',
190
+ * // quality: 'legendary',
191
+ * // level: 88
192
+ * // },
193
+ * // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
194
+ * // ]
195
+ * // ]
38
196
  */
39
197
  export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V[], R, MK, MV[], MR> implements IBinaryTree<K, V[], R, MK, MV, MR> {
40
198
  /**
@@ -48,7 +206,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
48
206
  * `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
49
207
  * additional options for configuring the TreeMultiMap instance.
50
208
  */
51
- constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V[], TreeMultiMapNode<K, V>> | R>, options?: TreeMultiMapOptions<K, V[], R>);
209
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
52
210
  /**
53
211
  * Time Complexity: O(1)
54
212
  * Space Complexity: O(1)
@@ -67,15 +225,18 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
67
225
  * Time Complexity: O(1)
68
226
  * Space Complexity: O(1)
69
227
  *
70
- * The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
71
- * key and an empty array of values.
72
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
73
- * that will be created in the TreeMultiMap data structure.
74
- * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
75
- * an empty array as its value.
228
+ * The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
229
+ * and value array.
230
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
231
+ * `TreeMultiMap`.
232
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
233
+ * values associated with a specific key in the TreeMultiMap data structure.
234
+ * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
235
+ * value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
236
+ * value is used.
76
237
  */
77
- createNode(key: K): TreeMultiMapNode<K, V>;
78
- add(node: BTNRep<K, V[], TreeMultiMapNode<K, V>>): boolean;
238
+ createNode(key: K, value?: V[]): TreeMultiMapNode<K, V>;
239
+ add(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
79
240
  add(key: K, value: V): boolean;
80
241
  /**
81
242
  * Time Complexity: O(log n)
@@ -83,7 +244,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
83
244
  *
84
245
  * The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
85
246
  * and deletes the entire node if no values are left for that key.
86
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
247
+ * @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
87
248
  * parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
88
249
  * array of values, or just a key itself.
89
250
  * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
@@ -93,7 +254,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
93
254
  * @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
94
255
  * successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
95
256
  */
96
- deleteValue(keyNodeOrEntry: BTNRep<K, V[], TreeMultiMapNode<K, V>> | K, value: V): boolean;
257
+ deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
97
258
  /**
98
259
  * Time Complexity: O(n)
99
260
  * Space Complexity: O(n)
@@ -1,5 +1,6 @@
1
1
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
2
2
  export class TreeMultiMapNode extends RedBlackTreeNode {
3
+ parent = undefined;
3
4
  /**
4
5
  * This TypeScript constructor initializes an object with a key of type K and an array of values of
5
6
  * type V.
@@ -12,7 +13,6 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
12
13
  constructor(key, value) {
13
14
  super(key, value);
14
15
  }
15
- parent = undefined;
16
16
  _left = undefined;
17
17
  get left() {
18
18
  return this._left;
@@ -37,11 +37,169 @@ export class TreeMultiMapNode extends RedBlackTreeNode {
37
37
  /**
38
38
  *
39
39
  * @example
40
- * // Find elements in a range
41
- * const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
42
- * console.log(tmm.search(new Range(5, 10))); // [5, 10, 7]
43
- * console.log(tmm.search(new Range(4, 12))); // [5, 10, 12, 7]
44
- * console.log(tmm.search(new Range(15, 20))); // [15, 18]
40
+ * // players ranked by score with their equipment
41
+ * type Equipment = {
42
+ * name: string; // Equipment name
43
+ * quality: 'legendary' | 'epic' | 'rare' | 'common';
44
+ * level: number;
45
+ * };
46
+ *
47
+ * type Player = {
48
+ * name: string;
49
+ * score: number;
50
+ * equipments: Equipment[];
51
+ * };
52
+ *
53
+ * // Mock player data with their scores and equipment
54
+ * const players: Player[] = [
55
+ * {
56
+ * name: 'DragonSlayer',
57
+ * score: 8750,
58
+ * equipments: [
59
+ * { name: 'AWM', quality: 'legendary', level: 85 },
60
+ * { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
61
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
62
+ * { name: 'Compensator', quality: 'epic', level: 78 },
63
+ * { name: 'Vertical Grip', quality: 'rare', level: 72 }
64
+ * ]
65
+ * },
66
+ * {
67
+ * name: 'ShadowNinja',
68
+ * score: 7200,
69
+ * equipments: [
70
+ * { name: 'M416', quality: 'epic', level: 75 },
71
+ * { name: 'Ghillie Suit', quality: 'rare', level: 70 },
72
+ * { name: 'Red Dot Sight', quality: 'common', level: 65 },
73
+ * { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
74
+ * ]
75
+ * },
76
+ * {
77
+ * name: 'RuneMaster',
78
+ * score: 9100,
79
+ * equipments: [
80
+ * { name: 'KAR98K', quality: 'legendary', level: 90 },
81
+ * { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
82
+ * { name: 'Holographic Sight', quality: 'epic', level: 82 },
83
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
84
+ * { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
85
+ * ]
86
+ * },
87
+ * {
88
+ * name: 'BattleKing',
89
+ * score: 8500,
90
+ * equipments: [
91
+ * { name: 'AUG', quality: 'epic', level: 82 },
92
+ * { name: 'Red Dot Sight', quality: 'rare', level: 75 },
93
+ * { name: 'Extended Mag', quality: 'common', level: 70 },
94
+ * { name: 'Tactical Stock', quality: 'rare', level: 76 }
95
+ * ]
96
+ * },
97
+ * {
98
+ * name: 'SniperElite',
99
+ * score: 7800,
100
+ * equipments: [
101
+ * { name: 'M24', quality: 'legendary', level: 88 },
102
+ * { name: 'Compensator', quality: 'epic', level: 80 },
103
+ * { name: 'Scope 8x', quality: 'legendary', level: 85 },
104
+ * { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
105
+ * ]
106
+ * },
107
+ * {
108
+ * name: 'RushMaster',
109
+ * score: 7500,
110
+ * equipments: [
111
+ * { name: 'Vector', quality: 'rare', level: 72 },
112
+ * { name: 'Level 2 Helmet', quality: 'common', level: 65 },
113
+ * { name: 'Quickdraw Mag', quality: 'common', level: 60 },
114
+ * { name: 'Laser Sight', quality: 'rare', level: 68 }
115
+ * ]
116
+ * },
117
+ * {
118
+ * name: 'GhostWarrior',
119
+ * score: 8200,
120
+ * equipments: [
121
+ * { name: 'SCAR-L', quality: 'epic', level: 78 },
122
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
123
+ * { name: 'Holographic Sight', quality: 'epic', level: 75 },
124
+ * { name: 'Suppressor', quality: 'rare', level: 72 },
125
+ * { name: 'Vertical Grip', quality: 'common', level: 65 }
126
+ * ]
127
+ * },
128
+ * {
129
+ * name: 'DeathDealer',
130
+ * score: 7300,
131
+ * equipments: [
132
+ * { name: 'SKS', quality: 'epic', level: 76 },
133
+ * { name: 'Holographic Sight', quality: 'rare', level: 68 },
134
+ * { name: 'Extended Mag', quality: 'common', level: 65 }
135
+ * ]
136
+ * },
137
+ * {
138
+ * name: 'StormRider',
139
+ * score: 8900,
140
+ * equipments: [
141
+ * { name: 'MK14', quality: 'legendary', level: 92 },
142
+ * { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
143
+ * { name: 'Scope 8x', quality: 'epic', level: 80 },
144
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
145
+ * { name: 'Tactical Stock', quality: 'rare', level: 75 }
146
+ * ]
147
+ * },
148
+ * {
149
+ * name: 'CombatLegend',
150
+ * score: 7600,
151
+ * equipments: [
152
+ * { name: 'UMP45', quality: 'rare', level: 74 },
153
+ * { name: 'Level 2 Vest', quality: 'common', level: 67 },
154
+ * { name: 'Red Dot Sight', quality: 'common', level: 62 },
155
+ * { name: 'Extended Mag', quality: 'rare', level: 70 }
156
+ * ]
157
+ * }
158
+ * ];
159
+ *
160
+ * // Create a TreeMultiMap for player rankings
161
+ * const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
162
+ * toEntryFn: ({ score, equipments }) => [score, equipments],
163
+ * isMapMode: false
164
+ * });
165
+ *
166
+ * const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
167
+ * console.log(topPlayersEquipments); // [
168
+ * // [
169
+ * // {
170
+ * // name: 'MK14',
171
+ * // quality: 'legendary',
172
+ * // level: 92
173
+ * // },
174
+ * // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
175
+ * // {
176
+ * // name: 'Scope 8x',
177
+ * // quality: 'epic',
178
+ * // level: 80
179
+ * // },
180
+ * // { name: 'Suppressor', quality: 'legendary', level: 88 },
181
+ * // {
182
+ * // name: 'Tactical Stock',
183
+ * // quality: 'rare',
184
+ * // level: 75
185
+ * // }
186
+ * // ],
187
+ * // [
188
+ * // { name: 'KAR98K', quality: 'legendary', level: 90 },
189
+ * // {
190
+ * // name: 'Level 3 Vest',
191
+ * // quality: 'legendary',
192
+ * // level: 85
193
+ * // },
194
+ * // { name: 'Holographic Sight', quality: 'epic', level: 82 },
195
+ * // {
196
+ * // name: 'Suppressor',
197
+ * // quality: 'legendary',
198
+ * // level: 88
199
+ * // },
200
+ * // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
201
+ * // ]
202
+ * // ]
45
203
  */
46
204
  export class TreeMultiMap extends RedBlackTree {
47
205
  /**
@@ -56,7 +214,7 @@ export class TreeMultiMap extends RedBlackTree {
56
214
  * additional options for configuring the TreeMultiMap instance.
57
215
  */
58
216
  constructor(keysNodesEntriesOrRaws = [], options) {
59
- super([], { ...options, isMapMode: true });
217
+ super([], { ...options });
60
218
  if (keysNodesEntriesOrRaws) {
61
219
  this.addMany(keysNodesEntriesOrRaws);
62
220
  }
@@ -80,6 +238,7 @@ export class TreeMultiMap extends RedBlackTree {
80
238
  specifyComparable: this._specifyComparable,
81
239
  toEntryFn: this._toEntryFn,
82
240
  isReverse: this._isReverse,
241
+ isMapMode: this._isMapMode,
83
242
  ...options
84
243
  });
85
244
  }
@@ -87,28 +246,30 @@ export class TreeMultiMap extends RedBlackTree {
87
246
  * Time Complexity: O(1)
88
247
  * Space Complexity: O(1)
89
248
  *
90
- * The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
91
- * key and an empty array of values.
92
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
93
- * that will be created in the TreeMultiMap data structure.
94
- * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
95
- * an empty array as its value.
249
+ * The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
250
+ * and value array.
251
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
252
+ * `TreeMultiMap`.
253
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
254
+ * values associated with a specific key in the TreeMultiMap data structure.
255
+ * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
256
+ * value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
257
+ * value is used.
96
258
  */
97
- createNode(key) {
98
- return new TreeMultiMapNode(key, []);
259
+ createNode(key, value = []) {
260
+ return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
99
261
  }
100
262
  /**
101
263
  * Time Complexity: O(log n)
102
264
  * Space Complexity: O(log n)
103
265
  *
104
- * The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
105
- * TreeMultiMapNode, handling different input types and scenarios.
106
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
107
- * parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
108
- * of values, and a `TreeMultiMapNode`, or just a key.
109
- * @param {V} [value] - The `value` parameter in the `override add` method represents the value that
110
- * you want to add to the TreeMultiMap. If the key is already present in the map, the new value will
111
- * be added to the existing list of values associated with that key. If the key is not present,
266
+ * The function overrides the add method to handle different types of input for a TreeMultiMap data
267
+ * structure.
268
+ * @param [key] - The `key` parameter in the `override add` method represents the key of the entry to
269
+ * be added to the TreeMultiMap. It can be of type `K`, which is the key type of the TreeMultiMap, or
270
+ * it can be a TreeMultiMapNode containing the key and its
271
+ * @param {V[]} [values] - The `values` parameter in the `add` method represents an array of values
272
+ * that you want to add to the TreeMultiMap. It can contain one or more values of type `V`.
112
273
  * @returns The `add` method is returning a boolean value, which indicates whether the operation was
113
274
  * successful or not.
114
275
  */
@@ -118,30 +279,40 @@ export class TreeMultiMap extends RedBlackTree {
118
279
  const _commonAdd = (key, values) => {
119
280
  if (key === undefined || key === null)
120
281
  return false;
121
- const existingValues = this.get(key);
122
- if (existingValues !== undefined && values !== undefined) {
123
- for (const value of values)
124
- existingValues.push(value);
125
- return true;
126
- }
127
- const existingNode = this.getNode(key);
128
- if (this.isRealNode(existingNode)) {
129
- if (existingValues === undefined) {
130
- super.add(key, values);
131
- return true;
132
- }
133
- if (values !== undefined) {
282
+ const _addToValues = () => {
283
+ const existingValues = this.get(key);
284
+ if (existingValues !== undefined && values !== undefined) {
134
285
  for (const value of values)
135
286
  existingValues.push(value);
136
287
  return true;
137
288
  }
289
+ return false;
290
+ };
291
+ const _addByNode = () => {
292
+ const existingNode = this.getNode(key);
293
+ if (this.isRealNode(existingNode)) {
294
+ const existingValues = this.get(existingNode);
295
+ if (existingValues === undefined) {
296
+ super.add(key, values);
297
+ return true;
298
+ }
299
+ if (values !== undefined) {
300
+ for (const value of values)
301
+ existingValues.push(value);
302
+ return true;
303
+ }
304
+ else {
305
+ return false;
306
+ }
307
+ }
138
308
  else {
139
- return false;
309
+ return super.add(key, values);
140
310
  }
311
+ };
312
+ if (this._isMapMode) {
313
+ return _addByNode() || _addToValues();
141
314
  }
142
- else {
143
- return super.add(key, values);
144
- }
315
+ return _addToValues() || _addByNode();
145
316
  };
146
317
  if (this.isEntry(keyNodeOrEntry)) {
147
318
  const [key, values] = keyNodeOrEntry;
@@ -155,7 +326,7 @@ export class TreeMultiMap extends RedBlackTree {
155
326
  *
156
327
  * The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
157
328
  * and deletes the entire node if no values are left for that key.
158
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
329
+ * @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
159
330
  * parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
160
331
  * array of values, or just a key itself.
161
332
  * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
@@ -1 +1 @@
1
- {"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"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,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
1
+ {"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGlE,MAAM,OAAO,gBAAmC,SAAQ,gBAAwB;IACrE,MAAM,GAA4B,SAAS,CAAC;IAErD;;;;;;;;OAQG;IACH,YAAY,GAAM,EAAE,KAAW;QAC7B,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpB,CAAC;IAEQ,KAAK,GAA+C,SAAS,CAAC;IAEvE,IAAa,IAAI;QACf,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAa,IAAI,CAAC,CAA4C;QAC5D,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEQ,MAAM,GAA+C,SAAS,CAAC;IAExE,IAAa,KAAK;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAa,KAAK,CAAC,CAA4C;QAC7D,IAAI,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsKG;AACH,MAAM,OA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E,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,UAAU,CAAC,cAAc,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CACT,cAAuG,EACvG,KAAQ;QAER,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACxC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,KAAK,KAAK,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC/B,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAExB,4CAA4C;YAC5C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAErD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;OAOG;IACM,KAAK;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -266,8 +266,8 @@ export class AbstractGraph extends IterableEntryBase {
266
266
  const queue = new Queue([vertex1]);
267
267
  visited.set(vertex1, true);
268
268
  let cost = 0;
269
- while (queue.size > 0) {
270
- for (let i = 0; i < queue.size; i++) {
269
+ while (queue.length > 0) {
270
+ for (let i = 0; i < queue.length; i++) {
271
271
  const cur = queue.shift();
272
272
  if (cur === vertex2) {
273
273
  return cost;