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
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
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
+
23
+ export { TreeSet } from 'data-structure-typed';
24
+ export type { TreeSetOptions } from 'data-structure-typed';
@@ -0,0 +1,252 @@
1
+ import { BinaryTreeNode } from '../data-structures';
2
+ import type {
3
+ BinaryTreeDeleteResult,
4
+ BinaryTreeOptions,
5
+ BTNRep,
6
+ DFSOrderPattern,
7
+ EntryCallback,
8
+ IterationType,
9
+ NodeCallback,
10
+ NodePredicate,
11
+ OptNodeOrNull,
12
+ ReduceEntryCallback,
13
+ ToEntryFn
14
+ } from '../types';
15
+
16
+ /**
17
+ * Public, implementation-agnostic binary tree API.
18
+ * K = key, V = value, R = raw/record used with toEntryFn (optional).
19
+ * Transforming methods like `map` use method-level generics MK/MV/MR.
20
+ */
21
+ export interface IBinaryTree<K = any, V = any, R = any> {
22
+ // ---- state ----
23
+ readonly size: number;
24
+ readonly root: BinaryTreeNode<K, V> | null | undefined;
25
+ readonly isMapMode: boolean;
26
+ // NOTE: iterationType is mutable on the class; remove readonly here to match
27
+ iterationType: IterationType;
28
+ // Extra public state/getters implemented by BinaryTree (useful to callers)
29
+ readonly NIL: BinaryTreeNode<K, V>;
30
+ readonly store: Map<K, V | undefined>;
31
+ readonly toEntryFn?: ToEntryFn<K, V, R>;
32
+ readonly isDuplicate: boolean;
33
+
34
+ // ---- construction / mutation ----
35
+ createNode(key: K, value?: BinaryTreeNode<K, V>['value']): BinaryTreeNode<K, V>;
36
+
37
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R>;
38
+
39
+ add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
40
+
41
+ set(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
42
+
43
+ // Accept raw R as well (when toEntryFn is configured)
44
+ addMany(
45
+ keysNodesEntriesOrRaws: Iterable<
46
+ K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
47
+ >,
48
+ values?: Iterable<V | undefined>
49
+ ): boolean[];
50
+
51
+ // Accept BTNRep, predicate, or raw R for deletion
52
+ delete(
53
+ keyNodeEntryRawOrPredicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>
54
+ ): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
55
+
56
+ clear(): void;
57
+
58
+ isEmpty(): boolean;
59
+
60
+ // ---- query / read ----
61
+
62
+ // Widen `get` to support entry and optional traversal context (matches impl)
63
+ get(
64
+ keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
65
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
66
+ iterationType?: IterationType
67
+ ): V | undefined;
68
+
69
+ // `has` also supports node/entry/predicate and optional traversal context
70
+ has(
71
+ keyNodeEntryOrPredicate?:
72
+ | K
73
+ | BinaryTreeNode<K, V>
74
+ | [K | null | undefined, V | undefined]
75
+ | null
76
+ | undefined
77
+ | NodePredicate<BinaryTreeNode<K, V> | null>,
78
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
79
+ iterationType?: IterationType
80
+ ): boolean;
81
+
82
+ hasValue(value: V): boolean;
83
+
84
+ find(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): [K, V | undefined] | undefined;
85
+
86
+ // ---- iteration ----
87
+ [Symbol.iterator](): IterableIterator<[K, V | undefined]>;
88
+
89
+ entries(): IterableIterator<[K, V | undefined]>;
90
+
91
+ keys(): IterableIterator<K>;
92
+
93
+ values(): IterableIterator<V | undefined>;
94
+
95
+ forEach(callbackfn: EntryCallback<K, V | undefined, void>, thisArg?: unknown): void;
96
+
97
+ every(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
98
+
99
+ some(callbackfn: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): boolean;
100
+
101
+ reduce<U>(reducer: ReduceEntryCallback<K, V | undefined, U>, initialValue: U): U;
102
+
103
+ // ---- node access / extremes ----
104
+ getNode(
105
+ keyNodeEntryOrPredicate:
106
+ | K
107
+ | BinaryTreeNode<K, V>
108
+ | [K | null | undefined, V | undefined]
109
+ | null
110
+ | undefined
111
+ | NodePredicate<BinaryTreeNode<K, V> | null>,
112
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
113
+ iterationType?: IterationType
114
+ ): OptNodeOrNull<BinaryTreeNode<K, V>>;
115
+
116
+ getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(
117
+ callback?: C,
118
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
119
+ iterationType?: IterationType
120
+ ): ReturnType<C>;
121
+
122
+ getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(
123
+ callback?: C,
124
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
125
+ iterationType?: IterationType
126
+ ): ReturnType<C>;
127
+
128
+ // ---- traversal ----
129
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
130
+ callback?: C,
131
+ pattern?: DFSOrderPattern,
132
+ onlyOne?: boolean,
133
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
134
+ iterationType?: IterationType
135
+ ): ReturnType<C>[];
136
+
137
+ dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
138
+ callback?: C,
139
+ pattern?: DFSOrderPattern,
140
+ onlyOne?: boolean,
141
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
142
+ iterationType?: IterationType,
143
+ includeNull?: boolean
144
+ ): ReturnType<C>[];
145
+
146
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(
147
+ callback?: C,
148
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
149
+ iterationType?: IterationType,
150
+ includeNull?: false
151
+ ): ReturnType<C>[];
152
+
153
+ bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
154
+ callback?: C,
155
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
156
+ iterationType?: IterationType,
157
+ includeNull?: true
158
+ ): ReturnType<C>[];
159
+
160
+ morris<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
161
+ callback?: C,
162
+ pattern?: DFSOrderPattern,
163
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
164
+ ): ReturnType<C>[];
165
+
166
+ leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
167
+ callback?: C,
168
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
169
+ iterationType?: IterationType
170
+ ): ReturnType<C>[];
171
+
172
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(
173
+ callback?: C,
174
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
175
+ iterationType?: IterationType,
176
+ includeNull?: false
177
+ ): ReturnType<C>[][];
178
+
179
+ listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
180
+ callback?: C,
181
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
182
+ iterationType?: IterationType,
183
+ includeNull?: true
184
+ ): ReturnType<C>[][];
185
+
186
+ getPathToRoot<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(
187
+ beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
188
+ callback?: C,
189
+ isReverse?: boolean
190
+ ): ReturnType<C>[];
191
+
192
+ // ---- metrics & validation ----
193
+ getDepth(
194
+ dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
195
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
196
+ ): number;
197
+
198
+ getHeight(
199
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
200
+ iterationType?: IterationType
201
+ ): number;
202
+
203
+ getMinHeight(
204
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
205
+ iterationType?: IterationType
206
+ ): number;
207
+
208
+ isPerfectlyBalanced(
209
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
210
+ ): boolean;
211
+
212
+ isBST(
213
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
214
+ iterationType?: IterationType
215
+ ): boolean;
216
+
217
+ // ---- search helpers ----
218
+ search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(
219
+ keyNodeEntryOrPredicate:
220
+ | K
221
+ | BinaryTreeNode<K, V>
222
+ | [K | null | undefined, V | undefined]
223
+ | null
224
+ | undefined
225
+ | NodePredicate<BinaryTreeNode<K, V> | null>,
226
+ onlyOne?: boolean,
227
+ callback?: C,
228
+ startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
229
+ iterationType?: IterationType
230
+ ): ReturnType<C>[];
231
+
232
+ // ---- immutable transforms ----
233
+ clone(): this;
234
+
235
+ filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
236
+
237
+ map<MK = K, MV = V, MR = any>(
238
+ callback: EntryCallback<K, V | undefined, [MK, MV]>,
239
+ options?: Partial<BinaryTreeOptions<MK, MV, MR>>,
240
+ thisArg?: unknown
241
+ ): IBinaryTree<MK, MV, MR>;
242
+
243
+ // ---- bulk / interop ----
244
+ merge(anotherTree: IBinaryTree<K, V, R>): void;
245
+
246
+ refill(
247
+ keysNodesEntriesOrRaws: Iterable<
248
+ K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
249
+ >,
250
+ values?: Iterable<V | undefined>
251
+ ): void;
252
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { VertexKey } from '../types';
2
+
3
+ export interface IGraph<V, E, VO, EO> {
4
+ // Vertex factories
5
+ createVertex(key: VertexKey, value?: V): VO;
6
+
7
+ // Edge factories
8
+ createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
9
+
10
+ // Core vertex ops
11
+ getVertex(vertexKey: VertexKey): VO | undefined;
12
+
13
+ hasVertex(vertexOrKey: VO | VertexKey): boolean;
14
+
15
+ addVertex(vertex: VO): boolean;
16
+
17
+ addVertex(key: VertexKey, value?: V): boolean;
18
+
19
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean;
20
+
21
+ // Core edge ops
22
+ deleteEdge(edge: EO): EO | undefined;
23
+
24
+ getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
25
+
26
+ degreeOf(vertexOrKey: VO | VertexKey): number;
27
+
28
+ edgeSet(): EO[];
29
+
30
+ edgesOf(vertexOrKey: VO | VertexKey): EO[];
31
+
32
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
33
+
34
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
35
+
36
+ // Container-like ops
37
+ isEmpty(): boolean;
38
+
39
+ clear(): void;
40
+
41
+ clone(): this;
42
+
43
+ filter(...args: any[]): this;
44
+ }
@@ -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,25 @@
1
+ export type CP = 1 | -1 | 0;
2
+
3
+ export type IterationType = 'ITERATIVE' | 'RECURSIVE';
4
+
5
+ export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
6
+
7
+ export type Comparator<K> = (a: K, b: K) => number;
8
+
9
+ export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
10
+
11
+ export type NodeDisplayLayout = [string[], number, number, number];
12
+
13
+ export interface IterableWithSize<T> extends Iterable<T> {
14
+ size: number | ((...args: any[]) => number);
15
+ }
16
+
17
+ export interface IterableWithLength<T> extends Iterable<T> {
18
+ length: number | ((...args: any[]) => number);
19
+ }
20
+
21
+ export type OptValue<V> = V | undefined;
22
+
23
+ export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
24
+
25
+ export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
@@ -0,0 +1,34 @@
1
+ import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
+ import { LinearBase } from '../../../data-structures/base/linear-base';
3
+
4
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
5
+ export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
6
+ export type ReduceEntryCallback<K, V, R> = (
7
+ accumulator: R,
8
+ value: V,
9
+ key: K,
10
+ index: number,
11
+ original: IterableEntryBase<K, V>
12
+ ) => R;
13
+
14
+ export type ReduceElementCallback<E, R, U = E> = (
15
+ accumulator: U,
16
+ value: E,
17
+ index: number,
18
+ self: IterableElementBase<E, R>
19
+ ) => U;
20
+
21
+ export type ReduceLinearCallback<E, RT = E> = (
22
+ accumulator: RT,
23
+ element: E,
24
+ index: number,
25
+ original: LinearBase<E>
26
+ ) => RT;
27
+
28
+ export type IterableElementBaseOptions<E, R> = {
29
+ toElementFn?: (rawElement: R) => E;
30
+ };
31
+
32
+ export type LinearBaseOptions<E, R> = IterableElementBaseOptions<E, R> & {
33
+ maxLen?: number;
34
+ };
@@ -0,0 +1 @@
1
+ export * from './base';
@@ -0,0 +1,3 @@
1
+ import { AVLTreeOptions } from './avl-tree';
2
+
3
+ export type AVLTreeCounterOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
@@ -0,0 +1,3 @@
1
+ import type { AVLTreeOptions } from './avl-tree';
2
+
3
+ export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {}
@@ -0,0 +1,3 @@
1
+ import { BSTOptions } from './bst';
2
+
3
+ export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1,31 @@
1
+ import { IterationType, OptValue } from '../../common';
2
+ import { DFSOperation } from '../../../common';
3
+
4
+ export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
5
+
6
+ export type BinaryTreeOptions<K, V, R> = {
7
+ iterationType?: IterationType;
8
+ toEntryFn?: ToEntryFn<K, V, R>;
9
+ isMapMode?: boolean;
10
+ isDuplicate?: boolean;
11
+ }
12
+
13
+ export type BinaryTreePrintOptions = { isShowUndefined?: boolean; isShowNull?: boolean; isShowRedBlackNIL?: boolean };
14
+
15
+ export type OptNodeOrNull<NODE> = NODE | null | undefined;
16
+
17
+ export type BTNOptKeyOrNull<K> = K | null | undefined;
18
+
19
+ export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
20
+
21
+ export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
22
+
23
+ export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
24
+
25
+ export type BinaryTreeDeleteResult<NODE> = { deleted: OptNodeOrNull<NODE>; needBalanced: OptNodeOrNull<NODE> };
26
+
27
+ export type NodeCallback<NODE, D = any> = (node: NODE) => D;
28
+
29
+ export type NodePredicate<NODE> = (node: NODE) => boolean;
30
+
31
+ export type DFSStackItem<NODE> = { opt: DFSOperation; node: OptNodeOrNull<NODE> }
@@ -0,0 +1,19 @@
1
+ import type { BinaryTreeOptions } from './binary-tree';
2
+ import type { Comparator, OptValue } from '../../common';
3
+
4
+ type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
5
+
6
+ export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
7
+ comparator?: Comparator<K>;
8
+ }
9
+
10
+ export type BSTNOptKey<K> = K | undefined;
11
+
12
+ export type OptNode<NODE> = NODE | undefined;
13
+
14
+ export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
15
+
16
+ export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
17
+
18
+ export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
19
+
@@ -0,0 +1,9 @@
1
+ export * from './binary-tree';
2
+ export * from './bst';
3
+ export * from './avl-tree';
4
+ export * from './segment-tree';
5
+ export * from './avl-tree-multi-map';
6
+ export * from './red-black-tree';
7
+ export * from './tree-multi-map';
8
+ export * from './tree-counter';
9
+ export * from './avl-tree-counter';
@@ -0,0 +1,5 @@
1
+ import type { BSTOptions } from './bst';
2
+
3
+ export type RBTNColor = 'RED' | 'BLACK';
4
+
5
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1 @@
1
+ export type SegmentTreeNodeVal = number;
@@ -0,0 +1,3 @@
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
+
3
+ export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -0,0 +1,3 @@
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
+
3
+ export type TreeMultiMapOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {}
@@ -0,0 +1,18 @@
1
+ export type VertexKey = string | number;
2
+
3
+ export type DijkstraResult<V> =
4
+ | {
5
+ distMap: Map<V, number>;
6
+ distPaths?: Map<V, V[]>;
7
+ preMap: Map<V, V | undefined>;
8
+ seen: Set<V>;
9
+ paths: V[][];
10
+ minDist: number;
11
+ minPath: V[];
12
+ }
13
+ | undefined;
14
+
15
+ export type GraphOptions<V = any> = {
16
+ vertexValueInitializer?: (key: VertexKey) => V;
17
+ defaultEdgeWeight?: number;
18
+ };
@@ -0,0 +1,2 @@
1
+ // 0 means unknown, 1 means visiting, 2 means visited;
2
+ export type TopologicalStatus = 0 | 1 | 2;
@@ -0,0 +1,3 @@
1
+ export * from './abstract-graph';
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
+
8
+ export type LinkedHashMapOptions<K, V, R> = {
9
+ hashFn?: (key: K) => string;
10
+ objHashFn?: (key: K) => object;
11
+ toEntryFn?: (rawElement: R) => [K, V];
12
+ };
13
+
14
+ export type HashMapOptions<K, V, R> = {
15
+ hashFn?: (key: K) => string;
16
+ toEntryFn?: (rawElement: R) => [K, V];
17
+ };
18
+
19
+ export type HashMapStoreItem<K, V> = { key: K; value: V };
@@ -0,0 +1,3 @@
1
+ export * from './hash-map';
2
+
3
+ export type HashFunction<K> = (key: K) => number;
@@ -0,0 +1,6 @@
1
+ import { Comparator } from '../../common';
2
+ import { IterableElementBaseOptions } from '../base';
3
+
4
+ export type HeapOptions<E, R> = IterableElementBaseOptions<E, R> & {
5
+ comparator?: Comparator<E>;
6
+ };
@@ -0,0 +1 @@
1
+ export * from './heap';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export * from './binary-tree';
2
+ export * from './graph';
3
+ export * from './linked-list';
4
+ export * from './heap';
5
+ export * from './matrix';
6
+ export * from './hash';
7
+ export * from './priority-queue';
8
+ export * from './queue';
9
+ export * from './stack';
10
+ export * from './tree';
11
+ export * from './trie';
12
+ export * from './base';
@@ -0,0 +1,3 @@
1
+ import { LinearBaseOptions } from '../base';
2
+
3
+ export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -0,0 +1,3 @@
1
+ export * from './singly-linked-list';
2
+ export * from './doubly-linked-list';
3
+ export * from './skip-linked-list';
@@ -0,0 +1,3 @@
1
+ import { LinearBaseOptions } from '../base';
2
+
3
+ export type SinglyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
@@ -0,0 +1 @@
1
+ export type SkipLinkedListOptions = { maxLevel?: number; probability?: number };
@@ -0,0 +1,2 @@
1
+ export * from './navigator';
2
+ export * from './matrix';
@@ -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
+
3
+ export type Turning = { [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,3 @@
1
+ export * from './priority-queue';
2
+ export * from './min-priority-queue';
3
+ export * from './max-priority-queue';