data-structure-typed 1.50.2 → 1.50.4

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 (203) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
  2. package/CHANGELOG.md +1 -1
  3. package/README.md +23 -21
  4. package/README_zh-CN.md +7 -7
  5. package/SPECIFICATION.md +56 -0
  6. package/SPONSOR-zh-CN.md +90 -0
  7. package/SPONSOR.md +54 -0
  8. package/benchmark/report.html +13 -13
  9. package/benchmark/report.json +149 -155
  10. package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
  11. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  13. package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
  15. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
  16. package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  19. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  20. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
  24. package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
  27. package/dist/cjs/data-structures/binary-tree/index.js +2 -1
  28. package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
  30. package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
  31. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  33. package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
  34. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
  42. package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
  45. package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
  46. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
  48. package/dist/cjs/data-structures/hash/hash-map.js +196 -62
  49. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  50. package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
  51. package/dist/cjs/data-structures/heap/heap.js +29 -20
  52. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  54. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
  55. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  57. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
  58. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  60. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
  61. package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
  62. package/dist/cjs/data-structures/matrix/matrix.js +1 -1
  63. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  64. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  65. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  67. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  70. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
  71. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  72. package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
  73. package/dist/cjs/data-structures/queue/deque.js +100 -16
  74. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  75. package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
  76. package/dist/cjs/data-structures/queue/queue.js +65 -45
  77. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  78. package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
  79. package/dist/cjs/data-structures/stack/stack.js +36 -22
  80. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  81. package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
  82. package/dist/cjs/data-structures/tree/tree.js +77 -11
  83. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  84. package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
  85. package/dist/cjs/data-structures/trie/trie.js +115 -36
  86. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  87. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  88. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
  89. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
  90. package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
  91. package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
  92. package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
  93. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  94. package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
  95. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
  96. package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
  97. package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
  98. package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
  99. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
  100. package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
  101. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  102. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
  106. package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
  107. package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
  108. package/dist/mjs/data-structures/binary-tree/index.js +2 -1
  109. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
  110. package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
  111. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  112. package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
  113. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
  114. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
  115. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
  116. package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
  117. package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
  118. package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
  119. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
  120. package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
  121. package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
  122. package/dist/mjs/data-structures/hash/hash-map.js +204 -70
  123. package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
  124. package/dist/mjs/data-structures/heap/heap.js +29 -20
  125. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
  126. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
  127. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
  128. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
  129. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  130. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
  131. package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
  132. package/dist/mjs/data-structures/matrix/matrix.js +1 -1
  133. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  134. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  135. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  136. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  137. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  138. package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
  139. package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
  140. package/dist/mjs/data-structures/queue/deque.js +105 -21
  141. package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
  142. package/dist/mjs/data-structures/queue/queue.js +65 -45
  143. package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
  144. package/dist/mjs/data-structures/stack/stack.js +36 -22
  145. package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
  146. package/dist/mjs/data-structures/tree/tree.js +80 -14
  147. package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
  148. package/dist/mjs/data-structures/trie/trie.js +118 -39
  149. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
  150. package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
  151. package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
  152. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
  153. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
  154. package/dist/umd/data-structure-typed.js +1876 -656
  155. package/dist/umd/data-structure-typed.min.js +2 -2
  156. package/dist/umd/data-structure-typed.min.js.map +1 -1
  157. package/package.json +59 -58
  158. package/src/data-structures/base/iterable-base.ts +12 -0
  159. package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
  160. package/src/data-structures/binary-tree/avl-tree.ts +37 -3
  161. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  162. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  163. package/src/data-structures/binary-tree/bst.ts +51 -19
  164. package/src/data-structures/binary-tree/index.ts +2 -1
  165. package/src/data-structures/binary-tree/rb-tree.ts +99 -28
  166. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  167. package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
  168. package/src/data-structures/graph/abstract-graph.ts +0 -211
  169. package/src/data-structures/graph/directed-graph.ts +122 -0
  170. package/src/data-structures/graph/undirected-graph.ts +143 -19
  171. package/src/data-structures/hash/hash-map.ts +228 -76
  172. package/src/data-structures/heap/heap.ts +31 -20
  173. package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
  174. package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
  175. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  176. package/src/data-structures/matrix/matrix.ts +1 -1
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  179. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  180. package/src/data-structures/queue/deque.ts +118 -22
  181. package/src/data-structures/queue/queue.ts +68 -45
  182. package/src/data-structures/stack/stack.ts +39 -23
  183. package/src/data-structures/tree/tree.ts +89 -15
  184. package/src/data-structures/trie/trie.ts +131 -40
  185. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
  186. package/src/types/data-structures/binary-tree/index.ts +2 -1
  187. package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
  188. package/test/integration/index.html +2 -2
  189. package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
  190. package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
  191. package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
  192. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
  193. package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
  194. package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
  195. package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
  196. package/test/unit/data-structures/queue/queue.test.ts +2 -0
  197. package/test/unit/unrestricted-interconversion.test.ts +3 -3
  198. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
  199. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  200. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
  201. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
  202. package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
  203. /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.50.2",
3
+ "version": "1.50.4",
4
4
  "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -94,17 +94,52 @@
94
94
  "keywords": [
95
95
  "data structure",
96
96
  "data structures",
97
- "javascript data structure",
98
- "javascript data structures",
99
- "typescript data structure",
100
- "typescript data structures",
101
- "js data structure",
102
- "js data structures",
103
- "data-structure",
104
97
  "datastructure",
98
+ "datastructures",
105
99
  "data",
106
100
  "structure",
107
101
  "structures",
102
+ "min",
103
+ "max",
104
+ "heap",
105
+ "priority",
106
+ "queue",
107
+ "min heap",
108
+ "min-heap",
109
+ "max heap",
110
+ "max-heap",
111
+ "priority queue",
112
+ "priority-queue",
113
+ "max priority queue",
114
+ "max-priority-queue",
115
+ "min priority queue",
116
+ "min-priority-queue",
117
+ "binary search tree",
118
+ "binary-search-tree",
119
+ "BST",
120
+ "binary tree",
121
+ "binary-tree",
122
+ "red black tree",
123
+ "red black tree",
124
+ "red-black-tree",
125
+ "rb tree",
126
+ "trie",
127
+ "prefix tree",
128
+ "prefix-tree",
129
+ "avl tree",
130
+ "avl-tree",
131
+ "tree set",
132
+ "tree-set",
133
+ "tree multiset",
134
+ "tree-multiset",
135
+ "tree map",
136
+ "tree-map",
137
+ "tree multimap",
138
+ "tree-multimap",
139
+ "binary indexed tree",
140
+ "binary-indexed-tree",
141
+ "segment tree",
142
+ "segment-tree",
108
143
  "binary",
109
144
  "depth",
110
145
  "breadth",
@@ -124,18 +159,26 @@
124
159
  "set",
125
160
  "multiset",
126
161
  "multimap",
127
- "directed",
128
- "undirected",
129
- "graph",
130
- "min",
131
- "max",
132
- "heap",
133
- "priority",
134
- "queue",
135
162
  "singly",
136
163
  "doubly",
137
164
  "linked",
138
165
  "list",
166
+ "linked list",
167
+ "linked-list",
168
+ "singly linked list",
169
+ "singly-linked-list",
170
+ "doubly linked list",
171
+ "doubly-linked-list",
172
+ "javascript data structure",
173
+ "javascript data structures",
174
+ "typescript data structures",
175
+ "js data structure",
176
+ "js data structures",
177
+ "data-structure",
178
+ "data-structures",
179
+ "directed",
180
+ "undirected",
181
+ "graph",
139
182
  "js",
140
183
  "ts",
141
184
  "javascript",
@@ -159,32 +202,6 @@
159
202
  "java.util",
160
203
  "Java",
161
204
  "util",
162
- "binary search tree",
163
- "binary-search-tree",
164
- "BST",
165
- "binary tree",
166
- "binary-tree",
167
- "red black tree",
168
- "red black tree",
169
- "red-black-tree",
170
- "rb tree",
171
- "trie",
172
- "prefix tree",
173
- "prefix-tree",
174
- "avl tree",
175
- "avl-tree",
176
- "tree set",
177
- "tree-set",
178
- "tree multiset",
179
- "tree-multiset",
180
- "tree map",
181
- "tree-map",
182
- "tree multimap",
183
- "tree-multimap",
184
- "binary indexed tree",
185
- "binary-indexed-tree",
186
- "segment tree",
187
- "segment-tree",
188
205
  "sort",
189
206
  "sorted",
190
207
  "order",
@@ -212,28 +229,12 @@
212
229
  "directed-graph",
213
230
  "undirected graph",
214
231
  "undirected-graph",
215
- "min heap",
216
- "min-heap",
217
- "max heap",
218
- "max-heap",
219
- "priority queue",
220
- "priority-queue",
221
- "max priority queue",
222
- "max-priority-queue",
223
- "min priority queue",
224
- "min-priority-queue",
225
232
  "hash",
226
233
  "map",
227
234
  "hashmap",
228
235
  "hash map",
229
236
  "hash-map",
230
237
  "deque",
231
- "linked list",
232
- "linked-list",
233
- "singly linked list",
234
- "singly-linked-list",
235
- "doubly linked list",
236
- "doubly-linked-list",
237
238
  "stack",
238
239
  "CommonJS",
239
240
  "ES6",
@@ -289,8 +289,14 @@ export abstract class IterableEntryBase<K = any, V = any> {
289
289
 
290
290
  abstract isEmpty(): boolean;
291
291
 
292
+ abstract clear(): void;
293
+
292
294
  abstract clone(): any;
293
295
 
296
+ abstract map(...args: any[]): any;
297
+
298
+ abstract filter(...args: any[]): any;
299
+
294
300
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
295
301
  }
296
302
 
@@ -497,7 +503,13 @@ export abstract class IterableElementBase<E = any, C = any> {
497
503
 
498
504
  abstract isEmpty(): boolean;
499
505
 
506
+ abstract clear(): void;
507
+
500
508
  abstract clone(): C;
501
509
 
510
+ abstract map(...args: any[]): any;
511
+
512
+ abstract filter(...args: any[]): any;
513
+
502
514
  protected abstract _getIterator(...args: any[]): IterableIterator<E>;
503
515
  }
@@ -6,25 +6,23 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type {
9
+ AVLTreeMultiMapNested,
10
+ AVLTreeMultiMapNodeNested,
11
+ AVLTreeMultiMapOptions,
9
12
  BinaryTreeDeleteResult,
10
13
  BSTNKeyOrNode,
11
14
  BTNCallback,
12
- KeyOrNodeOrEntry,
13
- TreeMultimapNested,
14
- TreeMultimapNodeNested,
15
- TreeMultimapOptions
15
+ KeyOrNodeOrEntry
16
16
  } from '../../types';
17
17
  import { FamilyPosition, IterationType } from '../../types';
18
18
  import { IBinaryTree } from '../../interfaces';
19
19
  import { AVLTree, AVLTreeNode } from './avl-tree';
20
20
 
21
- export class TreeMultimapNode<
21
+ export class AVLTreeMultiMapNode<
22
22
  K = any,
23
23
  V = any,
24
- NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNodeNested<K, V>
24
+ NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>
25
25
  > extends AVLTreeNode<K, V, NODE> {
26
- count: number;
27
-
28
26
  /**
29
27
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
30
28
  * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
@@ -39,27 +37,51 @@ export class TreeMultimapNode<
39
37
  super(key, value);
40
38
  this.count = count;
41
39
  }
40
+
41
+ protected _count: number = 1;
42
+
43
+ /**
44
+ * The function returns the value of the protected variable _count.
45
+ * @returns The count property of the object, which is of type number.
46
+ */
47
+ get count(): number {
48
+ return this._count;
49
+ }
50
+
51
+ /**
52
+ * The above function sets the value of the count property.
53
+ * @param {number} value - The value parameter is of type number, which means it can accept any
54
+ * numeric value.
55
+ */
56
+ set count(value: number) {
57
+ this._count = value;
58
+ }
42
59
  }
43
60
 
44
61
  /**
45
- * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
62
+ * The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
46
63
  */
47
- export class TreeMultimap<
64
+ export class AVLTreeMultiMap<
48
65
  K = any,
49
66
  V = any,
50
- NODE extends TreeMultimapNode<K, V, NODE> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>,
51
- TREE extends TreeMultimap<K, V, NODE, TREE> = TreeMultimap<K, V, NODE, TreeMultimapNested<K, V, NODE>>
67
+ NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>,
68
+ TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>
52
69
  >
53
70
  extends AVLTree<K, V, NODE, TREE>
54
71
  implements IBinaryTree<K, V, NODE, TREE> {
55
- constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: TreeMultimapOptions<K>) {
72
+ constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: AVLTreeMultiMapOptions<K>) {
56
73
  super([], options);
57
74
  if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
58
75
  }
59
76
 
60
- private _count = 0;
77
+ protected _count = 0;
61
78
 
62
79
  // TODO the _count is not accurate after nodes count modified
80
+ /**
81
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
82
+ * search.
83
+ * @returns the sum of the count property of all nodes in the tree.
84
+ */
63
85
  get count(): number {
64
86
  let sum = 0;
65
87
  this.dfs(node => (sum += node.count));
@@ -76,11 +98,20 @@ export class TreeMultimap<
76
98
  * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
77
99
  */
78
100
  override createNode(key: K, value?: V, count?: number): NODE {
79
- return new TreeMultimapNode(key, value, count) as NODE;
101
+ return new AVLTreeMultiMapNode(key, value, count) as NODE;
80
102
  }
81
103
 
82
- override createTree(options?: TreeMultimapOptions<K>): TREE {
83
- return new TreeMultimap<K, V, NODE, TREE>([], {
104
+ /**
105
+ * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
106
+ * @param [options] - The `options` parameter is an optional object that contains additional
107
+ * configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
108
+ * `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
109
+ * the tree, respectively. These properties can be
110
+ * @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
111
+ * default options. The returned value is casted as `TREE`.
112
+ */
113
+ override createTree(options?: AVLTreeMultiMapOptions<K>): TREE {
114
+ return new AVLTreeMultiMap<K, V, NODE, TREE>([], {
84
115
  iterationType: this.iterationType,
85
116
  variant: this.variant,
86
117
  ...options
@@ -124,13 +155,13 @@ export class TreeMultimap<
124
155
  }
125
156
 
126
157
  /**
127
- * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
158
+ * The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
128
159
  * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
129
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
160
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
130
161
  * class.
131
162
  */
132
163
  override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
133
- return keyOrNodeOrEntry instanceof TreeMultimapNode;
164
+ return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
134
165
  }
135
166
 
136
167
  /**
@@ -375,6 +406,14 @@ export class TreeMultimap<
375
406
  return undefined;
376
407
  }
377
408
 
409
+ /**
410
+ * The function replaces an old node with a new node and updates the count property of the new node.
411
+ * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
412
+ * needs to be replaced in a data structure.
413
+ * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
414
+ * @returns The method is returning the result of calling the `_replaceNode` method from the
415
+ * superclass, after updating the `count` property of the `newNode` object.
416
+ */
378
417
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
379
418
  newNode.count = oldNode.count + newNode.count;
380
419
  return super._replaceNode(oldNode, newNode);
@@ -22,11 +22,36 @@ export class AVLTreeNode<
22
22
  V = any,
23
23
  NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>
24
24
  > extends BSTNode<K, V, NODE> {
25
- height: number;
26
-
25
+ /**
26
+ * The constructor function initializes a new instance of a class with a key and an optional value,
27
+ * and sets the height property to 0.
28
+ * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
29
+ * constructor. It is used to initialize the key property of the object being created.
30
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
31
+ * value associated with the key in the constructor.
32
+ */
27
33
  constructor(key: K, value?: V) {
28
34
  super(key, value);
29
- this.height = 0;
35
+ this._height = 0;
36
+ }
37
+
38
+ protected _height: number;
39
+
40
+ /**
41
+ * The function returns the value of the height property.
42
+ * @returns The height of the object.
43
+ */
44
+ get height(): number {
45
+ return this._height;
46
+ }
47
+
48
+ /**
49
+ * The above function sets the value of the height property.
50
+ * @param {number} value - The value parameter is a number that represents the new height value to be
51
+ * set.
52
+ */
53
+ set height(value: number) {
54
+ this._height = value;
30
55
  }
31
56
  }
32
57
 
@@ -488,6 +513,15 @@ export class AVLTree<
488
513
  }
489
514
  }
490
515
 
516
+ /**
517
+ * The function replaces an old node with a new node while preserving the height of the old node.
518
+ * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
519
+ * `newNode`.
520
+ * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
521
+ * the data structure.
522
+ * @returns the result of calling the `_replaceNode` method on the superclass, passing in the
523
+ * `oldNode` and `newNode` as arguments.
524
+ */
491
525
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE {
492
526
  newNode.height = oldNode.height;
493
527
 
@@ -27,26 +27,48 @@ export class BinaryIndexedTree {
27
27
 
28
28
  protected _freqMap: Record<number, number>;
29
29
 
30
+ /**
31
+ * The function returns the frequency map of numbers.
32
+ * @returns The `_freqMap` property, which is a record with number keys and number values, is being
33
+ * returned.
34
+ */
30
35
  get freqMap(): Record<number, number> {
31
36
  return this._freqMap;
32
37
  }
33
38
 
34
39
  protected _msb: number;
35
40
 
41
+ /**
42
+ * The function returns the value of the _msb property.
43
+ * @returns The `_msb` property of the object.
44
+ */
36
45
  get msb(): number {
37
46
  return this._msb;
38
47
  }
39
48
 
40
49
  protected _negativeCount: number;
41
50
 
51
+ /**
52
+ * The function returns the value of the _negativeCount property.
53
+ * @returns The method is returning the value of the variable `_negativeCount`, which is of type
54
+ * `number`.
55
+ */
42
56
  get negativeCount(): number {
43
57
  return this._negativeCount;
44
58
  }
45
59
 
60
+ /**
61
+ * The above function returns the value of the protected variable `_freq`.
62
+ * @returns The frequency value stored in the protected variable `_freq`.
63
+ */
46
64
  get freq(): number {
47
65
  return this._freq;
48
66
  }
49
67
 
68
+ /**
69
+ * The above function returns the maximum value.
70
+ * @returns The maximum value stored in the variable `_max`.
71
+ */
50
72
  get max(): number {
51
73
  return this._max;
52
74
  }
@@ -44,7 +44,7 @@ export class BinaryTreeNode<
44
44
  /**
45
45
  * The constructor function initializes an object with a key and an optional value.
46
46
  * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
47
- * constructor. It is used to set the value of the "key" property of the object being created.
47
+ * constructor. It is used to set the key property of the object being created.
48
48
  * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
49
49
  * value associated with the key in the constructor.
50
50
  */
@@ -34,10 +34,19 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
34
34
 
35
35
  protected override _left?: NODE;
36
36
 
37
+ /**
38
+ * The function returns the value of the `_left` property.
39
+ * @returns The `_left` property of the current object is being returned.
40
+ */
37
41
  override get left(): NODE | undefined {
38
42
  return this._left;
39
43
  }
40
44
 
45
+ /**
46
+ * The function sets the left child of a node and updates the parent reference of the child.
47
+ * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
48
+ * instance of the `NODE` class or `undefined`.
49
+ */
41
50
  override set left(v: NODE | undefined) {
42
51
  if (v) {
43
52
  v.parent = this as unknown as NODE;
@@ -47,10 +56,20 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
47
56
 
48
57
  protected override _right?: NODE;
49
58
 
59
+ /**
60
+ * The function returns the right node of a binary tree or undefined if there is no right node.
61
+ * @returns The method is returning the value of the `_right` property, which is of type `NODE` or
62
+ * `undefined`.
63
+ */
50
64
  override get right(): NODE | undefined {
51
65
  return this._right;
52
66
  }
53
67
 
68
+ /**
69
+ * The function sets the right child of a node and updates the parent reference of the child.
70
+ * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
71
+ * `NODE` object or `undefined`.
72
+ */
54
73
  override set right(v: NODE | undefined) {
55
74
  if (v) {
56
75
  v.parent = this as unknown as NODE;
@@ -77,10 +96,10 @@ export class BST<
77
96
  extends BinaryTree<K, V, NODE, TREE>
78
97
  implements IBinaryTree<K, V, NODE, TREE> {
79
98
  /**
80
- * This is the constructor function for a binary search tree class in TypeScript, which initializes
81
- * the tree with optional keysOrNodesOrEntries and options.
82
- * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
83
- * binary search tree.
99
+ * This is the constructor function for a TypeScript class that initializes a binary search tree with
100
+ * optional keys or nodes or entries and options.
101
+ * @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
102
+ * to initialize the binary search tree with the provided keys, nodes, or entries.
84
103
  * @param [options] - The `options` parameter is an optional object that can contain additional
85
104
  * configuration options for the binary search tree. It can have the following properties:
86
105
  */
@@ -99,23 +118,31 @@ export class BST<
99
118
 
100
119
  protected override _root?: NODE;
101
120
 
121
+ /**
122
+ * The function returns the root node of a tree structure.
123
+ * @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
124
+ */
102
125
  override get root(): NODE | undefined {
103
126
  return this._root;
104
127
  }
105
128
 
106
129
  protected _variant = BSTVariant.STANDARD;
107
130
 
131
+ /**
132
+ * The function returns the value of the _variant property.
133
+ * @returns The value of the `_variant` property.
134
+ */
108
135
  get variant() {
109
136
  return this._variant;
110
137
  }
111
138
 
112
139
  /**
113
- * The function creates a new binary search tree node with the given key and value.
114
- * @param {K} key - The key parameter is the key value that will be associated with
115
- * the new node. It is used to determine the position of the node in the binary search tree.
116
- * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It
117
- * represents the value associated with the node in a binary search tree.
118
- * @returns a new instance of the BSTNode class with the specified key and value.
140
+ * The function creates a new BSTNode with the given key and value and returns it.
141
+ * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
142
+ * being created.
143
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
144
+ * value associated with the key in the node being created.
145
+ * @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
119
146
  */
120
147
  override createNode(key: K, value?: V): NODE {
121
148
  return new BSTNode<K, V, NODE>(key, value) as NODE;
@@ -124,9 +151,10 @@ export class BST<
124
151
  /**
125
152
  * The function creates a new binary search tree with the specified options.
126
153
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
127
- * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which is a type
128
- * that defines various options for creating a binary search tree.
129
- * @returns a new instance of the BST class with the specified options.
154
+ * behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
155
+ * partial object of type `BSTOptions<K>`.
156
+ * @returns a new instance of the BST class, with the provided options merged with the default
157
+ * options. The returned value is casted as TREE.
130
158
  */
131
159
  override createTree(options?: Partial<BSTOptions<K>>): TREE {
132
160
  return new BST<K, V, NODE, TREE>([], {
@@ -680,9 +708,8 @@ export class BST<
680
708
  const compared = this._compare(cur.key, targetKey);
681
709
  if (compared === lesserOrGreater) ans.push(callback(cur));
682
710
 
683
- if (!cur.left && !cur.right) return;
684
- if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater) _traverse(cur.left);
685
- if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater) _traverse(cur.right);
711
+ if (this.isRealNode(cur.left)) _traverse(cur.left);
712
+ if (this.isRealNode(cur.right)) _traverse(cur.right);
686
713
  };
687
714
 
688
715
  _traverse(this.root);
@@ -691,12 +718,12 @@ export class BST<
691
718
  const queue = new Queue<NODE>([this.root]);
692
719
  while (queue.size > 0) {
693
720
  const cur = queue.shift();
694
- if (cur) {
721
+ if (this.isRealNode(cur)) {
695
722
  const compared = this._compare(cur.key, targetKey);
696
723
  if (compared === lesserOrGreater) ans.push(callback(cur));
697
724
 
698
- if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater) queue.push(cur.left);
699
- if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater) queue.push(cur.right);
725
+ if (this.isRealNode(cur.left)) queue.push(cur.left);
726
+ if (this.isRealNode(cur.right)) queue.push(cur.right);
700
727
  }
701
728
  }
702
729
  return ans;
@@ -824,6 +851,11 @@ export class BST<
824
851
  return balanced;
825
852
  }
826
853
 
854
+ /**
855
+ * The function sets the root property of an object and updates the parent property of the new root.
856
+ * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
857
+ * can either be an object of type `NODE` or it can be `undefined`.
858
+ */
827
859
  protected _setRoot(v: NODE | undefined) {
828
860
  if (v) {
829
861
  v.parent = undefined;
@@ -4,4 +4,5 @@ export * from './binary-indexed-tree';
4
4
  export * from './segment-tree';
5
5
  export * from './avl-tree';
6
6
  export * from './rb-tree';
7
- export * from './tree-multimap';
7
+ export * from './avl-tree-multi-map';
8
+ export * from './tree-multi-map';