data-structure-typed 2.0.5 → 2.1.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 (260) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/COMMANDS.md +17 -0
  3. package/benchmark/report.html +13 -77
  4. package/benchmark/report.json +145 -177
  5. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  6. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  7. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  9. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  12. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  13. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  27. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  28. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  42. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  45. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  46. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  48. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  49. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  51. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  54. package/dist/cjs/data-structures/heap/heap.js +340 -349
  55. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  56. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  57. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  58. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  59. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  60. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  61. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  62. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  65. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  68. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  71. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  74. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  77. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  80. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  81. package/dist/cjs/data-structures/queue/deque.js +309 -348
  82. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  83. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  84. package/dist/cjs/data-structures/queue/queue.js +265 -248
  85. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  86. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  87. package/dist/cjs/data-structures/stack/stack.js +181 -125
  88. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  89. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  90. package/dist/cjs/data-structures/trie/trie.js +189 -172
  91. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  92. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  93. package/dist/cjs/interfaces/graph.d.ts +16 -0
  94. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  95. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  96. package/dist/cjs/types/utils/utils.d.ts +1 -0
  97. package/dist/cjs/utils/utils.d.ts +1 -1
  98. package/dist/cjs/utils/utils.js +2 -1
  99. package/dist/cjs/utils/utils.js.map +1 -1
  100. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  101. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  102. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  103. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  104. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  105. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  106. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  107. package/dist/esm/data-structures/base/linear-base.js +137 -274
  108. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  109. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  112. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  115. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  116. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  118. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  119. package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  121. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  122. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  123. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  124. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  127. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  128. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  130. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  133. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  134. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  135. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  136. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  137. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  138. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  139. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  140. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  141. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  142. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  143. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  144. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  145. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  146. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  147. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  148. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  149. package/dist/esm/data-structures/heap/heap.js +329 -349
  150. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  151. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  152. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  153. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  154. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  155. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  156. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  157. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  160. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  163. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  166. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  169. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  172. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  173. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  175. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  176. package/dist/esm/data-structures/queue/deque.js +313 -348
  177. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  178. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  179. package/dist/esm/data-structures/queue/queue.js +263 -248
  180. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  181. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  182. package/dist/esm/data-structures/stack/stack.js +181 -125
  183. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  184. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  185. package/dist/esm/data-structures/trie/trie.js +193 -172
  186. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  187. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  188. package/dist/esm/interfaces/graph.d.ts +16 -0
  189. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  190. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  191. package/dist/esm/types/utils/utils.d.ts +1 -0
  192. package/dist/esm/utils/utils.d.ts +1 -1
  193. package/dist/esm/utils/utils.js +2 -1
  194. package/dist/esm/utils/utils.js.map +1 -1
  195. package/dist/umd/data-structure-typed.js +4685 -6477
  196. package/dist/umd/data-structure-typed.min.js +8 -6
  197. package/dist/umd/data-structure-typed.min.js.map +1 -1
  198. package/package.json +3 -4
  199. package/src/data-structures/base/iterable-element-base.ts +238 -115
  200. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  201. package/src/data-structures/base/linear-base.ts +271 -277
  202. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  203. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  204. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  205. package/src/data-structures/binary-tree/binary-tree.ts +660 -889
  206. package/src/data-structures/binary-tree/bst.ts +568 -570
  207. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  208. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  209. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  210. package/src/data-structures/graph/abstract-graph.ts +339 -264
  211. package/src/data-structures/graph/directed-graph.ts +146 -236
  212. package/src/data-structures/graph/map-graph.ts +63 -60
  213. package/src/data-structures/graph/undirected-graph.ts +129 -152
  214. package/src/data-structures/hash/hash-map.ts +274 -496
  215. package/src/data-structures/heap/heap.ts +389 -402
  216. package/src/data-structures/heap/max-heap.ts +12 -76
  217. package/src/data-structures/heap/min-heap.ts +13 -76
  218. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  219. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  220. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  223. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  224. package/src/data-structures/queue/deque.ts +381 -357
  225. package/src/data-structures/queue/queue.ts +310 -264
  226. package/src/data-structures/stack/stack.ts +217 -131
  227. package/src/data-structures/trie/trie.ts +240 -175
  228. package/src/interfaces/binary-tree.ts +240 -6
  229. package/src/interfaces/graph.ts +37 -0
  230. package/src/types/data-structures/base/base.ts +5 -5
  231. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  232. package/src/types/utils/utils.ts +2 -0
  233. package/src/utils/utils.ts +9 -14
  234. package/test/integration/index.html +1 -1
  235. package/test/performance/benchmark-runner.ts +528 -0
  236. package/test/performance/reportor.mjs +43 -43
  237. package/test/performance/runner-config.json +39 -0
  238. package/test/performance/single-suite-runner.ts +69 -0
  239. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  240. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  241. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  242. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  243. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  244. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  245. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  246. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  247. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  248. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  249. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  250. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  251. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  252. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  253. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  254. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  255. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  256. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  258. package/test/unit/utils/utils.test.ts +0 -1
  259. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  260. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -7,49 +7,64 @@
7
7
  */
8
8
  import type { ElementCallback, TrieOptions } from '../../types';
9
9
  import { IterableElementBase } from '../base';
10
+ /**
11
+ * Node used by Trie to store one character and its children.
12
+ * @remarks Time O(1), Space O(1)
13
+ */
10
14
  export declare class TrieNode {
15
+ /**
16
+ * Create a Trie node with a character key.
17
+ * @remarks Time O(1), Space O(1)
18
+ * @returns New TrieNode instance.
19
+ */
11
20
  constructor(key: string);
12
21
  protected _key: string;
13
22
  /**
14
- * The function returns the value of the protected variable _key.
15
- * @returns The value of the `_key` property, which is a string.
23
+ * Get the character key of this node.
24
+ * @remarks Time O(1), Space O(1)
25
+ * @returns Character key string.
16
26
  */
17
27
  get key(): string;
18
28
  /**
19
- * The above function sets the value of a protected variable called "key".
20
- * @param {string} value - The value parameter is a string that represents the value to be assigned
21
- * to the key.
29
+ * Set the character key of this node.
30
+ * @remarks Time O(1), Space O(1)
31
+ * @param value - New character key.
32
+ * @returns void
22
33
  */
23
34
  set key(value: string);
24
35
  protected _children: Map<string, TrieNode>;
25
36
  /**
26
- * The function returns the children of a TrieNode as a Map.
27
- * @returns The `children` property of the TrieNode object, which is a Map containing string keys and
28
- * TrieNode values.
37
+ * Get the child map of this node.
38
+ * @remarks Time O(1), Space O(1)
39
+ * @returns Map from character to child node.
29
40
  */
30
41
  get children(): Map<string, TrieNode>;
31
42
  /**
32
- * The function sets the value of the `_children` property of a TrieNode object.
33
- * @param value - The value parameter is a Map object that represents the children of a TrieNode. The
34
- * keys of the map are strings, which represent the characters that are associated with each child
35
- * TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
36
- * current TrieNode.
43
+ * Replace the child map of this node.
44
+ * @remarks Time O(1), Space O(1)
45
+ * @param value - New map of character node.
46
+ * @returns void
37
47
  */
38
48
  set children(value: Map<string, TrieNode>);
39
49
  protected _isEnd: boolean;
40
50
  /**
41
- * The function returns a boolean value indicating whether a certain condition is met.
42
- * @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
51
+ * Check whether this node marks the end of a word.
52
+ * @remarks Time O(1), Space O(1)
53
+ * @returns True if this node ends a word.
43
54
  */
44
55
  get isEnd(): boolean;
45
56
  /**
46
- * The function sets the value of the "_isEnd" property.
47
- * @param {boolean} value - The value parameter is a boolean value that indicates whether the current
48
- * state is the end state or not.
57
+ * Mark this node as the end of a word or not.
58
+ * @remarks Time O(1), Space O(1)
59
+ * @param value - Whether this node ends a word.
60
+ * @returns void
49
61
  */
50
62
  set isEnd(value: boolean);
51
63
  }
52
64
  /**
65
+ * Prefix tree (Trie) for fast prefix queries and word storage.
66
+ * @remarks Time O(1), Space O(1)
67
+ * @template R
53
68
  * 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
54
69
  * 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
55
70
  * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
@@ -145,207 +160,191 @@ export declare class TrieNode {
145
160
  */
146
161
  export declare class Trie<R = any> extends IterableElementBase<string, R> {
147
162
  /**
148
- * The constructor initializes a Trie data structure with optional options and words provided as
149
- * input.
150
- * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
151
- * iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
152
- * a list of words or elements. If no `words` are provided, an empty iterable is used as the default
153
- * value.
154
- * @param [options] - The `options` parameter in the constructor is an optional object that can
155
- * contain configuration options for the Trie data structure. One of the options it can have is
156
- * `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
157
- * not. If `caseSensitive` is set to `
163
+ * Create a Trie and optionally bulk-insert words.
164
+ * @remarks Time O(totalChars), Space O(totalChars)
165
+ * @param [words] - Iterable of strings (or raw records if toElementFn is provided).
166
+ * @param [options] - Options such as toElementFn and caseSensitive.
167
+ * @returns New Trie instance.
158
168
  */
159
169
  constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
160
170
  protected _size: number;
161
171
  /**
162
- * The size function returns the size of the stack.
163
- * @return The number of elements in the list
172
+ * Get the number of stored words.
173
+ * @remarks Time O(1), Space O(1)
174
+ * @returns Word count.
164
175
  */
165
176
  get size(): number;
166
177
  protected _caseSensitive: boolean;
167
178
  /**
168
- * The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
169
- * @return The value of the _caseSensitive protected variable
179
+ * Get whether comparisons are case-sensitive.
180
+ * @remarks Time O(1), Space O(1)
181
+ * @returns True if case-sensitive.
170
182
  */
171
183
  get caseSensitive(): boolean;
172
184
  protected _root: TrieNode;
173
185
  /**
174
- * The root function returns the root node of the tree.
175
- * @return The root node
186
+ * Get the root node.
187
+ * @remarks Time O(1), Space O(1)
188
+ * @returns Root TrieNode.
176
189
  */
177
190
  get root(): TrieNode;
178
191
  /**
179
- * Time Complexity: O(l), where l is the length of the word being added.
180
- * Space Complexity: O(l) - Each character in the word adds a TrieNode.
181
- *
182
- * Add a word to the Trie structure.
183
- * @param {string} word - The word to add.
184
- * @returns {boolean} True if the word was successfully added.
192
+ * (Protected) Get total count for base class iteration.
193
+ * @remarks Time O(1), Space O(1)
194
+ * @returns Total number of elements.
195
+ */
196
+ protected get _total(): number;
197
+ /**
198
+ * Insert one word into the trie.
199
+ * @remarks Time O(L), Space O(L)
200
+ * @param word - Word to insert.
201
+ * @returns True if the word was newly added.
185
202
  */
186
203
  add(word: string): boolean;
187
204
  /**
188
- * Time Complexity: O(n * l)
189
- * Space Complexity: O(1)
190
- *
191
- * The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
192
- * them using a provided function if available, and adds them to a data structure while returning an
193
- * array of boolean values indicating success.
194
- * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
195
- * an iterable that contains either strings or elements of type `R`.
196
- * @returns The `addMany` method returns an array of boolean values indicating whether each word in
197
- * the input iterable was successfully added to the data structure.
205
+ * Insert many words from an iterable.
206
+ * @remarks Time O(ΣL), Space O(ΣL)
207
+ * @param words - Iterable of strings (or raw records if toElementFn is provided).
208
+ * @returns Array of per-word 'added' flags.
198
209
  */
199
210
  addMany(words: Iterable<string> | Iterable<R>): boolean[];
200
211
  /**
201
- * Time Complexity: O(l), where l is the length of the input word.
202
- * Space Complexity: O(1) - Constant space.
203
- *
204
- * Check if the Trie contains a given word.
205
- * @param {string} word - The word to check for.
206
- * @returns {boolean} True if the word is present in the Trie.
212
+ * Check whether a word exists.
213
+ * @remarks Time O(L), Space O(1)
214
+ * @param word - Word to search for.
215
+ * @returns True if present.
207
216
  */
208
217
  has(word: string): boolean;
209
218
  /**
210
- * Time Complexity: O(1)
211
- * Space Complexity: O(1)
212
- *
213
- * The isEmpty function checks if the size of the queue is 0.
214
- * @return True if the size of the queue is 0
219
+ * Check whether the trie is empty.
220
+ * @remarks Time O(1), Space O(1)
221
+ * @returns True if size is 0.
215
222
  */
216
223
  isEmpty(): boolean;
217
224
  /**
218
- * Time Complexity: O(1)
219
- * Space Complexity: O(1)
220
- *
221
- * The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
225
+ * Remove all words and reset to a fresh root.
226
+ * @remarks Time O(1), Space O(1)
227
+ * @returns void
222
228
  */
223
229
  clear(): void;
224
230
  /**
225
- * Time Complexity: O(l), where l is the length of the word being deleted.
226
- * Space Complexity: O(n) - Due to the recursive DFS approach.
227
- *
228
- * Remove a word from the Trie structure.
229
- * @param{string} word - The word to delete.
230
- * @returns {boolean} True if the word was successfully removed.
231
+ * Delete one word if present.
232
+ * @remarks Time O(L), Space O(1)
233
+ * @param word - Word to delete.
234
+ * @returns True if a word was removed.
231
235
  */
232
236
  delete(word: string): boolean;
233
237
  /**
234
- * Time Complexity: O(n)
235
- * Space Complexity: O(1)
236
- *
237
- * The function `getHeight` calculates the height of a trie data structure starting from the root
238
- * node.
239
- * @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
240
- * the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
241
- * tree and returns the maximum depth found.
238
+ * Compute the height (max depth) of the trie.
239
+ * @remarks Time O(N), Space O(H)
240
+ * @returns Maximum depth from root to a leaf.
242
241
  */
243
242
  getHeight(): number;
244
243
  /**
245
- * Time Complexity: O(l), where l is the length of the input prefix.
246
- * Space Complexity: O(1) - Constant space.
247
- *
248
- * Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
249
- * @param {string} input - The input string to check.
250
- * @returns {boolean} True if it's an absolute prefix in the Trie.
244
+ * Check whether input is a proper prefix of at least one word.
245
+ * @remarks Time O(L), Space O(1)
246
+ * @param input - String to test as prefix.
247
+ * @returns True if input is a prefix but not a full word.
251
248
  */
252
249
  hasPurePrefix(input: string): boolean;
253
250
  /**
254
- * Time Complexity: O(l), where l is the length of the input prefix.
255
- * Space Complexity: O(1) - Constant space.
256
- *
257
- * Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
258
- * @param {string} input - The input string representing the prefix to check.
259
- * @returns {boolean} True if it's a prefix in the Trie.
251
+ * Check whether any word starts with input.
252
+ * @remarks Time O(L), Space O(1)
253
+ * @param input - String to test as prefix.
254
+ * @returns True if input matches a path from root.
260
255
  */
261
256
  hasPrefix(input: string): boolean;
262
257
  /**
263
- * Time Complexity: O(n), where n is the total number of nodes in the trie.
264
- * Space Complexity: O(l), where l is the length of the input prefix.
265
- *
266
- * Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
267
- * @param {string} input - The input string representing the common prefix to check for.
268
- * @returns {boolean} True if it's a common prefix in the Trie.
258
+ * Check whether the trie’s longest common prefix equals input.
259
+ * @remarks Time O(min(H,L)), Space O(1)
260
+ * @param input - Candidate longest common prefix.
261
+ * @returns True if input equals the common prefix.
269
262
  */
270
263
  hasCommonPrefix(input: string): boolean;
271
264
  /**
272
- * Time Complexity: O(n), where n is the total number of nodes in the trie.
273
- * Space Complexity: O(l), where l is the length of the longest common prefix.
274
- *
275
- * Get the longest common prefix among all the words stored in the Trie.
276
- * @returns {string} The longest common prefix found in the Trie.
265
+ * Return the longest common prefix among all words.
266
+ * @remarks Time O(H), Space O(1)
267
+ * @returns The longest common prefix string.
277
268
  */
278
269
  getLongestCommonPrefix(): string;
279
270
  /**
280
- * Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
281
- * Space Complexity: O(w * l) - The space required for the output array.
282
- *
283
- * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
284
- * @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
285
- * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
286
- * @param {number} max - The max count of words will be found
287
- * @param isAllWhenEmptyPrefix - If true, when the prefix provided as '', returns all the words in the trie.
288
- * @returns {string[]} an array of strings.
271
+ * Collect words under a prefix up to a maximum count.
272
+ * @remarks Time O(K·L), Space O(K·L)
273
+ * @param [prefix] - Prefix to match; default empty string for root.
274
+ * @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
275
+ * @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
276
+ * @returns Array of collected words (at most max).
289
277
  */
290
278
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
291
279
  /**
292
- * Time Complexity: O(n)
293
- * Space Complexity: O(n)
294
- *
295
- * The `clone` function returns a new instance of the Trie class with the same values and case
296
- * sensitivity as the original Trie.
297
- * @returns A new instance of the Trie class is being returned.
298
- */
299
- clone(): Trie<R>;
300
- /**
301
- * Time Complexity: O(n)
302
- * Space Complexity: O(n)
303
- *
304
- * The `filter` function takes a predicate function and returns a new array containing all the
305
- * elements for which the predicate function returns true.
306
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
307
- * `word`, `index`, and `this`. It should return a boolean value indicating whether the current
308
- * element should be included in the filtered results or not.
309
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
310
- * specify the value of `this` within the `predicate` function. It is used when you want to bind a
311
- * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
312
- * @returns The `filter` method is returning an array of strings (`string[]`).
313
- */
314
- filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): Trie<R>;
315
- /**
316
- * Time Complexity: O(n)
317
- * Space Complexity: O(n)
318
- *
319
- * The `map` function creates a new Trie by applying a callback function to each element in the
320
- * current Trie.
321
- * @param callback - The callback parameter is a function that will be called for each element in the
322
- * Trie. It takes four arguments:
323
- * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
324
- * convert the raw element (`RM`) into a string representation. This can be useful if the raw element
325
- * is not already a string or if you want to customize how the element is converted into a string. If
326
- * this parameter is
327
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
328
- * specify the value of `this` within the callback function. It is used to set the context or scope
329
- * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
330
- * value of
331
- * @returns a new Trie object.
332
- */
333
- map<RM>(callback: ElementCallback<string, R, string>, toElementFn?: (rawElement: RM) => string, thisArg?: any): Trie<RM>;
334
- /**
335
- * Time Complexity: O(n)
336
- * Space Complexity: O(n)
337
- *
338
- * The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
339
- * trie data structure and yields all the paths to the end nodes.
280
+ * Deep clone this trie by iterating and inserting all words.
281
+ * @remarks Time O(ΣL), Space O(ΣL)
282
+ * @returns A new trie with the same words and options.
283
+ */
284
+ clone(): this;
285
+ /**
286
+ * Filter words into a new trie of the same class.
287
+ * @remarks Time O(ΣL), Space O(ΣL)
288
+ * @param predicate - Predicate (word, index, trie) → boolean to keep word.
289
+ * @param [thisArg] - Value for `this` inside the predicate.
290
+ * @returns A new trie containing words that satisfy the predicate.
291
+ */
292
+ filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this;
293
+ map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
294
+ /**
295
+ * Map words into a new trie (possibly different record type).
296
+ * @remarks Time O(ΣL), Space O(ΣL)
297
+ * @template EM
298
+ * @template RM
299
+ * @param callback - Mapping function (word, index, trie) newWord (string).
300
+ * @param [options] - Options for the output trie (e.g., toElementFn, caseSensitive).
301
+ * @param [thisArg] - Value for `this` inside the callback.
302
+ * @returns A new Trie constructed from mapped words.
303
+ */
304
+ map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: any): IterableElementBase<EM, RM>;
305
+ /**
306
+ * Map words into a new trie of the same element type.
307
+ * @remarks Time O(ΣL), Space O(ΣL)
308
+ * @param callback - Mapping function (word, index, trie) → string.
309
+ * @param [thisArg] - Value for `this` inside the callback.
310
+ * @returns A new trie with mapped words.
311
+ */
312
+ mapSame(callback: ElementCallback<string, R, string>, thisArg?: any): this;
313
+ /**
314
+ * (Protected) Create an empty instance of the same concrete class.
315
+ * @remarks Time O(1), Space O(1)
316
+ * @param [options] - Options forwarded to the constructor.
317
+ * @returns An empty like-kind trie instance.
318
+ */
319
+ protected _createInstance(options?: TrieOptions<R>): this;
320
+ /**
321
+ * (Protected) Create a like-kind trie and seed it from an iterable.
322
+ * @remarks Time O(ΣL), Space O(ΣL)
323
+ * @template RM
324
+ * @param [elements] - Iterable used to seed the new trie.
325
+ * @param [options] - Options forwarded to the constructor.
326
+ * @returns A like-kind Trie instance.
327
+ */
328
+ protected _createLike<RM>(elements?: Iterable<string> | Iterable<RM>, options?: TrieOptions<RM>): Trie<RM>;
329
+ /**
330
+ * (Protected) Spawn an empty like-kind trie instance.
331
+ * @remarks Time O(1), Space O(1)
332
+ * @template RM
333
+ * @param [options] - Options forwarded to the constructor.
334
+ * @returns An empty like-kind Trie instance.
335
+ */
336
+ protected _spawnLike<RM>(options?: TrieOptions<RM>): Trie<RM>;
337
+ /**
338
+ * (Protected) Iterate all words in lexicographic order of edges.
339
+ * @remarks Time O(ΣL), Space O(H)
340
+ * @returns Iterator of words.
340
341
  */
341
342
  protected _getIterator(): IterableIterator<string>;
342
- protected get _total(): number;
343
343
  /**
344
- * Time Complexity: O(l), where l is the length of the input string.
345
- * Space Complexity: O(1) - Constant space.
346
- *
347
- * @param str
348
- * @protected
344
+ * (Protected) Normalize a string according to case sensitivity.
345
+ * @remarks Time O(L), Space O(L)
346
+ * @param str - Input string to normalize.
347
+ * @returns Normalized string based on caseSensitive.
349
348
  */
350
349
  protected _caseProcess(str: string): string;
351
350
  }