data-structure-typed 0.8.18 → 1.12.9

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 (287) hide show
  1. package/.dependency-cruiser.js +449 -0
  2. package/.idea/data-structure-typed.iml +2 -0
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +298 -2
  5. package/dist/data-structures/binary-tree/aa-tree.js +5 -2
  6. package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
  7. package/dist/data-structures/binary-tree/avl-tree.js +150 -46
  8. package/dist/data-structures/binary-tree/b-tree.js +5 -2
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
  12. package/dist/data-structures/binary-tree/binary-tree.js +747 -369
  13. package/dist/data-structures/binary-tree/bst.d.ts +20 -8
  14. package/dist/data-structures/binary-tree/bst.js +164 -107
  15. package/dist/data-structures/binary-tree/rb-tree.js +5 -2
  16. package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
  17. package/dist/data-structures/binary-tree/segment-tree.js +95 -61
  18. package/dist/data-structures/binary-tree/splay-tree.js +5 -2
  19. package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
  20. package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
  21. package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
  22. package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
  23. package/dist/data-structures/graph/abstract-graph.js +712 -323
  24. package/dist/data-structures/graph/directed-graph.d.ts +114 -12
  25. package/dist/data-structures/graph/directed-graph.js +372 -128
  26. package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
  27. package/dist/data-structures/graph/undirected-graph.js +233 -81
  28. package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
  29. package/dist/data-structures/hash/coordinate-map.js +70 -20
  30. package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
  31. package/dist/data-structures/hash/coordinate-set.js +58 -15
  32. package/dist/data-structures/hash/index.d.ts +5 -0
  33. package/dist/data-structures/hash/index.js +5 -0
  34. package/dist/data-structures/heap/heap.d.ts +26 -37
  35. package/dist/data-structures/heap/heap.js +56 -60
  36. package/dist/data-structures/heap/max-heap.d.ts +8 -2
  37. package/dist/data-structures/heap/max-heap.js +32 -9
  38. package/dist/data-structures/heap/min-heap.d.ts +9 -2
  39. package/dist/data-structures/heap/min-heap.js +33 -9
  40. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
  41. package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
  42. package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
  43. package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
  44. package/dist/data-structures/matrix/matrix.d.ts +9 -0
  45. package/dist/data-structures/matrix/matrix.js +19 -7
  46. package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
  47. package/dist/data-structures/matrix/matrix2d.js +158 -61
  48. package/dist/data-structures/matrix/navigator.d.ts +34 -16
  49. package/dist/data-structures/matrix/navigator.js +65 -18
  50. package/dist/data-structures/matrix/vector2d.d.ts +153 -29
  51. package/dist/data-structures/matrix/vector2d.js +249 -102
  52. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
  53. package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
  54. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
  55. package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
  56. package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
  57. package/dist/data-structures/priority-queue/priority-queue.js +285 -116
  58. package/dist/data-structures/queue/deque.d.ts +69 -0
  59. package/dist/data-structures/queue/deque.js +151 -56
  60. package/dist/data-structures/queue/queue.d.ts +34 -37
  61. package/dist/data-structures/queue/queue.js +59 -61
  62. package/dist/data-structures/stack/stack.d.ts +29 -35
  63. package/dist/data-structures/stack/stack.js +51 -56
  64. package/dist/data-structures/trie/trie.d.ts +36 -6
  65. package/dist/data-structures/trie/trie.js +256 -83
  66. package/dist/data-structures/types/abstract-graph.d.ts +29 -0
  67. package/dist/data-structures/types/abstract-graph.js +2 -0
  68. package/dist/data-structures/types/avl-tree.d.ts +5 -0
  69. package/dist/data-structures/types/avl-tree.js +2 -0
  70. package/dist/data-structures/types/binary-tree.d.ts +16 -0
  71. package/dist/data-structures/types/binary-tree.js +2 -0
  72. package/dist/data-structures/types/bst.d.ts +7 -0
  73. package/dist/data-structures/types/bst.js +2 -0
  74. package/dist/data-structures/types/directed-graph.d.ts +10 -0
  75. package/dist/data-structures/types/directed-graph.js +2 -0
  76. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
  77. package/dist/data-structures/types/doubly-linked-list.js +2 -0
  78. package/dist/data-structures/types/heap.d.ts +7 -0
  79. package/dist/data-structures/types/heap.js +2 -0
  80. package/dist/data-structures/types/index.d.ts +13 -0
  81. package/dist/data-structures/types/index.js +29 -0
  82. package/dist/data-structures/types/navigator.d.ts +14 -0
  83. package/dist/data-structures/types/navigator.js +2 -0
  84. package/dist/data-structures/types/priority-queue.d.ts +7 -0
  85. package/dist/data-structures/types/priority-queue.js +2 -0
  86. package/dist/data-structures/types/segment-tree.d.ts +1 -0
  87. package/dist/data-structures/types/segment-tree.js +2 -0
  88. package/dist/data-structures/types/singly-linked-list.js +2 -0
  89. package/dist/data-structures/types/tree-multiset.d.ts +5 -0
  90. package/dist/data-structures/types/tree-multiset.js +2 -0
  91. package/dist/utils/trampoline.d.ts +14 -0
  92. package/dist/utils/trampoline.js +130 -0
  93. package/dist/utils/types/index.js +17 -0
  94. package/dist/{types → utils}/types/utils.d.ts +15 -1
  95. package/dist/{types → utils/types}/utils.js +21 -19
  96. package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
  97. package/dist/utils/utils.js +651 -0
  98. package/docs/.nojekyll +1 -0
  99. package/docs/assets/highlight.css +85 -0
  100. package/docs/assets/main.js +58 -0
  101. package/docs/assets/search.js +1 -0
  102. package/docs/assets/style.css +1367 -0
  103. package/docs/classes/AVLTree.html +2046 -0
  104. package/docs/classes/AVLTreeNode.html +423 -0
  105. package/docs/classes/AaTree.html +117 -0
  106. package/docs/classes/AbstractEdge.html +198 -0
  107. package/docs/classes/AbstractGraph.html +891 -0
  108. package/docs/classes/AbstractVertex.html +164 -0
  109. package/docs/classes/ArrayDeque.html +384 -0
  110. package/docs/classes/BST.html +1893 -0
  111. package/docs/classes/BSTNode.html +425 -0
  112. package/docs/classes/BTree.html +117 -0
  113. package/docs/classes/BinaryIndexedTree.html +244 -0
  114. package/docs/classes/BinaryTree.html +1754 -0
  115. package/docs/classes/BinaryTreeNode.html +396 -0
  116. package/docs/classes/Character.html +165 -0
  117. package/docs/classes/CoordinateMap.html +394 -0
  118. package/docs/classes/CoordinateSet.html +355 -0
  119. package/docs/classes/Deque.html +617 -0
  120. package/docs/classes/DirectedEdge.html +247 -0
  121. package/docs/classes/DirectedGraph.html +1207 -0
  122. package/docs/classes/DirectedVertex.html +154 -0
  123. package/docs/classes/DoublyLinkedList.html +619 -0
  124. package/docs/classes/DoublyLinkedListNode.html +160 -0
  125. package/docs/classes/Heap.html +315 -0
  126. package/docs/classes/Matrix2D.html +447 -0
  127. package/docs/classes/MatrixNTI2D.html +181 -0
  128. package/docs/classes/MaxHeap.html +325 -0
  129. package/docs/classes/MaxPriorityQueue.html +668 -0
  130. package/docs/classes/MinHeap.html +326 -0
  131. package/docs/classes/MinPriorityQueue.html +668 -0
  132. package/docs/classes/Navigator.html +285 -0
  133. package/docs/classes/ObjectDeque.html +289 -0
  134. package/docs/classes/PriorityQueue.html +643 -0
  135. package/docs/classes/Queue.html +337 -0
  136. package/docs/classes/RBTree.html +117 -0
  137. package/docs/classes/SegmentTree.html +234 -0
  138. package/docs/classes/SegmentTreeNode.html +302 -0
  139. package/docs/classes/SinglyLinkedList.html +1035 -0
  140. package/docs/classes/SinglyLinkedListNode.html +304 -0
  141. package/docs/classes/SplayTree.html +117 -0
  142. package/docs/classes/Stack.html +313 -0
  143. package/docs/classes/TreeMultiSet.html +1897 -0
  144. package/docs/classes/Trie.html +317 -0
  145. package/docs/classes/TrieNode.html +221 -0
  146. package/docs/classes/TwoThreeTree.html +117 -0
  147. package/docs/classes/UndirectedEdge.html +220 -0
  148. package/docs/classes/UndirectedGraph.html +1006 -0
  149. package/docs/classes/UndirectedVertex.html +154 -0
  150. package/docs/classes/Vector2D.html +746 -0
  151. package/docs/enums/CP.html +126 -0
  152. package/docs/enums/FamilyPosition.html +126 -0
  153. package/docs/enums/LoopType.html +119 -0
  154. package/docs/index.html +288 -0
  155. package/docs/modules.html +146 -0
  156. package/jest.config.js +5 -0
  157. package/package.json +33 -47
  158. package/rename_clear_files.sh +29 -0
  159. package/src/assets/complexities-diff.jpg +0 -0
  160. package/src/assets/data-structure-complexities.jpg +0 -0
  161. package/src/data-structures/binary-tree/avl-tree.ts +58 -6
  162. package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
  163. package/src/data-structures/binary-tree/binary-tree.ts +460 -145
  164. package/src/data-structures/binary-tree/bst.ts +31 -25
  165. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  166. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  167. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  168. package/src/data-structures/binary-tree/segment-tree.ts +25 -12
  169. package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
  170. package/src/data-structures/diagrams/README.md +5 -0
  171. package/src/data-structures/graph/abstract-graph.ts +224 -108
  172. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  173. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  174. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  175. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  176. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  177. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  178. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  179. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  180. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  181. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  182. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  183. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  184. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  185. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  186. package/src/data-structures/graph/directed-graph.ts +132 -26
  187. package/src/data-structures/graph/undirected-graph.ts +78 -11
  188. package/src/data-structures/hash/coordinate-map.ts +33 -1
  189. package/src/data-structures/hash/coordinate-set.ts +25 -0
  190. package/src/data-structures/hash/index.ts +5 -0
  191. package/src/data-structures/heap/heap.ts +27 -41
  192. package/src/data-structures/heap/max-heap.ts +8 -2
  193. package/src/data-structures/heap/min-heap.ts +9 -2
  194. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
  195. package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
  196. package/src/data-structures/matrix/matrix.ts +11 -0
  197. package/src/data-structures/matrix/matrix2d.ts +90 -10
  198. package/src/data-structures/matrix/navigator.ts +34 -14
  199. package/src/data-structures/matrix/vector2d.ts +187 -63
  200. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
  201. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
  202. package/src/data-structures/priority-queue/priority-queue.ts +200 -78
  203. package/src/data-structures/queue/deque.ts +71 -2
  204. package/src/data-structures/queue/queue.ts +37 -40
  205. package/src/data-structures/stack/stack.ts +32 -38
  206. package/src/data-structures/trie/trie.ts +83 -14
  207. package/src/data-structures/types/abstract-graph.ts +51 -0
  208. package/src/data-structures/types/avl-tree.ts +6 -0
  209. package/src/data-structures/types/binary-tree.ts +15 -0
  210. package/src/data-structures/types/bst.ts +5 -0
  211. package/src/data-structures/types/directed-graph.ts +18 -0
  212. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  213. package/src/data-structures/types/heap.ts +8 -0
  214. package/src/data-structures/types/index.ts +13 -0
  215. package/src/data-structures/types/navigator.ts +13 -0
  216. package/src/data-structures/types/priority-queue.ts +9 -0
  217. package/src/data-structures/types/segment-tree.ts +1 -0
  218. package/src/data-structures/types/singly-linked-list.ts +1 -0
  219. package/src/data-structures/types/tree-multiset.ts +3 -0
  220. package/src/utils/index.ts +1 -0
  221. package/src/utils/trampoline.ts +51 -0
  222. package/src/utils/types/index.ts +1 -0
  223. package/src/{types → utils/types}/utils.ts +27 -5
  224. package/src/{utils.ts → utils/utils.ts} +41 -131
  225. package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
  226. package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
  227. package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
  228. package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
  229. package/tsconfig.json +9 -6
  230. package/dist/data-structures/trampoline.d.ts +0 -25
  231. package/dist/data-structures/trampoline.js +0 -52
  232. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  233. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  234. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  235. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  236. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  237. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  238. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  239. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  240. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  241. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  242. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  243. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  244. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  245. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  246. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  247. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  248. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  249. package/dist/types/data-structures/hash/index.d.ts +0 -1
  250. package/dist/types/data-structures/hash/pair.d.ts +0 -1
  251. package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
  252. package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
  253. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  254. package/dist/types/data-structures/heap/index.d.ts +0 -3
  255. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  256. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  257. package/dist/types/data-structures/index.d.ts +0 -9
  258. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  259. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  260. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  261. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
  262. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  263. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  264. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  265. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  266. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  267. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  268. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  269. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  270. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  271. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  272. package/dist/types/data-structures/queue/index.d.ts +0 -1
  273. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  274. package/dist/types/data-structures/stack/index.d.ts +0 -1
  275. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  276. package/dist/types/data-structures/trampoline.d.ts +0 -25
  277. package/dist/types/data-structures/trie/index.d.ts +0 -1
  278. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  279. package/dist/types/utils.d.ts +0 -46
  280. package/dist/utils.js +0 -569
  281. package/src/data-structures/trampoline.ts +0 -91
  282. package/src/types/index.ts +0 -1
  283. /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
  284. /package/dist/{types → utils}/index.d.ts +0 -0
  285. /package/dist/{types → utils}/index.js +0 -0
  286. /package/dist/{types → utils}/types/index.d.ts +0 -0
  287. /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
@@ -1,59 +0,0 @@
1
- export declare class DoublyLinkedListNode<T> {
2
- val: T;
3
- next: DoublyLinkedListNode<T> | null;
4
- prev: DoublyLinkedListNode<T> | null;
5
- constructor(nodeValue: T);
6
- }
7
- export type DoublyLinkedListGetBy = 'node' | 'val';
8
- export declare class DoublyLinkedList<T> {
9
- private _first;
10
- private _last;
11
- private _size;
12
- get size(): number;
13
- set size(v: number);
14
- /**
15
- * Adds a node at the beginning of the linked list
16
- * @param val Value to be stored at the beginning of the linked list
17
- */
18
- offerFirst(val: T): boolean;
19
- /**
20
- * Adds a node to the end of the linked list
21
- * @param val Value to be stored in the Doubly linked list node
22
- */
23
- offerLast(val: T): boolean;
24
- peekFirst(): T | null;
25
- peekFirst(by: 'val'): T | null;
26
- peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
27
- peekLast(): T | null;
28
- peekLast(by: 'val'): T | null;
29
- peekLast(by: 'node'): DoublyLinkedListNode<T> | null;
30
- pollFirst(): T | null;
31
- pollFirst(by: 'val'): T | null;
32
- pollFirst(by: 'node'): DoublyLinkedListNode<T> | null;
33
- pollLast(): T | null;
34
- pollLast(by: 'val'): T | null;
35
- pollLast(by: 'node'): DoublyLinkedListNode<T> | null;
36
- get(index: number): T | null;
37
- get(index: number, by: 'node'): DoublyLinkedListNode<T> | null;
38
- get(index: number, by: 'val'): T | null;
39
- /**
40
- * Updates the value of the node at the specified index.
41
- * If index = 0; Value of the first element in the list is updated.
42
- * If index = 3; Value of the fourth element in the list is updated.
43
- * @param index Index of the node to be updated
44
- * @param val New value of the node
45
- */
46
- set(index: number, val: T): boolean;
47
- isEmpty(): boolean;
48
- /**
49
- * Inserts a new node at the specified index.
50
- * @param index Index at which the new node has to be inserted
51
- * @param val Value of the new node to be inserted
52
- */
53
- insert(index: number, val: T): boolean;
54
- /**
55
- * Removes a node at the specified index and returns its value.
56
- * @param index Index at which the node has to be removed.
57
- */
58
- remove(index: number): T | null;
59
- }
@@ -1,2 +0,0 @@
1
- export * from './singly-linked-list';
2
- export * from './doubly-linked-list';
@@ -1,358 +0,0 @@
1
- /** Type used for filter and find methods, returning a boolean */
2
- type TTestFunction<NodeData> = (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean;
3
- /** Type used for map and forEach methods, returning anything */
4
- type TMapFunction<NodeData> = (data: any, index: number, list: SinglyLinkedList<NodeData>) => any;
5
- /**
6
- * The class which represents one link or node in a linked list
7
- * ```ts
8
- * const node = new SinglyLinkedListNode(1, null, null, null);
9
- * ```
10
- */
11
- export declare class SinglyLinkedListNode<NodeData = any> {
12
- /** Data stored on the node */
13
- val: NodeData;
14
- /** The previous node in the list */
15
- prev: SinglyLinkedListNode<NodeData> | null;
16
- /** The next link in the list */
17
- next: SinglyLinkedListNode<NodeData> | null;
18
- /** The list this node belongs to */
19
- list: SinglyLinkedList<NodeData> | null;
20
- constructor(
21
- /** Data stored on the node */
22
- val: NodeData,
23
- /** The previous node in the list */
24
- prev: SinglyLinkedListNode<NodeData> | null,
25
- /** The next link in the list */
26
- next: SinglyLinkedListNode<NodeData> | null,
27
- /** The list this node belongs to */
28
- list: SinglyLinkedList<NodeData> | null);
29
- /**
30
- * Alias to .val
31
- * ```ts
32
- * new LinkedList(1, 2, 3).head.value; // 1
33
- * ```
34
- */
35
- get value(): NodeData;
36
- /**
37
- * Get the index of this node
38
- * ```ts
39
- * new LinkedList(1, 2, 3).head.index; // 0
40
- * ```
41
- */
42
- get index(): number | undefined;
43
- /**
44
- * Insert a new node before this one
45
- * ```ts
46
- * new LinkedList(2, 3).head.insertBefore(1); // 1 <=> 2 <=> 3
47
- * ```
48
- * @param val Data to save in the node
49
- */
50
- insertBefore(val: NodeData): SinglyLinkedList<NodeData>;
51
- /**
52
- * Insert new val after this node
53
- * ```ts
54
- * new LinkedList(1, 2).tail.insertAfter(3); // 1 <=> 2 <=> 3
55
- * ```
56
- * @param val Data to be saved in the node
57
- */
58
- insertAfter(val: NodeData): SinglyLinkedList<NodeData>;
59
- /**
60
- * Remove this node
61
- * ```ts
62
- * new LinkedList(1, 2, 3, 4).tail.remove(); // 1 <=> 2 <=> 3
63
- * ```
64
- */
65
- remove(): SinglyLinkedListNode<NodeData>;
66
- }
67
- /**
68
- * A doubly linked list
69
- * ```ts
70
- * const list = new LinkedList(1, 2, 3);
71
- * const listFromArray = LinkedList.from([1, 2, 3]);
72
- * ```
73
- */
74
- export declare class SinglyLinkedList<NodeData = any> {
75
- /**
76
- * The length of the list
77
- */
78
- get length(): number;
79
- /**
80
- * Convert any iterable to a new linked list
81
- * ```javascript
82
- * const array = [1, 2, 3];
83
- * const list = LinkedList.from(array);
84
- * ```
85
- * @param iterable Any iterable datatype like Array or Map
86
- */
87
- static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
88
- /** The head of the list, the first node */
89
- head: SinglyLinkedListNode<NodeData> | null;
90
- /** The tail of the list, the last node */
91
- tail: SinglyLinkedListNode<NodeData> | null;
92
- /** Internal size reference */
93
- private size;
94
- constructor(...args: NodeData[]);
95
- /**
96
- * Get the node val at a specified index, zero based
97
- * ```ts
98
- * new LinkedList(1, 2, 3).get(0); // 1
99
- * ```
100
- * @param index to retrieve val at
101
- */
102
- get(index: number): NodeData | undefined;
103
- /**
104
- * Get the node at index, zero based
105
- * ```ts
106
- * new LinkedList(1, 2, 3).getNode(0);
107
- * // { prev: null, val: 1, next: SinglyLinkedListNode }
108
- * ```
109
- */
110
- getNode(index: number): SinglyLinkedListNode<NodeData> | undefined;
111
- /**
112
- * Return the first node and its index in the list that
113
- * satisfies the testing function
114
- * ```ts
115
- * new LinkedList(1, 2, 3).findNodeIndex(val => val === 1);
116
- * // { node: SinglyLinkedListNode, index: 0 }
117
- * ```
118
- * @param f A function to be applied to the val of each node
119
- */
120
- findNodeIndex(f: TTestFunction<NodeData>): ({
121
- node: SinglyLinkedListNode<NodeData>;
122
- index: number;
123
- }) | undefined;
124
- /**
125
- * Returns the first node in the list that
126
- * satisfies the provided testing function. Otherwise undefined is returned.
127
- * ```ts
128
- * new LinkedList(1, 2, 3).findNode(val => val === 1);
129
- * // { prev: null, val: 1, next: SinglyLinkedListNode }
130
- * ```
131
- * @param f Function to test val against
132
- */
133
- findNode(f: TTestFunction<NodeData>): SinglyLinkedListNode<NodeData> | undefined;
134
- /**
135
- * Returns the value of the first element in the list that
136
- * satisfies the provided testing function. Otherwise undefined is returned.
137
- * ```ts
138
- * new LinkedList(1, 2, 3).find(val => val === 1); // 1
139
- * ```
140
- * @param f Function to test val against
141
- */
142
- find(f: TTestFunction<NodeData>): NodeData | undefined;
143
- /**
144
- * Returns the index of the first node in the list that
145
- * satisfies the provided testing function. Ohterwise -1 is returned.
146
- * ```ts
147
- * new LinkedList(1, 2, 3).findIndex(val => val === 3); // 2
148
- * ```
149
- * @param f Function to test val against
150
- */
151
- findIndex(f: TTestFunction<NodeData>): number;
152
- /**
153
- * Append one or any number of nodes to the end of the list.
154
- * This modifies the list in place and returns the list itself
155
- * to make this method chainable.
156
- * ```ts
157
- * new LinkedList(1).append(2).append(3, 4); // 1 <=> 2 <=> 3 <=> 4
158
- * ```
159
- * @param args Data to be stored in the node, takes any number of arguments
160
- */
161
- append(...args: NodeData[]): SinglyLinkedList<NodeData>;
162
- /**
163
- * Synonym for append
164
- * ```ts
165
- * new LinkedList(1).push(2).push(3, 4); // 1 <=> 2 <=> 3 <=> 4
166
- * ```
167
- * @param args Data to be stored, takes any number of arguments
168
- */
169
- push(...args: NodeData[]): number;
170
- /**
171
- * Prepend any number of val arguments to the list. The
172
- * argument list is prepended as a block to reduce confusion:
173
- * ```javascript
174
- * new LinkedList(3, 4).prepend(0, 1, 2); // [0, 1, 2, 3, 4]
175
- * ```
176
- * @param args Data to be stored in the node, accepts any number of arguments
177
- */
178
- prepend(...args: NodeData[]): SinglyLinkedList<NodeData>;
179
- /**
180
- * Insert a new node at a given index position. If index is
181
- * out of bounds, the node is appended, if index is negative
182
- * or 0, it will be prepended.
183
- * ```ts
184
- * new LinkedList(1, 3).insertAt(1, 2); // 1 <=> 2 <=> 3
185
- * ```
186
- * @param index The index to insert the new node at
187
- * @param val Data to be stored on the new node
188
- */
189
- insertAt(index: number, val: NodeData): SinglyLinkedList<NodeData>;
190
- /**
191
- * Remove the specified node from the list and return the removed
192
- * node afterwards.
193
- * ```ts
194
- * const list = new LinkedList(1, 2, 3);
195
- * list.removeNode(list.tail); // { prev: null, val: 3, next: null, list: null }
196
- * ```
197
- * @param node The node to be removed
198
- */
199
- removeNode(node: SinglyLinkedListNode<NodeData>): SinglyLinkedListNode<NodeData>;
200
- /**
201
- * Remove the node at the specified index
202
- * ```ts
203
- * new LinkedList(1, 2, 3).removeAt(2); // { prev: null, val: 3, next: null, list: null }
204
- * ```
205
- * @param index Index at which to remove
206
- */
207
- removeAt(index: number): SinglyLinkedListNode<NodeData> | undefined;
208
- /**
209
- * Insert a new node before the reference node
210
- * ```ts
211
- * const list = new LinkedList(1, 3);
212
- * list.insertBefore(list.tail, 2); // 1 <=> 2 <=> 3
213
- * ```
214
- * @param referenceNode The node reference
215
- * @param val Data to save in the node
216
- */
217
- insertBefore(referenceNode: SinglyLinkedListNode<NodeData>, val: NodeData): SinglyLinkedList<NodeData>;
218
- /**
219
- * Sorts the linked list using the provided compare function
220
- * @param compare A function used to compare the val of two nodes. It should return
221
- * a boolean. True will insert a before b, false will insert b before a.
222
- * (a, b) => a < b or (1, 2) => 1 < 2 === true, 2 will be inserted after 1,
223
- * the sort order will be ascending.
224
- */
225
- sort(compare: (a: NodeData, b: NodeData) => boolean): SinglyLinkedList<NodeData>;
226
- /**
227
- * Insert a new node after this one
228
- * ```ts
229
- * const list = new LinkedList(2, 3);
230
- * list.insertAfter(list.head, 1); // 1 <=> 2 <=> 3
231
- * ```
232
- * @param referenceNode The reference node
233
- * @param val Data to be saved in the node
234
- */
235
- insertAfter(referenceNode: SinglyLinkedListNode<NodeData>, val: NodeData): SinglyLinkedList<NodeData>;
236
- /**
237
- * Remove the first node from the list and return the val of the removed node
238
- * or undefined
239
- * ```ts
240
- * new LinkedList(1, 2, 3).shift(); // 1
241
- * ```
242
- */
243
- shift(): NodeData | undefined;
244
- /**
245
- * Remove the last node from the list and return the val of the removed node
246
- * or undefined if the list was empty
247
- * ```ts
248
- * new LinkedList(1, 2, 3).pop(); // 3
249
- * ```
250
- */
251
- pop(): NodeData | undefined;
252
- /**
253
- * Merge the current list with another. Both lists will be
254
- * equal after merging.
255
- * ```ts
256
- * const list = new LinkedList(1, 2);
257
- * const otherList = new LinkedList(3);
258
- * list.merge(otherList);
259
- * (list === otherList); // true
260
- * ```
261
- * @param list The list to be merged
262
- */
263
- merge(list: SinglyLinkedList<NodeData>): void;
264
- /**
265
- * Removes all nodes from a list
266
- *
267
- * ```ts
268
- * list.clear();
269
- * ```
270
- */
271
- clear(): this;
272
- /**
273
- * The slice() method returns a shallow copy of a
274
- * portion of a list into a new list object selected
275
- * from start to end (end not included).
276
- * The original list will not be modified.
277
- * ```ts
278
- * const list = new LinkedList(1, 2, 3, 4, 5);
279
- * const newList = list.slice(0, 3); // 1 <=> 2 <=> 3
280
- * ```
281
- * @param start Start index
282
- * @param end End index, optional
283
- */
284
- slice(start: number, end?: number): SinglyLinkedList<NodeData | {}>;
285
- /**
286
- * The reverse() function reverses the list in place and returns the list
287
- * itself.
288
- * ```ts
289
- * new LinkedList(1, 2, 3).reverse(); // 3 <=> 2 <=> 1
290
- * ```
291
- */
292
- reverse(): SinglyLinkedList<NodeData>;
293
- /**
294
- * The forEach() method executes a provided function once for each list node.
295
- * ```ts
296
- * new LinkedList(1, 2, 3).forEach(val => log(val)); // 1 2 3
297
- * ```
298
- * @param f Function to execute for each element, taking up to three arguments.
299
- * @param reverse Indicates if the list should be walked in reverse order, default is false
300
- */
301
- forEach(f: TMapFunction<NodeData>, reverse?: boolean): void;
302
- /**
303
- * The map() method creates a new list with the results of
304
- * calling a provided function on every node in the calling list.
305
- * ```ts
306
- * new LinkedList(1, 2, 3).map(val => val + 10); // 11 <=> 12 <=> 13
307
- * ```
308
- * @param f Function that produces an node of the new list, taking up to three arguments
309
- * @param reverse Indicates if the list should be mapped in reverse order, default is false
310
- */
311
- map(f: TMapFunction<NodeData>, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
312
- /**
313
- * The filter() method creates a new list with all nodes
314
- * that pass the test implemented by the provided function.
315
- * ```ts
316
- * new LinkedList(1, 2, 3, 4, 5).filter(val => val < 4); // 1 <=> 2 <=> 3
317
- * ```
318
- * @param f Function to test each node val in the list. Return true to keep the node
319
- * @param reverse Indicates if the list should be filtered in reverse order, default is false
320
- */
321
- filter(f: TTestFunction<NodeData>, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
322
- /**
323
- * Reduce over each node in the list
324
- * ```ts
325
- * new LinkedList(1, 2, 3).reduce(n => n += 1, 0); // 3
326
- * ```
327
- * @param f A reducer function
328
- * @param start An initial value
329
- * @returns The final state of the accumulator
330
- */
331
- reduce(f: (accumulator: any, currentNode: NodeData, index: number, list: SinglyLinkedList<NodeData>) => any, start?: any, reverse?: boolean): any;
332
- /**
333
- * Convert the linked list to an array
334
- * ```ts
335
- * new LinkedList(1, 2, 3).toArray(); // [1, 2, 3]
336
- * ```
337
- */
338
- toArray(): NodeData[];
339
- /**
340
- * Convert a linked list to string
341
- * ```ts
342
- * new LinkedList('one', 'two', 'three').toString(' <=> ') === 'one <=> two <=> three';
343
- * ```
344
- * @param separator Optional string to be placed in between val nodes, default is one space
345
- */
346
- toString(separator?: string): string;
347
- /**
348
- * The iterator implementation
349
- * ```ts
350
- * const list = new LinkedList(1, 2, 3);
351
- * for (const val of list) { log(val); } // 1 2 3
352
- * ```
353
- */
354
- [Symbol.iterator](): IterableIterator<NodeData>;
355
- /** Private helper function to reduce duplication of pop() and shift() methods */
356
- private removeFromAnyEnd;
357
- }
358
- export {};
@@ -1,3 +0,0 @@
1
- export * from './matrix';
2
- export * from './vector2d';
3
- export * from './matrix2d';
@@ -1,9 +0,0 @@
1
- export declare class MatrixNTI2D<T = number> {
2
- private readonly _matrix;
3
- constructor(options: {
4
- row: number;
5
- col: number;
6
- initialVal?: T;
7
- });
8
- toArray(): Array<Array<T>>;
9
- }
@@ -1,25 +0,0 @@
1
- import Vector2D from './vector2d';
2
- export declare class Matrix2D {
3
- private readonly _matrix;
4
- constructor(value?: number[][] | Vector2D);
5
- /**
6
- * Return the matrix values
7
- */
8
- get m(): number[][];
9
- static get empty(): number[][];
10
- get toVector(): Vector2D;
11
- /**
12
- * Initialize an identity matrix
13
- */
14
- static get identity(): number[][];
15
- static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
16
- static subtract(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
17
- static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D;
18
- static multiplyByValue(matrix: Matrix2D, value: number): Matrix2D;
19
- static multiplyByVector(matrix: Matrix2D, vector: Vector2D): Vector2D;
20
- static view(width: number, height: number): Matrix2D;
21
- static scale(factor: number): Matrix2D;
22
- static rotate(radians: number): Matrix2D;
23
- static translate(vector: Vector2D): Matrix2D;
24
- }
25
- export default Matrix2D;
@@ -1,31 +0,0 @@
1
- type Direction = 'up' | 'right' | 'down' | 'left';
2
- type Turning = {
3
- [key in Direction]: Direction;
4
- };
5
- export declare class Character {
6
- direction: Direction;
7
- turn: () => Character;
8
- constructor(direction: Direction, turning: Turning);
9
- }
10
- interface NavigatorParams<T> {
11
- matrix: T[][];
12
- turning: Turning;
13
- onMove: (cur: [number, number]) => void;
14
- init: {
15
- cur: [number, number];
16
- charDir: Direction;
17
- VISITED: T;
18
- };
19
- }
20
- export declare class Navigator<T = number> {
21
- private readonly _matrix;
22
- private readonly _cur;
23
- private _character;
24
- private readonly _VISITED;
25
- onMove: (cur: [number, number]) => void;
26
- constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }: NavigatorParams<T>);
27
- start(): void;
28
- check(direction: Direction): boolean;
29
- move(direction: Direction): void;
30
- }
31
- export {};
@@ -1,74 +0,0 @@
1
- declare class Vector2D {
2
- x: number;
3
- y: number;
4
- w: number;
5
- static add(vector1: Vector2D, vector2: Vector2D): Vector2D;
6
- static subtract(vector1: Vector2D, vector2: Vector2D): Vector2D;
7
- static subtractValue(vector: Vector2D, value: number): Vector2D;
8
- static multiply(vector: Vector2D, value: number): Vector2D;
9
- static divide(vector: Vector2D, value: number): Vector2D;
10
- static equals(vector1: Vector2D, vector2: Vector2D): boolean;
11
- static equalsRounded(vector1: Vector2D, vector2: Vector2D, roundingFactor?: number): boolean;
12
- /**
13
- * Normalizes the vector if it matches a certain condition
14
- */
15
- static normalize(vector: Vector2D): Vector2D;
16
- /**
17
- * Adjusts x and y so that the length of the vector does not exceed max
18
- */
19
- static truncate(vector: Vector2D, max: number): Vector2D;
20
- /**
21
- * The vector that is perpendicular to this one
22
- */
23
- static perp(vector: Vector2D): Vector2D;
24
- /**
25
- * returns the vector that is the reverse of this vector
26
- */
27
- static reverse(vector: Vector2D): Vector2D;
28
- static abs(vector: Vector2D): Vector2D;
29
- /**
30
- * The dot product of v1 and v2
31
- */
32
- static dot(vector1: Vector2D, vector2: Vector2D): number;
33
- /**
34
- * The distance between this and the vector
35
- */
36
- static distance(vector1: Vector2D, vector2: Vector2D): number;
37
- /**
38
- * The distance between this and the vector squared
39
- */
40
- static distanceSq(vector1: Vector2D, vector2: Vector2D): number;
41
- /**
42
- * Returns positive if v2 is clockwise of this vector, negative if counterclockwise
43
- * (assuming the Y axis is pointing down, X axis to right like a Window app)
44
- */
45
- static sign(vector1: Vector2D, vector2: Vector2D): number;
46
- /**
47
- * Returns the angle between origin and the given vector in radians
48
- * @param vector
49
- */
50
- static angle(vector: Vector2D): number;
51
- static random(maxX: number, maxY: number): Vector2D;
52
- constructor(x?: number, y?: number, w?: number);
53
- /**
54
- * Check wether both x and y are zero
55
- */
56
- zero(): void;
57
- /**
58
- * Set x and y both to zero
59
- */
60
- get isZero(): boolean;
61
- /**
62
- * The length / magnitude of the vector
63
- */
64
- get length(): number;
65
- /**
66
- * The squared length of the vector
67
- */
68
- get lengthSq(): number;
69
- /**
70
- * Return the vector with rounded values
71
- */
72
- get rounded(): Vector2D;
73
- }
74
- export default Vector2D;
@@ -1,3 +0,0 @@
1
- export * from './priority-queue';
2
- export * from './min-priority-queue';
3
- export * from './max-priority-queue';
@@ -1,4 +0,0 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
2
- export declare class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
4
- }
@@ -1,4 +0,0 @@
1
- import { PriorityQueue, PriorityQueueOptions } from './priority-queue';
2
- export declare class MinPriorityQueue<T = number> extends PriorityQueue<T> {
3
- constructor(options: PriorityQueueOptions<T>);
4
- }
@@ -1,36 +0,0 @@
1
- export type PriorityQueueComparator<T> = (a: T, b: T) => number;
2
- export interface PriorityQueueOptions<T> {
3
- nodes?: T[];
4
- isFix?: boolean;
5
- comparator: PriorityQueueComparator<T>;
6
- }
7
- export type PriorityQueueDFSOrderPattern = 'pre' | 'in' | 'post';
8
- export declare class PriorityQueue<T = number> {
9
- protected nodes: T[];
10
- get size(): number;
11
- protected readonly _comparator: PriorityQueueComparator<T>;
12
- constructor(options: PriorityQueueOptions<T>);
13
- protected _compare(a: number, b: number): boolean;
14
- protected _swap(a: number, b: number): void;
15
- protected _isValidIndex(index: number): boolean;
16
- protected _getParent(child: number): number;
17
- protected _getLeft(parent: number): number;
18
- protected _getRight(parent: number): number;
19
- protected _getComparedChild(parent: number): number;
20
- protected _heapifyUp(start: number): void;
21
- protected _heapifyDown(start: number): void;
22
- protected _fix(): void;
23
- offer(node: T): void;
24
- peek(): T | null;
25
- poll(): T | null;
26
- leaf(): T | null;
27
- isEmpty(): boolean;
28
- clear(): void;
29
- toArray(): T[];
30
- clone(): PriorityQueue<T>;
31
- isValid(): boolean;
32
- sort(): T[];
33
- DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[];
34
- static heapify<T>(options: PriorityQueueOptions<T>): PriorityQueue<T>;
35
- static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>): boolean;
36
- }
@@ -1,37 +0,0 @@
1
- import { DoublyLinkedList } from '../linked-list';
2
- export declare class Deque<T> extends DoublyLinkedList<T> {
3
- }
4
- export declare class ObjectDeque<T> {
5
- protected _nodes: {
6
- [key: number]: T;
7
- };
8
- protected _capacity: number;
9
- protected _first: number;
10
- protected _last: number;
11
- protected _size: number;
12
- constructor(capacity?: number);
13
- size(): number;
14
- offerFirst(value: T): void;
15
- offerLast(value: T): void;
16
- pollFirst(): T | undefined;
17
- peekFirst(): T | undefined;
18
- pollLast(): T | undefined;
19
- peekLast(): T | undefined;
20
- get(index: number): NonNullable<T> | null;
21
- isEmpty(): boolean;
22
- }
23
- export declare class ArrayDeque<T> {
24
- protected _nodes: T[];
25
- get size(): number;
26
- offerLast(value: T): number;
27
- pollLast(): T | null;
28
- pollFirst(): T | null;
29
- offerFirst(value: T): number;
30
- peekFirst(): T | null;
31
- peekLast(): T | null;
32
- get(index: number): T | null;
33
- set(index: number, value: T): T;
34
- insert(index: number, value: T): T[];
35
- remove(index: number): T[];
36
- isEmpty(): boolean;
37
- }
@@ -1 +0,0 @@
1
- export * from './queue';