tree-set-typed 2.3.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 (273) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.prettierignore +6 -0
  3. package/.prettierrc.js +16 -0
  4. package/LICENSE +21 -0
  5. package/README.md +482 -0
  6. package/coverage/clover.xml +13 -0
  7. package/coverage/coverage-final.json +96 -0
  8. package/coverage/coverage-summary.json +60 -0
  9. package/coverage/lcov-report/base.css +403 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +119 -0
  13. package/coverage/lcov-report/index.ts.html +109 -0
  14. package/coverage/lcov-report/prettify.css +1 -0
  15. package/coverage/lcov-report/prettify.js +2 -0
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +206 -0
  18. package/coverage/lcov.info +14 -0
  19. package/dist/cjs/index.cjs +12 -0
  20. package/dist/cjs/index.cjs.map +1 -0
  21. package/dist/cjs-legacy/index.cjs +12 -0
  22. package/dist/cjs-legacy/index.cjs.map +1 -0
  23. package/dist/esm/index.mjs +3 -0
  24. package/dist/esm/index.mjs.map +1 -0
  25. package/dist/esm-legacy/index.mjs +3 -0
  26. package/dist/esm-legacy/index.mjs.map +1 -0
  27. package/dist/types/common/index.d.ts +12 -0
  28. package/dist/types/constants/index.d.ts +4 -0
  29. package/dist/types/data-structures/base/index.d.ts +2 -0
  30. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  31. package/dist/types/data-structures/base/iterable-entry-base.d.ts +150 -0
  32. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  33. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -0
  34. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -0
  35. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +440 -0
  36. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -0
  37. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +807 -0
  38. package/dist/types/data-structures/binary-tree/bst.d.ts +645 -0
  39. package/dist/types/data-structures/binary-tree/index.d.ts +10 -0
  40. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +312 -0
  41. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -0
  42. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +243 -0
  43. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +333 -0
  44. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  45. package/dist/types/data-structures/graph/directed-graph.d.ts +332 -0
  46. package/dist/types/data-structures/graph/index.d.ts +4 -0
  47. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  48. package/dist/types/data-structures/graph/undirected-graph.d.ts +347 -0
  49. package/dist/types/data-structures/hash/hash-map.d.ts +428 -0
  50. package/dist/types/data-structures/hash/index.d.ts +1 -0
  51. package/dist/types/data-structures/heap/heap.d.ts +552 -0
  52. package/dist/types/data-structures/heap/index.d.ts +3 -0
  53. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  54. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  55. package/dist/types/data-structures/index.d.ts +12 -0
  56. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +437 -0
  57. package/dist/types/data-structures/linked-list/index.d.ts +3 -0
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +567 -0
  59. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  60. package/dist/types/data-structures/matrix/index.d.ts +2 -0
  61. package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
  62. package/dist/types/data-structures/matrix/navigator.d.ts +55 -0
  63. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  64. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  65. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  66. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  67. package/dist/types/data-structures/queue/deque.d.ts +459 -0
  68. package/dist/types/data-structures/queue/index.d.ts +2 -0
  69. package/dist/types/data-structures/queue/queue.d.ts +364 -0
  70. package/dist/types/data-structures/stack/index.d.ts +1 -0
  71. package/dist/types/data-structures/stack/stack.d.ts +324 -0
  72. package/dist/types/data-structures/tree/index.d.ts +1 -0
  73. package/dist/types/data-structures/tree/tree.d.ts +62 -0
  74. package/dist/types/data-structures/trie/index.d.ts +1 -0
  75. package/dist/types/data-structures/trie/trie.d.ts +412 -0
  76. package/dist/types/index.d.ts +23 -0
  77. package/dist/types/interfaces/binary-tree.d.ts +60 -0
  78. package/dist/types/interfaces/doubly-linked-list.d.ts +1 -0
  79. package/dist/types/interfaces/graph.d.ts +21 -0
  80. package/dist/types/interfaces/heap.d.ts +1 -0
  81. package/dist/types/interfaces/index.d.ts +8 -0
  82. package/dist/types/interfaces/navigator.d.ts +1 -0
  83. package/dist/types/interfaces/priority-queue.d.ts +1 -0
  84. package/dist/types/interfaces/segment-tree.d.ts +1 -0
  85. package/dist/types/interfaces/singly-linked-list.d.ts +1 -0
  86. package/dist/types/types/common.d.ts +15 -0
  87. package/dist/types/types/data-structures/base/base.d.ts +13 -0
  88. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  89. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  90. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  91. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  92. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  93. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  94. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  95. package/dist/types/types/data-structures/binary-tree/index.d.ts +9 -0
  96. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  97. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  98. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  99. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  100. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  101. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  102. package/dist/types/types/data-structures/graph/index.d.ts +3 -0
  103. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  104. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  105. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  106. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  107. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  108. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  109. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  110. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  111. package/dist/types/types/data-structures/index.d.ts +12 -0
  112. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  113. package/dist/types/types/data-structures/linked-list/index.d.ts +3 -0
  114. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  115. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  116. package/dist/types/types/data-structures/matrix/index.d.ts +2 -0
  117. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  118. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  119. package/dist/types/types/data-structures/priority-queue/index.d.ts +3 -0
  120. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  121. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  122. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  123. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  124. package/dist/types/types/data-structures/queue/index.d.ts +2 -0
  125. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  126. package/dist/types/types/data-structures/stack/index.d.ts +1 -0
  127. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  128. package/dist/types/types/data-structures/tree/index.d.ts +1 -0
  129. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  130. package/dist/types/types/data-structures/trie/index.d.ts +1 -0
  131. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  132. package/dist/types/types/index.d.ts +3 -0
  133. package/dist/types/types/utils/index.d.ts +2 -0
  134. package/dist/types/types/utils/utils.d.ts +22 -0
  135. package/dist/types/types/utils/validate-type.d.ts +19 -0
  136. package/dist/types/utils/index.d.ts +2 -0
  137. package/dist/types/utils/number.d.ts +14 -0
  138. package/dist/types/utils/utils.d.ts +209 -0
  139. package/dist/umd/red-black-tree-typed.js +14578 -0
  140. package/dist/umd/red-black-tree-typed.js.map +1 -0
  141. package/dist/umd/red-black-tree-typed.min.js +44 -0
  142. package/dist/umd/red-black-tree-typed.min.js.map +1 -0
  143. package/docs/.nojekyll +1 -0
  144. package/docs/assets/highlight.css +92 -0
  145. package/docs/assets/main.js +59 -0
  146. package/docs/assets/navigation.js +1 -0
  147. package/docs/assets/search.js +1 -0
  148. package/docs/assets/style.css +1383 -0
  149. package/docs/classes/AVLTree.html +2046 -0
  150. package/docs/classes/AVLTreeNode.html +263 -0
  151. package/docs/index.html +523 -0
  152. package/docs/modules.html +45 -0
  153. package/jest.config.js +8 -0
  154. package/package.json +113 -0
  155. package/src/common/index.ts +23 -0
  156. package/src/constants/index.ts +4 -0
  157. package/src/data-structures/base/index.ts +2 -0
  158. package/src/data-structures/base/iterable-element-base.ts +352 -0
  159. package/src/data-structures/base/iterable-entry-base.ts +246 -0
  160. package/src/data-structures/base/linear-base.ts +643 -0
  161. package/src/data-structures/binary-tree/avl-tree-counter.ts +539 -0
  162. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +438 -0
  163. package/src/data-structures/binary-tree/avl-tree.ts +840 -0
  164. package/src/data-structures/binary-tree/binary-indexed-tree.ts +331 -0
  165. package/src/data-structures/binary-tree/binary-tree.ts +2492 -0
  166. package/src/data-structures/binary-tree/bst.ts +2024 -0
  167. package/src/data-structures/binary-tree/index.ts +10 -0
  168. package/src/data-structures/binary-tree/red-black-tree.ts +767 -0
  169. package/src/data-structures/binary-tree/segment-tree.ts +324 -0
  170. package/src/data-structures/binary-tree/tree-counter.ts +575 -0
  171. package/src/data-structures/binary-tree/tree-multi-map.ts +549 -0
  172. package/src/data-structures/graph/abstract-graph.ts +1081 -0
  173. package/src/data-structures/graph/directed-graph.ts +715 -0
  174. package/src/data-structures/graph/index.ts +4 -0
  175. package/src/data-structures/graph/map-graph.ts +132 -0
  176. package/src/data-structures/graph/undirected-graph.ts +626 -0
  177. package/src/data-structures/hash/hash-map.ts +813 -0
  178. package/src/data-structures/hash/index.ts +1 -0
  179. package/src/data-structures/heap/heap.ts +1020 -0
  180. package/src/data-structures/heap/index.ts +3 -0
  181. package/src/data-structures/heap/max-heap.ts +47 -0
  182. package/src/data-structures/heap/min-heap.ts +36 -0
  183. package/src/data-structures/index.ts +12 -0
  184. package/src/data-structures/linked-list/doubly-linked-list.ts +876 -0
  185. package/src/data-structures/linked-list/index.ts +3 -0
  186. package/src/data-structures/linked-list/singly-linked-list.ts +1050 -0
  187. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  188. package/src/data-structures/matrix/index.ts +2 -0
  189. package/src/data-structures/matrix/matrix.ts +491 -0
  190. package/src/data-structures/matrix/navigator.ts +124 -0
  191. package/src/data-structures/priority-queue/index.ts +3 -0
  192. package/src/data-structures/priority-queue/max-priority-queue.ts +42 -0
  193. package/src/data-structures/priority-queue/min-priority-queue.ts +29 -0
  194. package/src/data-structures/priority-queue/priority-queue.ts +19 -0
  195. package/src/data-structures/queue/deque.ts +1001 -0
  196. package/src/data-structures/queue/index.ts +2 -0
  197. package/src/data-structures/queue/queue.ts +592 -0
  198. package/src/data-structures/stack/index.ts +1 -0
  199. package/src/data-structures/stack/stack.ts +469 -0
  200. package/src/data-structures/tree/index.ts +1 -0
  201. package/src/data-structures/tree/tree.ts +115 -0
  202. package/src/data-structures/trie/index.ts +1 -0
  203. package/src/data-structures/trie/trie.ts +756 -0
  204. package/src/index.ts +24 -0
  205. package/src/interfaces/binary-tree.ts +252 -0
  206. package/src/interfaces/doubly-linked-list.ts +1 -0
  207. package/src/interfaces/graph.ts +44 -0
  208. package/src/interfaces/heap.ts +1 -0
  209. package/src/interfaces/index.ts +8 -0
  210. package/src/interfaces/navigator.ts +1 -0
  211. package/src/interfaces/priority-queue.ts +1 -0
  212. package/src/interfaces/segment-tree.ts +1 -0
  213. package/src/interfaces/singly-linked-list.ts +1 -0
  214. package/src/types/common.ts +25 -0
  215. package/src/types/data-structures/base/base.ts +34 -0
  216. package/src/types/data-structures/base/index.ts +1 -0
  217. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  218. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -0
  219. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -0
  220. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  221. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  222. package/src/types/data-structures/binary-tree/bst.ts +19 -0
  223. package/src/types/data-structures/binary-tree/index.ts +9 -0
  224. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  225. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  226. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  227. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -0
  228. package/src/types/data-structures/graph/abstract-graph.ts +18 -0
  229. package/src/types/data-structures/graph/directed-graph.ts +2 -0
  230. package/src/types/data-structures/graph/index.ts +3 -0
  231. package/src/types/data-structures/graph/map-graph.ts +1 -0
  232. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  233. package/src/types/data-structures/hash/hash-map.ts +19 -0
  234. package/src/types/data-structures/hash/index.ts +3 -0
  235. package/src/types/data-structures/heap/heap.ts +6 -0
  236. package/src/types/data-structures/heap/index.ts +1 -0
  237. package/src/types/data-structures/heap/max-heap.ts +1 -0
  238. package/src/types/data-structures/heap/min-heap.ts +1 -0
  239. package/src/types/data-structures/index.ts +12 -0
  240. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -0
  241. package/src/types/data-structures/linked-list/index.ts +3 -0
  242. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -0
  243. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  244. package/src/types/data-structures/matrix/index.ts +2 -0
  245. package/src/types/data-structures/matrix/matrix.ts +7 -0
  246. package/src/types/data-structures/matrix/navigator.ts +14 -0
  247. package/src/types/data-structures/priority-queue/index.ts +3 -0
  248. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  249. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  250. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -0
  251. package/src/types/data-structures/queue/deque.ts +5 -0
  252. package/src/types/data-structures/queue/index.ts +2 -0
  253. package/src/types/data-structures/queue/queue.ts +5 -0
  254. package/src/types/data-structures/stack/index.ts +1 -0
  255. package/src/types/data-structures/stack/stack.ts +3 -0
  256. package/src/types/data-structures/tree/index.ts +1 -0
  257. package/src/types/data-structures/tree/tree.ts +1 -0
  258. package/src/types/data-structures/trie/index.ts +1 -0
  259. package/src/types/data-structures/trie/trie.ts +3 -0
  260. package/src/types/index.ts +3 -0
  261. package/src/types/utils/index.ts +2 -0
  262. package/src/types/utils/utils.ts +33 -0
  263. package/src/types/utils/validate-type.ts +35 -0
  264. package/src/utils/index.ts +2 -0
  265. package/src/utils/number.ts +22 -0
  266. package/src/utils/utils.ts +350 -0
  267. package/test/index.test.ts +111 -0
  268. package/tsconfig.base.json +23 -0
  269. package/tsconfig.json +12 -0
  270. package/tsconfig.test.json +8 -0
  271. package/tsconfig.types.json +15 -0
  272. package/tsup.config.js +28 -0
  273. package/tsup.node.config.js +71 -0
@@ -0,0 +1,62 @@
1
+ export declare class TreeNode<V = any> {
2
+ /**
3
+ * The constructor function initializes a TreeNode object with a key, optional value, and optional
4
+ * children.
5
+ * @param {string} key - A string representing the key of the tree node.
6
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
7
+ * value associated with the node. If no value is provided, it defaults to `undefined`.
8
+ * @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
9
+ * objects. It represents the child nodes of the current node. If no children are provided, the
10
+ * default value is an empty array.
11
+ */
12
+ constructor(key: string, value?: V, children?: TreeNode<V>[]);
13
+ protected _key: string;
14
+ /**
15
+ * The function returns the value of the protected variable _key.
16
+ * @returns The value of the `_key` property, which is a string.
17
+ */
18
+ get key(): string;
19
+ /**
20
+ * The above function sets the value of a protected variable called "key".
21
+ * @param {string} value - The value parameter is a string that represents the value to be assigned
22
+ * to the key.
23
+ */
24
+ set key(value: string);
25
+ protected _value?: V | undefined;
26
+ /**
27
+ * The function returns the value stored in a variable, or undefined if the variable is empty.
28
+ * @returns The value of the variable `_value` is being returned.
29
+ */
30
+ get value(): V | undefined;
31
+ /**
32
+ * The function sets the value of a variable.
33
+ * @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
34
+ * can accept a value of type "V" or it can be undefined.
35
+ */
36
+ set value(value: V | undefined);
37
+ protected _children?: TreeNode<V>[] | undefined;
38
+ /**
39
+ * The function returns an array of TreeNode objects or undefined.
40
+ * @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
41
+ * which means it can either be an array of `TreeNode<V>` objects or `undefined`.
42
+ */
43
+ get children(): TreeNode<V>[] | undefined;
44
+ /**
45
+ * The function sets the value of the children property of a TreeNode object.
46
+ * @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
47
+ * undefined. This means that it can accept an array of TreeNode objects or undefined.
48
+ */
49
+ set children(value: TreeNode<V>[] | undefined);
50
+ /**
51
+ * The function `addChildren` adds one or more child nodes to the current node.
52
+ * @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
53
+ * `TreeNode<V>` object or an array of `TreeNode<V>` objects.
54
+ */
55
+ addChildren(children: TreeNode<V> | TreeNode<V>[]): void;
56
+ /**
57
+ * The function `getHeight()` calculates the maximum depth of a tree structure by performing a
58
+ * breadth-first search.
59
+ * @returns the maximum depth or height of the tree.
60
+ */
61
+ getHeight(): number;
62
+ }
@@ -0,0 +1 @@
1
+ export * from './trie';
@@ -0,0 +1,412 @@
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
+ * // basic Trie creation and add words
81
+ * // Create a simple Trie with initial words
82
+ * const trie = new Trie(['apple', 'app', 'apply']);
83
+ *
84
+ * // Verify size
85
+ * console.log(trie.size); // 3;
86
+ *
87
+ * // Check if words exist
88
+ * console.log(trie.has('apple')); // true;
89
+ * console.log(trie.has('app')); // true;
90
+ *
91
+ * // Add a new word
92
+ * trie.add('application');
93
+ * console.log(trie.size); // 4;
94
+ * @example
95
+ * // Trie getWords and prefix search
96
+ * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
97
+ *
98
+ * // Get all words with prefix 'app'
99
+ * const appWords = trie.getWords('app');
100
+ * console.log(appWords); // contains 'app';
101
+ * console.log(appWords); // contains 'apple';
102
+ * console.log(appWords); // contains 'apply';
103
+ * console.log(appWords); // contains 'application';
104
+ * expect(appWords).not.toContain('apricot');
105
+ * @example
106
+ * // Trie isPrefix and isAbsolutePrefix checks
107
+ * const trie = new Trie(['tree', 'trial', 'trick', 'trip', 'trie']);
108
+ *
109
+ * // Check if string is a prefix of any word
110
+ * console.log(trie.hasPrefix('tri')); // true;
111
+ * console.log(trie.hasPrefix('tr')); // true;
112
+ * console.log(trie.hasPrefix('xyz')); // false;
113
+ *
114
+ * // Check if string is an absolute prefix (not a complete word)
115
+ * console.log(trie.hasPurePrefix('tri')); // true;
116
+ * console.log(trie.hasPurePrefix('tree')); // false; // 'tree' is a complete word
117
+ *
118
+ * // Verify size
119
+ * console.log(trie.size); // 5;
120
+ * @example
121
+ * // Trie delete and iteration
122
+ * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
123
+ *
124
+ * // Delete a word
125
+ * trie.delete('card');
126
+ * console.log(trie.has('card')); // false;
127
+ *
128
+ * // Word with same prefix still exists
129
+ * console.log(trie.has('care')); // true;
130
+ *
131
+ * // Size decreased
132
+ * console.log(trie.size); // 5;
133
+ *
134
+ * // Iterate through all words
135
+ * const allWords = [...trie];
136
+ * console.log(allWords.length); // 5;
137
+ * @example
138
+ * // Trie for autocomplete search index
139
+ * // Trie is perfect for autocomplete: O(m + k) where m is prefix length, k is results
140
+ * const searchIndex = new Trie(['typescript', 'javascript', 'python', 'java', 'rust', 'ruby', 'golang', 'kotlin']);
141
+ *
142
+ * // User types 'j' - get all suggestions
143
+ * const jResults = searchIndex.getWords('j');
144
+ * console.log(jResults); // contains 'javascript';
145
+ * console.log(jResults); // contains 'java';
146
+ * console.log(jResults.length); // 2;
147
+ *
148
+ * // User types 'ja' - get more specific suggestions
149
+ * const jaResults = searchIndex.getWords('ja');
150
+ * console.log(jaResults); // contains 'javascript';
151
+ * console.log(jaResults); // contains 'java';
152
+ * console.log(jaResults.length); // 2;
153
+ *
154
+ * // User types 'jav' - even more specific
155
+ * const javResults = searchIndex.getWords('jav');
156
+ * console.log(javResults); // contains 'javascript';
157
+ * console.log(javResults); // contains 'java';
158
+ * console.log(javResults.length); // 2;
159
+ *
160
+ * // Check for common prefix
161
+ *
162
+ * console.log(searchIndex.hasCommonPrefix('ja')); // false; // Not all words start with 'ja'
163
+ *
164
+ * // Total words in index
165
+ * console.log(searchIndex.size); // 8;
166
+ *
167
+ * // Get height (depth of tree)
168
+ * const height = searchIndex.getHeight();
169
+ * console.log(typeof height); // 'number';
170
+ * @example
171
+ * // Dictionary: Case-insensitive word lookup
172
+ * // Create a case-insensitive dictionary
173
+ * const dictionary = new Trie<string>([], { caseSensitive: false });
174
+ *
175
+ * // Add words with mixed casing
176
+ * dictionary.add('Hello');
177
+ * dictionary.add('WORLD');
178
+ * dictionary.add('JavaScript');
179
+ *
180
+ * // Test lookups with different casings
181
+ * console.log(dictionary.has('hello')); // true;
182
+ * console.log(dictionary.has('HELLO')); // true;
183
+ * console.log(dictionary.has('Hello')); // true;
184
+ * console.log(dictionary.has('javascript')); // true;
185
+ * console.log(dictionary.has('JAVASCRIPT')); // true;
186
+ * @example
187
+ * // File System Path Operations
188
+ * const fileSystem = new Trie<string>([
189
+ * '/home/user/documents/file1.txt',
190
+ * '/home/user/documents/file2.txt',
191
+ * '/home/user/pictures/photo.jpg',
192
+ * '/home/user/pictures/vacation/',
193
+ * '/home/user/downloads'
194
+ * ]);
195
+ *
196
+ * // Find common directory prefix
197
+ * console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/';
198
+ *
199
+ * // List all files in a directory
200
+ * const documentsFiles = fileSystem.getWords('/home/user/documents/');
201
+ * console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt'];
202
+ * @example
203
+ * // IP Address Routing Table
204
+ * // Add IP address prefixes and their corresponding routes
205
+ * const routes = {
206
+ * '192.168.1': 'LAN_SUBNET_1',
207
+ * '192.168.2': 'LAN_SUBNET_2',
208
+ * '10.0.0': 'PRIVATE_NETWORK_1',
209
+ * '10.0.1': 'PRIVATE_NETWORK_2'
210
+ * };
211
+ *
212
+ * const ipRoutingTable = new Trie<string>(Object.keys(routes));
213
+ *
214
+ * // Check IP address prefix matching
215
+ * console.log(ipRoutingTable.hasPrefix('192.168.1')); // true;
216
+ * console.log(ipRoutingTable.hasPrefix('192.168.2')); // true;
217
+ *
218
+ * // Validate IP address belongs to subnet
219
+ * const ip = '192.168.1.100';
220
+ * const subnet = ip.split('.').slice(0, 3).join('.');
221
+ * console.log(ipRoutingTable.hasPrefix(subnet)); // true;
222
+ */
223
+ export declare class Trie<R = any> extends IterableElementBase<string, R> {
224
+ /**
225
+ * Create a Trie and optionally bulk-insert words.
226
+ * @remarks Time O(totalChars), Space O(totalChars)
227
+ * @param [words] - Iterable of strings (or raw records if toElementFn is provided).
228
+ * @param [options] - Options such as toElementFn and caseSensitive.
229
+ * @returns New Trie instance.
230
+ */
231
+ constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
232
+ protected _size: number;
233
+ /**
234
+ * Get the number of stored words.
235
+ * @remarks Time O(1), Space O(1)
236
+ * @returns Word count.
237
+ */
238
+ get size(): number;
239
+ protected _caseSensitive: boolean;
240
+ /**
241
+ * Get whether comparisons are case-sensitive.
242
+ * @remarks Time O(1), Space O(1)
243
+ * @returns True if case-sensitive.
244
+ */
245
+ get caseSensitive(): boolean;
246
+ protected _root: TrieNode;
247
+ /**
248
+ * Get the root node.
249
+ * @remarks Time O(1), Space O(1)
250
+ * @returns Root TrieNode.
251
+ */
252
+ get root(): TrieNode;
253
+ /**
254
+ * (Protected) Get total count for base class iteration.
255
+ * @remarks Time O(1), Space O(1)
256
+ * @returns Total number of elements.
257
+ */
258
+ protected get _total(): number;
259
+ /**
260
+ * Insert one word into the trie.
261
+ * @remarks Time O(L), Space O(L)
262
+ * @param word - Word to insert.
263
+ * @returns True if the word was newly added.
264
+ */
265
+ add(word: string): boolean;
266
+ /**
267
+ * Insert many words from an iterable.
268
+ * @remarks Time O(ΣL), Space O(ΣL)
269
+ * @param words - Iterable of strings (or raw records if toElementFn is provided).
270
+ * @returns Array of per-word 'added' flags.
271
+ */
272
+ addMany(words: Iterable<string> | Iterable<R>): boolean[];
273
+ /**
274
+ * Check whether a word exists.
275
+ * @remarks Time O(L), Space O(1)
276
+ * @param word - Word to search for.
277
+ * @returns True if present.
278
+ */
279
+ has(word: string): boolean;
280
+ /**
281
+ * Check whether the trie is empty.
282
+ * @remarks Time O(1), Space O(1)
283
+ * @returns True if size is 0.
284
+ */
285
+ isEmpty(): boolean;
286
+ /**
287
+ * Remove all words and reset to a fresh root.
288
+ * @remarks Time O(1), Space O(1)
289
+ * @returns void
290
+ */
291
+ clear(): void;
292
+ /**
293
+ * Delete one word if present.
294
+ * @remarks Time O(L), Space O(1)
295
+ * @param word - Word to delete.
296
+ * @returns True if a word was removed.
297
+ */
298
+ delete(word: string): boolean;
299
+ /**
300
+ * Compute the height (max depth) of the trie.
301
+ * @remarks Time O(N), Space O(H)
302
+ * @returns Maximum depth from root to a leaf.
303
+ */
304
+ getHeight(): number;
305
+ /**
306
+ * Check whether input is a proper prefix of at least one word.
307
+ * @remarks Time O(L), Space O(1)
308
+ * @param input - String to test as prefix.
309
+ * @returns True if input is a prefix but not a full word.
310
+ */
311
+ hasPurePrefix(input: string): boolean;
312
+ /**
313
+ * Check whether any word starts with input.
314
+ * @remarks Time O(L), Space O(1)
315
+ * @param input - String to test as prefix.
316
+ * @returns True if input matches a path from root.
317
+ */
318
+ hasPrefix(input: string): boolean;
319
+ /**
320
+ * Check whether the trie’s longest common prefix equals input.
321
+ * @remarks Time O(min(H,L)), Space O(1)
322
+ * @param input - Candidate longest common prefix.
323
+ * @returns True if input equals the common prefix.
324
+ */
325
+ hasCommonPrefix(input: string): boolean;
326
+ /**
327
+ * Return the longest common prefix among all words.
328
+ * @remarks Time O(H), Space O(1)
329
+ * @returns The longest common prefix string.
330
+ */
331
+ getLongestCommonPrefix(): string;
332
+ /**
333
+ * Collect words under a prefix up to a maximum count.
334
+ * @remarks Time O(K·L), Space O(K·L)
335
+ * @param [prefix] - Prefix to match; default empty string for root.
336
+ * @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
337
+ * @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
338
+ * @returns Array of collected words (at most max).
339
+ */
340
+ getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
341
+ /**
342
+ * Deep clone this trie by iterating and inserting all words.
343
+ * @remarks Time O(ΣL), Space O(ΣL)
344
+ * @returns A new trie with the same words and options.
345
+ */
346
+ clone(): this;
347
+ /**
348
+ * Filter words into a new trie of the same class.
349
+ * @remarks Time O(ΣL), Space O(ΣL)
350
+ * @param predicate - Predicate (word, index, trie) → boolean to keep word.
351
+ * @param [thisArg] - Value for `this` inside the predicate.
352
+ * @returns A new trie containing words that satisfy the predicate.
353
+ */
354
+ filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this;
355
+ map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
356
+ /**
357
+ * Map words into a new trie (possibly different record type).
358
+ * @remarks Time O(ΣL), Space O(ΣL)
359
+ * @template EM
360
+ * @template RM
361
+ * @param callback - Mapping function (word, index, trie) → newWord (string).
362
+ * @param [options] - Options for the output trie (e.g., toElementFn, caseSensitive).
363
+ * @param [thisArg] - Value for `this` inside the callback.
364
+ * @returns A new Trie constructed from mapped words.
365
+ */
366
+ map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: any): IterableElementBase<EM, RM>;
367
+ /**
368
+ * Map words into a new trie of the same element type.
369
+ * @remarks Time O(ΣL), Space O(ΣL)
370
+ * @param callback - Mapping function (word, index, trie) → string.
371
+ * @param [thisArg] - Value for `this` inside the callback.
372
+ * @returns A new trie with mapped words.
373
+ */
374
+ mapSame(callback: ElementCallback<string, R, string>, thisArg?: any): this;
375
+ /**
376
+ * (Protected) Create an empty instance of the same concrete class.
377
+ * @remarks Time O(1), Space O(1)
378
+ * @param [options] - Options forwarded to the constructor.
379
+ * @returns An empty like-kind trie instance.
380
+ */
381
+ protected _createInstance(options?: TrieOptions<R>): this;
382
+ /**
383
+ * (Protected) Create a like-kind trie and seed it from an iterable.
384
+ * @remarks Time O(ΣL), Space O(ΣL)
385
+ * @template RM
386
+ * @param [elements] - Iterable used to seed the new trie.
387
+ * @param [options] - Options forwarded to the constructor.
388
+ * @returns A like-kind Trie instance.
389
+ */
390
+ protected _createLike<RM>(elements?: Iterable<string> | Iterable<RM>, options?: TrieOptions<RM>): Trie<RM>;
391
+ /**
392
+ * (Protected) Spawn an empty like-kind trie instance.
393
+ * @remarks Time O(1), Space O(1)
394
+ * @template RM
395
+ * @param [options] - Options forwarded to the constructor.
396
+ * @returns An empty like-kind Trie instance.
397
+ */
398
+ protected _spawnLike<RM>(options?: TrieOptions<RM>): Trie<RM>;
399
+ /**
400
+ * (Protected) Iterate all words in lexicographic order of edges.
401
+ * @remarks Time O(ΣL), Space O(H)
402
+ * @returns Iterator of words.
403
+ */
404
+ protected _getIterator(): IterableIterator<string>;
405
+ /**
406
+ * (Protected) Normalize a string according to case sensitivity.
407
+ * @remarks Time O(L), Space O(L)
408
+ * @param str - Input string to normalize.
409
+ * @returns Normalized string based on caseSensitive.
410
+ */
411
+ protected _caseProcess(str: string): string;
412
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module tree-set-typed
4
+ *
5
+ * TreeSet - A sorted set implementation based on Red-Black Tree
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { TreeSet } from 'tree-set-typed';
10
+ *
11
+ * const set = new TreeSet<number>();
12
+ * set.add(5);
13
+ * set.add(3);
14
+ * set.add(7);
15
+ *
16
+ * console.log([...set]); // [3, 5, 7] - always sorted
17
+ * console.log(set.has(5)); // true
18
+ * console.log(set.first()); // 3
19
+ * console.log(set.last()); // 7
20
+ * ```
21
+ */
22
+ export { TreeSet } from 'data-structure-typed';
23
+ export type { TreeSetOptions } from 'data-structure-typed';
@@ -0,0 +1,60 @@
1
+ import { BinaryTreeNode } from '../data-structures';
2
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types';
3
+ /**
4
+ * Public, implementation-agnostic binary tree API.
5
+ * K = key, V = value, R = raw/record used with toEntryFn (optional).
6
+ * Transforming methods like `map` use method-level generics MK/MV/MR.
7
+ */
8
+ export interface IBinaryTree<K = any, V = any, R = any> {
9
+ readonly size: number;
10
+ readonly root: BinaryTreeNode<K, V> | null | undefined;
11
+ readonly isMapMode: boolean;
12
+ iterationType: IterationType;
13
+ readonly NIL: BinaryTreeNode<K, V>;
14
+ readonly store: Map<K, V | undefined>;
15
+ readonly toEntryFn?: ToEntryFn<K, V, R>;
16
+ readonly isDuplicate: boolean;
17
+ createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
18
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
19
+ add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
20
+ set(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
21
+ addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
22
+ delete(keyNodeEntryRawOrPredicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
23
+ clear(): void;
24
+ isEmpty(): boolean;
25
+ get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
26
+ has(keyNodeEntryOrPredicate?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
27
+ hasValue(value: V): boolean;
28
+ find(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): [K, V | undefined] | undefined;
29
+ [Symbol.iterator](): IterableIterator<[K, V | undefined]>;
30
+ entries(): IterableIterator<[K, V | undefined]>;
31
+ keys(): IterableIterator<K>;
32
+ values(): IterableIterator<V | undefined>;
33
+ forEach(callbackfn: EntryCallback<K, V | undefined, void>, thisArg?: unknown): void;
34
+ every(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
35
+ some(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
36
+ reduce<U>(reducer: ReduceEntryCallback<K, V | undefined, U>, initialValue: U): U;
37
+ getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): OptNodeOrNull<BinaryTreeNode<K, V>>;
38
+ getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
39
+ getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
40
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
41
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
42
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
43
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
44
+ morris<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): ReturnType<C>[];
45
+ leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
46
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
47
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
48
+ getPathToRoot<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, callback?: C, isReverse?: boolean): ReturnType<C>[];
49
+ getDepth(dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): number;
50
+ getHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
51
+ getMinHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
52
+ isPerfectlyBalanced(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
53
+ isBST(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
54
+ search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne?: boolean, callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
55
+ clone(): this;
56
+ filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
57
+ map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): IBinaryTree<MK, MV, MR>;
58
+ merge(anotherTree: IBinaryTree<K, V, R>): void;
59
+ refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
60
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { VertexKey } from '../types';
2
+ export interface IGraph<V, E, VO, EO> {
3
+ createVertex(key: VertexKey, value?: V): VO;
4
+ createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
5
+ getVertex(vertexKey: VertexKey): VO | undefined;
6
+ hasVertex(vertexOrKey: VO | VertexKey): boolean;
7
+ addVertex(vertex: VO): boolean;
8
+ addVertex(key: VertexKey, value?: V): boolean;
9
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean;
10
+ deleteEdge(edge: EO): EO | undefined;
11
+ getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
12
+ degreeOf(vertexOrKey: VO | VertexKey): number;
13
+ edgeSet(): EO[];
14
+ edgesOf(vertexOrKey: VO | VertexKey): EO[];
15
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
16
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
17
+ isEmpty(): boolean;
18
+ clear(): void;
19
+ clone(): this;
20
+ filter(...args: any[]): this;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './graph';
2
+ export * from './binary-tree';
3
+ export * from './doubly-linked-list';
4
+ export * from './heap';
5
+ export * from './navigator';
6
+ export * from './priority-queue';
7
+ export * from './segment-tree';
8
+ export * from './singly-linked-list';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ export type CP = 1 | -1 | 0;
2
+ export type IterationType = 'ITERATIVE' | 'RECURSIVE';
3
+ export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
4
+ export type Comparator<K> = (a: K, b: K) => number;
5
+ export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
6
+ export type NodeDisplayLayout = [string[], number, number, number];
7
+ export interface IterableWithSize<T> extends Iterable<T> {
8
+ size: number | ((...args: any[]) => number);
9
+ }
10
+ export interface IterableWithLength<T> extends Iterable<T> {
11
+ length: number | ((...args: any[]) => number);
12
+ }
13
+ export type OptValue<V> = V | undefined;
14
+ export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
15
+ export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
@@ -0,0 +1,13 @@
1
+ import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
+ import { LinearBase } from '../../../data-structures/base/linear-base';
3
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
4
+ export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
5
+ export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
6
+ export type ReduceElementCallback<E, R, U = E> = (accumulator: U, value: E, index: number, self: IterableElementBase<E, R>) => U;
7
+ export type ReduceLinearCallback<E, RT = E> = (accumulator: RT, element: E, index: number, original: LinearBase<E>) => RT;
8
+ export type IterableElementBaseOptions<E, R> = {
9
+ toElementFn?: (rawElement: R) => E;
10
+ };
11
+ export type LinearBaseOptions<E, R> = IterableElementBaseOptions<E, R> & {
12
+ maxLen?: number;
13
+ };
@@ -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> & {};