data-structure-typed 1.18.6 → 1.18.8

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 (262) hide show
  1. package/README.md +154 -366
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +72 -51
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +226 -158
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +7 -6
  5. package/dist/data-structures/binary-tree/avl-tree.js +5 -3
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +16 -6
  7. package/dist/data-structures/binary-tree/binary-tree.js +16 -7
  8. package/dist/data-structures/binary-tree/bst.d.ts +37 -28
  9. package/dist/data-structures/binary-tree/bst.js +44 -76
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
  11. package/dist/data-structures/binary-tree/rb-tree.js +27 -14
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +18 -7
  13. package/dist/data-structures/binary-tree/tree-multiset.js +20 -15
  14. package/dist/data-structures/graph/abstract-graph.d.ts +28 -27
  15. package/dist/data-structures/graph/abstract-graph.js +58 -36
  16. package/dist/data-structures/graph/directed-graph.d.ts +27 -24
  17. package/dist/data-structures/graph/directed-graph.js +65 -60
  18. package/dist/data-structures/graph/undirected-graph.d.ts +12 -18
  19. package/dist/data-structures/graph/undirected-graph.js +52 -65
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +100 -0
  21. package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
  22. package/dist/data-structures/interfaces/abstract-graph.d.ts +3 -8
  23. package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
  24. package/dist/data-structures/interfaces/binary-tree.d.ts +4 -24
  25. package/dist/data-structures/interfaces/bst.d.ts +18 -1
  26. package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
  27. package/dist/data-structures/interfaces/index.d.ts +1 -1
  28. package/dist/data-structures/interfaces/index.js +1 -1
  29. package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
  30. package/dist/data-structures/interfaces/rb-tree.js +2 -0
  31. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  32. package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
  33. package/dist/data-structures/tree/tree.d.ts +1 -4
  34. package/dist/data-structures/tree/tree.js +1 -12
  35. package/dist/data-structures/types/abstract-binary-tree.d.ts +11 -7
  36. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  37. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  38. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  39. package/dist/data-structures/types/bst.d.ts +1 -1
  40. package/dist/data-structures/types/bst.js +1 -1
  41. package/dist/data-structures/types/directed-graph.js +1 -1
  42. package/dist/data-structures/types/helpers.d.ts +1 -8
  43. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  44. package/dist/data-structures/types/rb-tree.js +1 -1
  45. package/dist/data-structures/types/tree-multiset.d.ts +4 -4
  46. package/dist/utils/types/utils.d.ts +18 -0
  47. package/dist/utils/utils.d.ts +6 -1
  48. package/dist/utils/utils.js +83 -1
  49. package/package.json +2 -2
  50. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  51. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  52. package/backup/recursive-type/src/assets/logo.png +0 -0
  53. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  54. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  55. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  56. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  57. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  59. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  60. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  64. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  65. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  66. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  67. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  68. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  69. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  70. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  71. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  86. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  87. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  88. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  90. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  91. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  92. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  93. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  96. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  97. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  98. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  99. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  100. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  101. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  102. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  103. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  104. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  105. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  106. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  108. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  109. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  114. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  115. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  116. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  117. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  118. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  119. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  120. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  121. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  122. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  123. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  124. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  125. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  126. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  127. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  128. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  129. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  130. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  131. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  132. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  133. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  134. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  135. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  136. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  137. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  138. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  139. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  140. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  141. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  142. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  143. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  144. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  145. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  146. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  147. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  149. package/backup/recursive-type/src/index.ts +0 -1
  150. package/backup/recursive-type/src/utils/index.ts +0 -2
  151. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  152. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  153. package/backup/recursive-type/src/utils/utils.ts +0 -78
  154. package/docs/.nojekyll +0 -1
  155. package/docs/assets/highlight.css +0 -92
  156. package/docs/assets/main.js +0 -58
  157. package/docs/assets/search.js +0 -1
  158. package/docs/assets/style.css +0 -1367
  159. package/docs/classes/AVLTree.html +0 -2339
  160. package/docs/classes/AVLTreeNode.html +0 -450
  161. package/docs/classes/AaTree.html +0 -166
  162. package/docs/classes/AbstractBinaryTree.html +0 -2023
  163. package/docs/classes/AbstractBinaryTreeNode.html +0 -491
  164. package/docs/classes/AbstractEdge.html +0 -289
  165. package/docs/classes/AbstractGraph.html +0 -1046
  166. package/docs/classes/AbstractVertex.html +0 -252
  167. package/docs/classes/ArrayDeque.html +0 -433
  168. package/docs/classes/BST.html +0 -2196
  169. package/docs/classes/BSTNode.html +0 -453
  170. package/docs/classes/BTree.html +0 -166
  171. package/docs/classes/BinaryIndexedTree.html +0 -335
  172. package/docs/classes/BinaryTree.html +0 -2037
  173. package/docs/classes/BinaryTreeNode.html +0 -452
  174. package/docs/classes/Character.html +0 -214
  175. package/docs/classes/CoordinateMap.html +0 -477
  176. package/docs/classes/CoordinateSet.html +0 -438
  177. package/docs/classes/Deque.html +0 -969
  178. package/docs/classes/DirectedEdge.html +0 -360
  179. package/docs/classes/DirectedGraph.html +0 -1408
  180. package/docs/classes/DirectedVertex.html +0 -248
  181. package/docs/classes/DoublyLinkedList.html +0 -962
  182. package/docs/classes/DoublyLinkedListNode.html +0 -291
  183. package/docs/classes/HashTable.html +0 -166
  184. package/docs/classes/Heap.html +0 -417
  185. package/docs/classes/HeapItem.html +0 -249
  186. package/docs/classes/Matrix2D.html +0 -496
  187. package/docs/classes/MatrixNTI2D.html +0 -234
  188. package/docs/classes/MaxHeap.html +0 -430
  189. package/docs/classes/MaxPriorityQueue.html +0 -830
  190. package/docs/classes/MinHeap.html +0 -431
  191. package/docs/classes/MinPriorityQueue.html +0 -832
  192. package/docs/classes/Navigator.html +0 -307
  193. package/docs/classes/ObjectDeque.html +0 -449
  194. package/docs/classes/Pair.html +0 -166
  195. package/docs/classes/PriorityQueue.html +0 -754
  196. package/docs/classes/Queue.html +0 -386
  197. package/docs/classes/SegmentTree.html +0 -428
  198. package/docs/classes/SegmentTreeNode.html +0 -351
  199. package/docs/classes/SinglyLinkedList.html +0 -782
  200. package/docs/classes/SinglyLinkedListNode.html +0 -264
  201. package/docs/classes/SkipLinkedList.html +0 -166
  202. package/docs/classes/SplayTree.html +0 -166
  203. package/docs/classes/Stack.html +0 -362
  204. package/docs/classes/TreeMap.html +0 -166
  205. package/docs/classes/TreeMultiSet.html +0 -2196
  206. package/docs/classes/TreeMultiSetNode.html +0 -450
  207. package/docs/classes/TreeNode.html +0 -337
  208. package/docs/classes/TreeSet.html +0 -166
  209. package/docs/classes/Trie.html +0 -366
  210. package/docs/classes/TrieNode.html +0 -274
  211. package/docs/classes/TwoThreeTree.html +0 -166
  212. package/docs/classes/UndirectedEdge.html +0 -331
  213. package/docs/classes/UndirectedGraph.html +0 -1196
  214. package/docs/classes/UndirectedVertex.html +0 -248
  215. package/docs/classes/Vector2D.html +0 -799
  216. package/docs/enums/CP.html +0 -175
  217. package/docs/enums/FamilyPosition.html +0 -175
  218. package/docs/enums/LoopType.html +0 -176
  219. package/docs/enums/RBColor.html +0 -168
  220. package/docs/enums/TopologicalProperty.html +0 -175
  221. package/docs/index.html +0 -639
  222. package/docs/interfaces/IBinaryTree.html +0 -189
  223. package/docs/interfaces/IBinaryTreeNode.html +0 -396
  224. package/docs/interfaces/IDirectedGraph.html +0 -259
  225. package/docs/interfaces/IGraph.html +0 -471
  226. package/docs/interfaces/IUNDirectedGraph.html +0 -151
  227. package/docs/modules.html +0 -250
  228. package/docs/types/AVLTreeOptions.html +0 -144
  229. package/docs/types/AbstractBinaryTreeOptions.html +0 -150
  230. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -146
  231. package/docs/types/AbstractResultByProperty.html +0 -146
  232. package/docs/types/AbstractResultsByProperty.html +0 -146
  233. package/docs/types/BSTComparator.html +0 -156
  234. package/docs/types/BSTOptions.html +0 -146
  235. package/docs/types/BinaryTreeDeletedResult.html +0 -153
  236. package/docs/types/BinaryTreeNodeId.html +0 -141
  237. package/docs/types/BinaryTreeNodePropertyName.html +0 -141
  238. package/docs/types/BinaryTreeOptions.html +0 -144
  239. package/docs/types/DFSOrderPattern.html +0 -141
  240. package/docs/types/DijkstraResult.html +0 -161
  241. package/docs/types/Direction.html +0 -141
  242. package/docs/types/EdgeId.html +0 -141
  243. package/docs/types/HeapOptions.html +0 -162
  244. package/docs/types/IdObject.html +0 -151
  245. package/docs/types/KeyValObject.html +0 -146
  246. package/docs/types/NavigatorParams.html +0 -175
  247. package/docs/types/NodeOrPropertyName.html +0 -141
  248. package/docs/types/PriorityQueueComparator.html +0 -161
  249. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -141
  250. package/docs/types/PriorityQueueOptions.html +0 -155
  251. package/docs/types/RBTreeOptions.html +0 -144
  252. package/docs/types/RecursiveAVLTreeNode.html +0 -146
  253. package/docs/types/RecursiveBSTNode.html +0 -146
  254. package/docs/types/RecursiveBinaryTreeNode.html +0 -146
  255. package/docs/types/RecursiveTreeMultiSetNode.html +0 -146
  256. package/docs/types/SegmentTreeNodeVal.html +0 -141
  257. package/docs/types/TopologicalStatus.html +0 -141
  258. package/docs/types/TreeMultiSetOptions.html +0 -146
  259. package/docs/types/Turning.html +0 -141
  260. package/docs/types/VertexId.html +0 -141
  261. package/notes/bst.test.ts +0 -181
  262. package/notes/note.md +0 -34
@@ -1,227 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class TrieNode {
9
-
10
- constructor(v: string) {
11
- this._val = v;
12
- this._isEnd = false;
13
- this._children = new Map<string, TrieNode>();
14
- }
15
-
16
- private _val;
17
-
18
- get val(): string {
19
- return this._val;
20
- }
21
-
22
- set val(v: string) {
23
- this._val = v;
24
- }
25
-
26
- protected _children: Map<string, TrieNode>;
27
-
28
- get children(): Map<string, TrieNode> {
29
- return this._children;
30
- }
31
-
32
- set children(v: Map<string, TrieNode>) {
33
- this._children = v;
34
- }
35
-
36
- protected _isEnd: boolean;
37
-
38
- get isEnd(): boolean {
39
- return this._isEnd;
40
- }
41
-
42
- set isEnd(v: boolean) {
43
- this._isEnd = v;
44
- }
45
-
46
- }
47
-
48
- export class Trie {
49
- constructor(words?: string[]) {
50
- this._root = new TrieNode('');
51
- if (words) {
52
- for (const i of words) {
53
- this.add(i);
54
- }
55
- }
56
- }
57
-
58
- protected _root: TrieNode;
59
-
60
- get root() {
61
- return this._root;
62
- }
63
-
64
- set root(v: TrieNode) {
65
- this._root = v;
66
- }
67
-
68
- add(word: string): boolean {
69
- let cur = this._root;
70
- for (const c of word) {
71
- let nodeC = cur.children.get(c);
72
- if (!nodeC) {
73
- nodeC = new TrieNode(c);
74
- cur.children.set(c, nodeC);
75
- }
76
- cur = nodeC;
77
- }
78
- cur.isEnd = true;
79
- return true;
80
- }
81
-
82
- has(input: string): boolean {
83
- let cur = this._root;
84
- for (const c of input) {
85
- const nodeC = cur.children.get(c);
86
- if (!nodeC) return false;
87
- cur = nodeC;
88
- }
89
- return cur.isEnd;
90
- }
91
-
92
- remove(word: string) {
93
- let isDeleted = false;
94
- const dfs = (cur: TrieNode, i: number): boolean => {
95
- const char = word[i];
96
- const child = cur.children.get(char);
97
- if (child) {
98
- if (i === word.length - 1) {
99
- if (child.isEnd) {
100
- if (child.children.size > 0) {
101
- child.isEnd = false;
102
- } else {
103
- cur.children.delete(char);
104
- }
105
- isDeleted = true;
106
- return true;
107
- }
108
- return false;
109
- }
110
- const res = dfs(child, i + 1);
111
- if (res && !cur.isEnd && child.children.size === 0) {
112
- cur.children.delete(char);
113
- return true;
114
- }
115
- return false;
116
- }
117
- return false;
118
- }
119
-
120
- dfs(this.root, 0);
121
- return isDeleted;
122
- }
123
-
124
- // --- start additional methods ---
125
- /**
126
- * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
127
- * @param {string} input - The input parameter is a string that represents the input value for the function.
128
- * @returns a boolean value.
129
- */
130
- isAbsPrefix(input: string): boolean {
131
- let cur = this._root;
132
- for (const c of input) {
133
- const nodeC = cur.children.get(c);
134
- if (!nodeC) return false;
135
- cur = nodeC;
136
- }
137
- return !cur.isEnd;
138
- }
139
-
140
- /**
141
- * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
142
- * @param {string} input - The input parameter is a string that represents the prefix we want to check.
143
- * @returns a boolean value.
144
- */
145
- isPrefix(input: string): boolean {
146
- let cur = this._root;
147
- for (const c of input) {
148
- const nodeC = cur.children.get(c);
149
- if (!nodeC) return false;
150
- cur = nodeC;
151
- }
152
- return true;
153
- }
154
-
155
- /**
156
- * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
157
- * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
158
- * in the Trie data structure.
159
- * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
160
- */
161
- isCommonPrefix(input: string): boolean {
162
- let commonPre = '';
163
- const dfs = (cur: TrieNode) => {
164
- commonPre += cur.val;
165
- if (commonPre === input) return;
166
- if (cur.isEnd) return;
167
- if (cur && cur.children && cur.children.size === 1) dfs(Array.from(cur.children.values())[0]);
168
- else return;
169
- }
170
- dfs(this._root);
171
- return commonPre === input;
172
- }
173
-
174
- /**
175
- * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
176
- * structure.
177
- * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
178
- * Trie.
179
- */
180
- getLongestCommonPrefix(): string {
181
- let commonPre = '';
182
- const dfs = (cur: TrieNode) => {
183
- commonPre += cur.val;
184
- if (cur.isEnd) return;
185
- if (cur && cur.children && cur.children.size === 1) dfs(Array.from(cur.children.values())[0]);
186
- else return;
187
- }
188
- dfs(this._root);
189
- return commonPre;
190
- }
191
-
192
- /**
193
- * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
194
- * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
195
- * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
196
- * @returns an array of strings.
197
- */
198
- getAll(prefix = ''): string[] {
199
- const words: string[] = [];
200
-
201
- function dfs(node: TrieNode, word: string) {
202
- for (const char of node.children.keys()) {
203
- const charNode = node.children.get(char);
204
- if (charNode !== undefined) {
205
- dfs(charNode, word.concat(char));
206
- }
207
- }
208
- if (node.isEnd) {
209
- words.push(word);
210
- }
211
- }
212
-
213
- let startNode = this._root;
214
-
215
- if (prefix) {
216
- for (const c of prefix) {
217
- const nodeC = startNode.children.get(c);
218
- if (nodeC) startNode = nodeC;
219
- }
220
- }
221
-
222
- dfs(startNode, prefix);
223
- return words;
224
- }
225
-
226
- // --- end additional methods ---
227
- }
@@ -1,5 +0,0 @@
1
- export type VertexId = string | number;
2
- export type EdgeId = string;
3
- export type DijkstraResult<V> =
4
- { distMap: Map<V, number>, preMap: Map<V, V | null>, seen: Set<V>, paths: V[][], minDist: number, minPath: V[] }
5
- | null;
@@ -1,8 +0,0 @@
1
- import {AVLTreeNode} from '../binary-tree';
2
-
3
- export type AVLTreeDeleted<N> = {
4
- deleted: N | null;
5
- needBalanced: N | null;
6
- }
7
-
8
- export type RecursiveAVLTreeNode<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T,AVLTreeNode<T,AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -1,10 +0,0 @@
1
- import {BinaryTreeNode} from '../binary-tree';
2
-
3
- export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
4
- export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
5
- export type DFSOrderPattern = 'in' | 'pre' | 'post';
6
- export type BinaryTreeNodeId = number;
7
- export type BinaryTreeDeleted<N> = { deleted: N | null | undefined, needBalanced: N | null };
8
- export type ResultByProperty<N extends BinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
9
- export type ResultsByProperty<N extends BinaryTreeNode<N['val'], N>> = ResultByProperty<N>[];
10
- export type RecursiveBinaryTreeNode<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T,BinaryTreeNode<T,BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -1,6 +0,0 @@
1
- import {BSTNode} from '../binary-tree';
2
- import type {BinaryTreeNodeId} from './binary-tree';
3
-
4
- export type BSTComparator = (a: BinaryTreeNodeId, b: BinaryTreeNodeId) => number;
5
- export type BSTDeletedResult<N extends BSTNode<N['val'], N>> = { deleted: N | null, needBalanced: N | null };
6
- export type RecursiveBSTNode<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T,BSTNode<T,BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@@ -1,8 +0,0 @@
1
- // 0 means unknown, 1 means visiting, 2 means visited;
2
- export type TopologicalStatus = 0 | 1 | 2;
3
-
4
- export enum TopologicalProperty {
5
- VAL = 'VAL',
6
- NODE = 'NODE',
7
- ID = 'ID',
8
- }
@@ -1,5 +0,0 @@
1
- export type HeapOptions<T> = {
2
- priority?: (element: T) => number;
3
- // TODO there is an idea that support chaining which is for conveniently using the data structure
4
- // isChaining? : boolean
5
- }
@@ -1,12 +0,0 @@
1
- export * from './binary-tree';
2
- export * from './bst';
3
- export * from './avl-tree';
4
- export * from './segment-tree';
5
- export * from './tree-multiset';
6
- export * from './abstract-graph';
7
- export * from './directed-graph';
8
- export * from './priority-queue';
9
- export * from './heap';
10
- export * from './singly-linked-list';
11
- export * from './doubly-linked-list';
12
- export * from './navigator';
@@ -1,13 +0,0 @@
1
- export type Direction = 'up' | 'right' | 'down' | 'left';
2
- export type Turning = { [key in Direction]: Direction };
3
-
4
- export type NavigatorParams<T> = {
5
- matrix: T[][],
6
- turning: Turning,
7
- onMove: (cur: [number, number]) => void
8
- init: {
9
- cur: [number, number],
10
- charDir: Direction,
11
- VISITED: T,
12
- }
13
- }
@@ -1,9 +0,0 @@
1
- export type PriorityQueueComparator<T> = (a: T, b: T) => number;
2
-
3
- export type PriorityQueueOptions<T> = {
4
- nodes?: T[];
5
- isFix?: boolean;
6
- comparator: PriorityQueueComparator<T>;
7
- }
8
-
9
- export type PriorityQueueDFSOrderPattern = 'pre' | 'in' | 'post';
@@ -1 +0,0 @@
1
- export type SegmentTreeNodeVal = number;
@@ -1 +0,0 @@
1
- export type TreeMultiSetDeletedResult<N> = { deleted: N | null, needBalanced: N | null };
@@ -1 +0,0 @@
1
- export * from './data-structures';
@@ -1,2 +0,0 @@
1
- export * from './utils';
2
- export * from './types';
@@ -1 +0,0 @@
1
- export * from './utils';
@@ -1,6 +0,0 @@
1
- export type ToThunkFn = () => ReturnType<TrlFn>;
2
- export type Thunk = () => ReturnType<ToThunkFn> & { __THUNK__: Symbol };
3
- export type TrlFn = (...args: any[]) => any;
4
- export type TrlAsyncFn = (...args: any[]) => any;
5
-
6
- export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -1,78 +0,0 @@
1
- export const uuidV4 = function () {
2
- return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
3
- const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
4
- return v.toString(16);
5
- });
6
- };
7
-
8
- export const arrayRemove = function <T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean): T[] {
9
- let i = -1, len = array ? array.length : 0;
10
- const result = [];
11
-
12
- while (++i < len) {
13
- const value = array[i];
14
- if (predicate(value, i, array)) {
15
- result.push(value);
16
- Array.prototype.splice.call(array, i--, 1);
17
- len--;
18
- }
19
- }
20
-
21
- return result;
22
- };
23
-
24
-
25
- /**
26
- * data-structure-typed
27
- *
28
- * @author Tyler Zeng
29
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
30
- * @license MIT License
31
- */
32
- import type {Thunk, ToThunkFn, TrlAsyncFn, TrlFn} from './types';
33
-
34
- export const THUNK_SYMBOL = Symbol('thunk')
35
-
36
- export const isThunk = (fnOrValue: any) => {
37
- return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === THUNK_SYMBOL
38
- }
39
-
40
- export const toThunk = (fn: ToThunkFn): Thunk => {
41
- const thunk = () => fn()
42
- thunk.__THUNK__ = THUNK_SYMBOL
43
- return thunk
44
- }
45
-
46
- export const trampoline = (fn: TrlFn) => {
47
- const cont = (...args: [...Parameters<TrlFn>]) => toThunk(() => fn(...args))
48
-
49
- return Object.assign(
50
- (...args: [...Parameters<TrlFn>]) => {
51
- let result = fn(...args)
52
-
53
- while (isThunk(result) && typeof result === 'function') {
54
- result = result()
55
- }
56
-
57
- return result
58
- },
59
- {cont}
60
- )
61
- }
62
-
63
- export const trampolineAsync = (fn: TrlAsyncFn) => {
64
- const cont = (...args: [...Parameters<TrlAsyncFn>]) => toThunk(() => fn(...args))
65
-
66
- return Object.assign(
67
- async (...args: [...Parameters<TrlAsyncFn>]) => {
68
- let result = await fn(...args)
69
-
70
- while (isThunk(result) && typeof result === 'function') {
71
- result = await result()
72
- }
73
-
74
- return result
75
- },
76
- {cont}
77
- )
78
- }
package/docs/.nojekyll DELETED
@@ -1 +0,0 @@
1
- TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -1,92 +0,0 @@
1
- :root {
2
- --light-hl-0: #795E26;
3
- --dark-hl-0: #DCDCAA;
4
- --light-hl-1: #000000;
5
- --dark-hl-1: #D4D4D4;
6
- --light-hl-2: #A31515;
7
- --dark-hl-2: #CE9178;
8
- --light-hl-3: #AF00DB;
9
- --dark-hl-3: #C586C0;
10
- --light-hl-4: #001080;
11
- --dark-hl-4: #9CDCFE;
12
- --light-hl-5: #0000FF;
13
- --dark-hl-5: #569CD6;
14
- --light-hl-6: #0070C1;
15
- --dark-hl-6: #4FC1FF;
16
- --light-hl-7: #098658;
17
- --dark-hl-7: #B5CEA8;
18
- --light-hl-8: #267F99;
19
- --dark-hl-8: #4EC9B0;
20
- --light-hl-9: #008000;
21
- --dark-hl-9: #6A9955;
22
- --light-code-background: #FFFFFF;
23
- --dark-code-background: #1E1E1E;
24
- }
25
-
26
- @media (prefers-color-scheme: light) { :root {
27
- --hl-0: var(--light-hl-0);
28
- --hl-1: var(--light-hl-1);
29
- --hl-2: var(--light-hl-2);
30
- --hl-3: var(--light-hl-3);
31
- --hl-4: var(--light-hl-4);
32
- --hl-5: var(--light-hl-5);
33
- --hl-6: var(--light-hl-6);
34
- --hl-7: var(--light-hl-7);
35
- --hl-8: var(--light-hl-8);
36
- --hl-9: var(--light-hl-9);
37
- --code-background: var(--light-code-background);
38
- } }
39
-
40
- @media (prefers-color-scheme: dark) { :root {
41
- --hl-0: var(--dark-hl-0);
42
- --hl-1: var(--dark-hl-1);
43
- --hl-2: var(--dark-hl-2);
44
- --hl-3: var(--dark-hl-3);
45
- --hl-4: var(--dark-hl-4);
46
- --hl-5: var(--dark-hl-5);
47
- --hl-6: var(--dark-hl-6);
48
- --hl-7: var(--dark-hl-7);
49
- --hl-8: var(--dark-hl-8);
50
- --hl-9: var(--dark-hl-9);
51
- --code-background: var(--dark-code-background);
52
- } }
53
-
54
- :root[data-theme='light'] {
55
- --hl-0: var(--light-hl-0);
56
- --hl-1: var(--light-hl-1);
57
- --hl-2: var(--light-hl-2);
58
- --hl-3: var(--light-hl-3);
59
- --hl-4: var(--light-hl-4);
60
- --hl-5: var(--light-hl-5);
61
- --hl-6: var(--light-hl-6);
62
- --hl-7: var(--light-hl-7);
63
- --hl-8: var(--light-hl-8);
64
- --hl-9: var(--light-hl-9);
65
- --code-background: var(--light-code-background);
66
- }
67
-
68
- :root[data-theme='dark'] {
69
- --hl-0: var(--dark-hl-0);
70
- --hl-1: var(--dark-hl-1);
71
- --hl-2: var(--dark-hl-2);
72
- --hl-3: var(--dark-hl-3);
73
- --hl-4: var(--dark-hl-4);
74
- --hl-5: var(--dark-hl-5);
75
- --hl-6: var(--dark-hl-6);
76
- --hl-7: var(--dark-hl-7);
77
- --hl-8: var(--dark-hl-8);
78
- --hl-9: var(--dark-hl-9);
79
- --code-background: var(--dark-code-background);
80
- }
81
-
82
- .hl-0 { color: var(--hl-0); }
83
- .hl-1 { color: var(--hl-1); }
84
- .hl-2 { color: var(--hl-2); }
85
- .hl-3 { color: var(--hl-3); }
86
- .hl-4 { color: var(--hl-4); }
87
- .hl-5 { color: var(--hl-5); }
88
- .hl-6 { color: var(--hl-6); }
89
- .hl-7 { color: var(--hl-7); }
90
- .hl-8 { color: var(--hl-8); }
91
- .hl-9 { color: var(--hl-9); }
92
- pre, code { background: var(--code-background); }