min-heap-typed 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/dist/cjs/index.cjs +987 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +980 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +13 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/max-heap-typed.js +992 -0
  87. package/dist/umd/max-heap-typed.js.map +1 -0
  88. package/dist/umd/max-heap-typed.min.js +16 -0
  89. package/dist/umd/max-heap-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  93. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  94. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  95. package/src/data-structures/binary-tree/bst.ts +1 -1
  96. package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
  97. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +1 -1
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -14
  192. package/dist/index.js +0 -30
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,4 +1,350 @@
1
- import { IterableElementBaseOptions } from '../base';
2
- export type TrieOptions<R> = {
3
- caseSensitive?: boolean;
4
- } & IterableElementBaseOptions<string, R>;
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { ElementCallback, TrieOptions } from '../../types';
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
+ */
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
+ */
20
+ constructor(key: string);
21
+ protected _key: string;
22
+ /**
23
+ * Get the character key of this node.
24
+ * @remarks Time O(1), Space O(1)
25
+ * @returns Character key string.
26
+ */
27
+ get key(): string;
28
+ /**
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
33
+ */
34
+ set key(value: string);
35
+ protected _children: Map<string, TrieNode>;
36
+ /**
37
+ * Get the child map of this node.
38
+ * @remarks Time O(1), Space O(1)
39
+ * @returns Map from character to child node.
40
+ */
41
+ get children(): Map<string, TrieNode>;
42
+ /**
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
47
+ */
48
+ set children(value: Map<string, TrieNode>);
49
+ protected _isEnd: boolean;
50
+ /**
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.
54
+ */
55
+ get isEnd(): boolean;
56
+ /**
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
61
+ */
62
+ set isEnd(value: boolean);
63
+ }
64
+ /**
65
+ * Prefix tree (Trie) for fast prefix queries and word storage.
66
+ * @remarks Time O(1), Space O(1)
67
+ * @template R
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.
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'.
70
+ * 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
71
+ * 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
72
+ * 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
73
+ * 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
74
+ * 7. String Retrieval: For example, searching for a specific string in a large set of strings.
75
+ * 8. Autocomplete: Providing recommended words or phrases as a user types.
76
+ * 9. Spell Check: Checking the spelling of words.
77
+ * 10. IP Routing: Used in certain types of IP routing algorithms.
78
+ * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
79
+ * @example
80
+ * // Autocomplete: Prefix validation and checking
81
+ * const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
82
+ *
83
+ * // Get all completions for a prefix
84
+ * const gmailCompletions = autocomplete.getWords('gmail');
85
+ * console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
86
+ * @example
87
+ * // File System Path Operations
88
+ * const fileSystem = new Trie<string>([
89
+ * '/home/user/documents/file1.txt',
90
+ * '/home/user/documents/file2.txt',
91
+ * '/home/user/pictures/photo.jpg',
92
+ * '/home/user/pictures/vacation/',
93
+ * '/home/user/downloads'
94
+ * ]);
95
+ *
96
+ * // Find common directory prefix
97
+ * console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
98
+ *
99
+ * // List all files in a directory
100
+ * const documentsFiles = fileSystem.getWords('/home/user/documents/');
101
+ * console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
102
+ * @example
103
+ * // Autocomplete: Basic word suggestions
104
+ * // Create a trie for autocomplete
105
+ * const autocomplete = new Trie<string>([
106
+ * 'function',
107
+ * 'functional',
108
+ * 'functions',
109
+ * 'class',
110
+ * 'classes',
111
+ * 'classical',
112
+ * 'closure',
113
+ * 'const',
114
+ * 'constructor'
115
+ * ]);
116
+ *
117
+ * // Test autocomplete with different prefixes
118
+ * console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
119
+ * console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
120
+ * console.log(autocomplete.getWords('con')); // ['constructor', 'const']
121
+ *
122
+ * // Test with non-matching prefix
123
+ * console.log(autocomplete.getWords('xyz')); // []
124
+ * @example
125
+ * // Dictionary: Case-insensitive word lookup
126
+ * // Create a case-insensitive dictionary
127
+ * const dictionary = new Trie<string>([], { caseSensitive: false });
128
+ *
129
+ * // Add words with mixed casing
130
+ * dictionary.add('Hello');
131
+ * dictionary.add('WORLD');
132
+ * dictionary.add('JavaScript');
133
+ *
134
+ * // Test lookups with different casings
135
+ * console.log(dictionary.has('hello')); // true
136
+ * console.log(dictionary.has('HELLO')); // true
137
+ * console.log(dictionary.has('Hello')); // true
138
+ * console.log(dictionary.has('javascript')); // true
139
+ * console.log(dictionary.has('JAVASCRIPT')); // true
140
+ * @example
141
+ * // IP Address Routing Table
142
+ * // Add IP address prefixes and their corresponding routes
143
+ * const routes = {
144
+ * '192.168.1': 'LAN_SUBNET_1',
145
+ * '192.168.2': 'LAN_SUBNET_2',
146
+ * '10.0.0': 'PRIVATE_NETWORK_1',
147
+ * '10.0.1': 'PRIVATE_NETWORK_2'
148
+ * };
149
+ *
150
+ * const ipRoutingTable = new Trie<string>(Object.keys(routes));
151
+ *
152
+ * // Check IP address prefix matching
153
+ * console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
154
+ * console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
155
+ *
156
+ * // Validate IP address belongs to subnet
157
+ * const ip = '192.168.1.100';
158
+ * const subnet = ip.split('.').slice(0, 3).join('.');
159
+ * console.log(ipRoutingTable.hasPrefix(subnet)); // true
160
+ */
161
+ export declare class Trie<R = any> extends IterableElementBase<string, R> {
162
+ /**
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.
168
+ */
169
+ constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
170
+ protected _size: number;
171
+ /**
172
+ * Get the number of stored words.
173
+ * @remarks Time O(1), Space O(1)
174
+ * @returns Word count.
175
+ */
176
+ get size(): number;
177
+ protected _caseSensitive: boolean;
178
+ /**
179
+ * Get whether comparisons are case-sensitive.
180
+ * @remarks Time O(1), Space O(1)
181
+ * @returns True if case-sensitive.
182
+ */
183
+ get caseSensitive(): boolean;
184
+ protected _root: TrieNode;
185
+ /**
186
+ * Get the root node.
187
+ * @remarks Time O(1), Space O(1)
188
+ * @returns Root TrieNode.
189
+ */
190
+ get root(): TrieNode;
191
+ /**
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.
202
+ */
203
+ add(word: string): boolean;
204
+ /**
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.
209
+ */
210
+ addMany(words: Iterable<string> | Iterable<R>): boolean[];
211
+ /**
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.
216
+ */
217
+ has(word: string): boolean;
218
+ /**
219
+ * Check whether the trie is empty.
220
+ * @remarks Time O(1), Space O(1)
221
+ * @returns True if size is 0.
222
+ */
223
+ isEmpty(): boolean;
224
+ /**
225
+ * Remove all words and reset to a fresh root.
226
+ * @remarks Time O(1), Space O(1)
227
+ * @returns void
228
+ */
229
+ clear(): void;
230
+ /**
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.
235
+ */
236
+ delete(word: string): boolean;
237
+ /**
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.
241
+ */
242
+ getHeight(): number;
243
+ /**
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.
248
+ */
249
+ hasPurePrefix(input: string): boolean;
250
+ /**
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.
255
+ */
256
+ hasPrefix(input: string): boolean;
257
+ /**
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.
262
+ */
263
+ hasCommonPrefix(input: string): boolean;
264
+ /**
265
+ * Return the longest common prefix among all words.
266
+ * @remarks Time O(H), Space O(1)
267
+ * @returns The longest common prefix string.
268
+ */
269
+ getLongestCommonPrefix(): string;
270
+ /**
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).
277
+ */
278
+ getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
279
+ /**
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.
341
+ */
342
+ protected _getIterator(): IterableIterator<string>;
343
+ /**
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.
348
+ */
349
+ protected _caseProcess(str: string): string;
350
+ }
@@ -1,3 +1,14 @@
1
- export * from './data-structures';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ export * from './data-structures/heap/min-heap';
9
+ export * from './data-structures/heap/heap';
10
+ export * from './types/data-structures/heap/min-heap';
11
+ export * from './types/data-structures/heap/heap';
12
+ export * from './types/common';
13
+ export * from './types/utils';
2
14
  export * from './common';
3
- export * from './utils';
@@ -14,7 +14,7 @@ export interface IBinaryTree<K = any, V = any, R = any> {
14
14
  readonly store: Map<K, V | undefined>;
15
15
  readonly toEntryFn?: ToEntryFn<K, V, R>;
16
16
  readonly isDuplicate: boolean;
17
- _createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
17
+ createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
18
18
  createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
19
19
  add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
20
20
  addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
@@ -0,0 +1 @@
1
+ export * from './base';
@@ -0,0 +1,2 @@
1
+ import { AVLTreeOptions } from './avl-tree';
2
+ export type AVLTreeCounterOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ import type { AVLTreeOptions } from './avl-tree';
2
+ export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ import { BSTOptions } from './bst';
2
+ export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1,29 @@
1
+ import { IterationType, OptValue } from '../../common';
2
+ import { DFSOperation } from '../../../common';
3
+ export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
4
+ export type BinaryTreeOptions<K, V, R> = {
5
+ iterationType?: IterationType;
6
+ toEntryFn?: ToEntryFn<K, V, R>;
7
+ isMapMode?: boolean;
8
+ isDuplicate?: boolean;
9
+ };
10
+ export type BinaryTreePrintOptions = {
11
+ isShowUndefined?: boolean;
12
+ isShowNull?: boolean;
13
+ isShowRedBlackNIL?: boolean;
14
+ };
15
+ export type OptNodeOrNull<NODE> = NODE | null | undefined;
16
+ export type BTNOptKeyOrNull<K> = K | null | undefined;
17
+ export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
18
+ export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
19
+ export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
20
+ export type BinaryTreeDeleteResult<NODE> = {
21
+ deleted: OptNodeOrNull<NODE>;
22
+ needBalanced: OptNodeOrNull<NODE>;
23
+ };
24
+ export type NodeCallback<NODE, D = any> = (node: NODE) => D;
25
+ export type NodePredicate<NODE> = (node: NODE) => boolean;
26
+ export type DFSStackItem<NODE> = {
27
+ opt: DFSOperation;
28
+ node: OptNodeOrNull<NODE>;
29
+ };
@@ -0,0 +1,12 @@
1
+ import type { BinaryTreeOptions } from './binary-tree';
2
+ import { Comparable } from '../../utils';
3
+ import { OptValue } from '../../common';
4
+ export type BSTOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'> & {
5
+ specifyComparable?: (key: K) => Comparable;
6
+ isReverse?: boolean;
7
+ };
8
+ export type BSTNOptKey<K> = K | undefined;
9
+ export type OptNode<NODE> = NODE | undefined;
10
+ export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
11
+ export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
12
+ export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
@@ -1,10 +1,9 @@
1
1
  export * from './binary-tree';
2
2
  export * from './bst';
3
- export * from './binary-indexed-tree';
4
- export * from './segment-tree';
5
3
  export * from './avl-tree';
6
- export * from './red-black-tree';
4
+ export * from './segment-tree';
7
5
  export * from './avl-tree-multi-map';
6
+ export * from './red-black-tree';
8
7
  export * from './tree-multi-map';
9
8
  export * from './tree-counter';
10
9
  export * from './avl-tree-counter';
@@ -0,0 +1,3 @@
1
+ import type { BSTOptions } from './bst';
2
+ export type RBTNColor = 'RED' | 'BLACK';
3
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1 @@
1
+ export type SegmentTreeNodeVal = number;
@@ -0,0 +1,2 @@
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
+ export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
+ export type TreeMultiMapOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -0,0 +1,14 @@
1
+ export type VertexKey = string | number;
2
+ export type DijkstraResult<V> = {
3
+ distMap: Map<V, number>;
4
+ distPaths?: Map<V, V[]>;
5
+ preMap: Map<V, V | undefined>;
6
+ seen: Set<V>;
7
+ paths: V[][];
8
+ minDist: number;
9
+ minPath: V[];
10
+ } | undefined;
11
+ export type GraphOptions<V = any> = {
12
+ vertexValueInitializer?: (key: VertexKey) => V;
13
+ defaultEdgeWeight?: number;
14
+ };
@@ -0,0 +1 @@
1
+ export type TopologicalStatus = 0 | 1 | 2;
@@ -1,4 +1,3 @@
1
1
  export * from './abstract-graph';
2
- export * from './directed-graph';
3
- export * from './undirected-graph';
4
2
  export * from './map-graph';
3
+ export * from './directed-graph';
@@ -0,0 +1 @@
1
+ export type MapGraphCoordinate = [number, number];
@@ -0,0 +1,19 @@
1
+ export type HashMapLinkedNode<K, V> = {
2
+ key: K;
3
+ value: V;
4
+ next: HashMapLinkedNode<K, V>;
5
+ prev: HashMapLinkedNode<K, V>;
6
+ };
7
+ export type LinkedHashMapOptions<K, V, R> = {
8
+ hashFn?: (key: K) => string;
9
+ objHashFn?: (key: K) => object;
10
+ toEntryFn?: (rawElement: R) => [K, V];
11
+ };
12
+ export type HashMapOptions<K, V, R> = {
13
+ hashFn?: (key: K) => string;
14
+ toEntryFn?: (rawElement: R) => [K, V];
15
+ };
16
+ export type HashMapStoreItem<K, V> = {
17
+ key: K;
18
+ value: V;
19
+ };
@@ -0,0 +1,2 @@
1
+ export * from './hash-map';
2
+ export type HashFunction<K> = (key: K) => number;
@@ -0,0 +1,5 @@
1
+ import { Comparator } from '../../common';
2
+ import { IterableElementBaseOptions } from '../base';
3
+ export type HeapOptions<E, R> = IterableElementBaseOptions<E, R> & {
4
+ comparator?: Comparator<E>;
5
+ };
@@ -0,0 +1 @@
1
+ export * from './heap';
@@ -0,0 +1,2 @@
1
+ import { LinearBaseOptions } from '../base';
2
+ export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -0,0 +1,2 @@
1
+ import { LinearBaseOptions } from '../base';
2
+ export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -0,0 +1,4 @@
1
+ export type SkipLinkedListOptions = {
2
+ maxLevel?: number;
3
+ probability?: number;
4
+ };
@@ -0,0 +1,7 @@
1
+ export type MatrixOptions = {
2
+ rows?: number;
3
+ cols?: number;
4
+ addFn?: (a: number, b: number) => any;
5
+ subtractFn?: (a: number, b: number) => any;
6
+ multiplyFn?: (a: number, b: number) => any;
7
+ };
@@ -0,0 +1,14 @@
1
+ export type Direction = 'up' | 'right' | 'down' | 'left';
2
+ export type Turning = {
3
+ [key in Direction]: Direction;
4
+ };
5
+ export type NavigatorParams<T = any> = {
6
+ matrix: T[][];
7
+ turning: Turning;
8
+ onMove: (cur: [number, number]) => void;
9
+ init: {
10
+ cur: [number, number];
11
+ charDir: Direction;
12
+ VISITED: T;
13
+ };
14
+ };
@@ -0,0 +1,2 @@
1
+ import { HeapOptions } from '../heap';
2
+ export type PriorityQueueOptions<E, R> = HeapOptions<E, R> & {};
@@ -0,0 +1,4 @@
1
+ import { LinearBaseOptions } from '../base';
2
+ export type DequeOptions<E, R> = {
3
+ bucketSize?: number;
4
+ } & LinearBaseOptions<E, R>;
@@ -0,0 +1,4 @@
1
+ import { LinearBaseOptions } from '../base';
2
+ export type QueueOptions<E, R> = LinearBaseOptions<E, R> & {
3
+ autoCompactRatio?: number;
4
+ };
@@ -0,0 +1,2 @@
1
+ import { IterableElementBaseOptions } from '../base';
2
+ export type StackOptions<E, R> = IterableElementBaseOptions<E, R> & {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { IterableElementBaseOptions } from '../base';
2
+ export type TrieOptions<R> = {
3
+ caseSensitive?: boolean;
4
+ } & IterableElementBaseOptions<string, R>;
@@ -0,0 +1,3 @@
1
+ export * from './data-structures';
2
+ export * from './common';
3
+ export * from './utils';
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ export * from './validate-type';