@raikuxq/alg-ds 1.2.5 → 3.0.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 (189) hide show
  1. package/README.md +27 -52
  2. package/lib/index.d.ts +1279 -3
  3. package/lib/index.mjs +1 -0
  4. package/package.json +79 -72
  5. package/lib/app/algorithms/binary-search.d.ts +0 -5
  6. package/lib/app/algorithms/binary-search.js +0 -27
  7. package/lib/app/algorithms/factorial.d.ts +0 -9
  8. package/lib/app/algorithms/factorial.js +0 -17
  9. package/lib/app/algorithms/fibonacci.d.ts +0 -9
  10. package/lib/app/algorithms/fibonacci.js +0 -17
  11. package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.d.ts +0 -39
  12. package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.js +0 -87
  13. package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.d.ts +0 -28
  14. package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.js +0 -70
  15. package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.d.ts +0 -28
  16. package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.js +0 -70
  17. package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.d.ts +0 -32
  18. package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.js +0 -97
  19. package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.d.ts +0 -6
  20. package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.js +0 -13
  21. package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.d.ts +0 -6
  22. package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.js +0 -13
  23. package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.d.ts +0 -6
  24. package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.js +0 -13
  25. package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.d.ts +0 -19
  26. package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.js +0 -28
  27. package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.d.ts +0 -32
  28. package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.js +0 -48
  29. package/lib/app/algorithms/graph/searching/hasPath.d.ts +0 -9
  30. package/lib/app/algorithms/graph/searching/hasPath.js +0 -30
  31. package/lib/app/algorithms/graph/searching/shortestPath.d.ts +0 -9
  32. package/lib/app/algorithms/graph/searching/shortestPath.js +0 -30
  33. package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.d.ts +0 -2
  34. package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.js +0 -14
  35. package/lib/app/algorithms/memoize.d.ts +0 -5
  36. package/lib/app/algorithms/memoize.js +0 -22
  37. package/lib/app/algorithms/sorts/bubble-sort.d.ts +0 -9
  38. package/lib/app/algorithms/sorts/bubble-sort.js +0 -23
  39. package/lib/app/algorithms/sorts/insertion-sort.d.ts +0 -9
  40. package/lib/app/algorithms/sorts/insertion-sort.js +0 -25
  41. package/lib/app/algorithms/sorts/merge-sort.d.ts +0 -9
  42. package/lib/app/algorithms/sorts/merge-sort.js +0 -61
  43. package/lib/app/algorithms/sorts/quick-sort.d.ts +0 -9
  44. package/lib/app/algorithms/sorts/quick-sort.js +0 -45
  45. package/lib/app/algorithms/sorts/select-sort.d.ts +0 -9
  46. package/lib/app/algorithms/sorts/select-sort.js +0 -20
  47. package/lib/app/algorithms/transpose-matrix.d.ts +0 -6
  48. package/lib/app/algorithms/transpose-matrix.js +0 -19
  49. package/lib/app/constants.d.ts +0 -2
  50. package/lib/app/constants.js +0 -6
  51. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +0 -15
  52. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +0 -53
  53. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +0 -60
  54. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +0 -35
  55. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +0 -13
  56. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +0 -59
  57. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +0 -75
  58. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +0 -276
  59. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +0 -16
  60. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +0 -70
  61. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +0 -58
  62. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +0 -236
  63. package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.d.ts +0 -6
  64. package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.js +0 -22
  65. package/lib/app/data-structures/Graph/AbstractGraph.d.ts +0 -84
  66. package/lib/app/data-structures/Graph/AbstractGraph.js +0 -143
  67. package/lib/app/data-structures/Graph/DirectedGraph.d.ts +0 -27
  68. package/lib/app/data-structures/Graph/DirectedGraph.js +0 -89
  69. package/lib/app/data-structures/Graph/GraphEdge.d.ts +0 -16
  70. package/lib/app/data-structures/Graph/GraphEdge.js +0 -43
  71. package/lib/app/data-structures/Graph/UndirectedGraph.d.ts +0 -31
  72. package/lib/app/data-structures/Graph/UndirectedGraph.js +0 -106
  73. package/lib/app/data-structures/Graph/_helpers/createGraph.d.ts +0 -6
  74. package/lib/app/data-structures/Graph/_helpers/createGraph.js +0 -22
  75. package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.d.ts +0 -7
  76. package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.js +0 -42
  77. package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.d.ts +0 -4
  78. package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.js +0 -67
  79. package/lib/app/data-structures/HashTable/HashTable.d.ts +0 -73
  80. package/lib/app/data-structures/HashTable/HashTable.js +0 -171
  81. package/lib/app/data-structures/HashTable/HashTableNode.d.ts +0 -11
  82. package/lib/app/data-structures/HashTable/HashTableNode.js +0 -39
  83. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +0 -134
  84. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +0 -247
  85. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +0 -20
  86. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +0 -41
  87. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +0 -42
  88. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +0 -98
  89. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +0 -25
  90. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +0 -65
  91. package/lib/app/data-structures/LinkedList/DoubleLinkedList/IterableDoubleLinkedList.d.ts +0 -18
  92. package/lib/app/data-structures/LinkedList/DoubleLinkedList/IterableDoubleLinkedList.js +0 -86
  93. package/lib/app/data-structures/LinkedList/SingleLinkedList/IterableSingleLinkedList.d.ts +0 -18
  94. package/lib/app/data-structures/LinkedList/SingleLinkedList/IterableSingleLinkedList.js +0 -68
  95. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +0 -46
  96. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +0 -103
  97. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts +0 -7
  98. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +0 -29
  99. package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.d.ts +0 -3
  100. package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.js +0 -34
  101. package/lib/app/data-structures/LoopedArray/LoopedArray.d.ts +0 -86
  102. package/lib/app/data-structures/LoopedArray/LoopedArray.js +0 -165
  103. package/lib/app/data-structures/Queue/Queue.d.ts +0 -50
  104. package/lib/app/data-structures/Queue/Queue.js +0 -85
  105. package/lib/app/data-structures/Stack/Stack.d.ts +0 -50
  106. package/lib/app/data-structures/Stack/Stack.js +0 -85
  107. package/lib/app/exceptions/CollectionIsEmptyException.d.ts +0 -4
  108. package/lib/app/exceptions/CollectionIsEmptyException.js +0 -28
  109. package/lib/app/exceptions/CollectionIsFullException.d.ts +0 -4
  110. package/lib/app/exceptions/CollectionIsFullException.js +0 -28
  111. package/lib/app/exceptions/IndexOutOfBoundsException.d.ts +0 -4
  112. package/lib/app/exceptions/IndexOutOfBoundsException.js +0 -28
  113. package/lib/app/exceptions/IsAlreadyExistsException.d.ts +0 -4
  114. package/lib/app/exceptions/IsAlreadyExistsException.js +0 -28
  115. package/lib/app/exceptions/IsNotFoundException.d.ts +0 -4
  116. package/lib/app/exceptions/IsNotFoundException.js +0 -28
  117. package/lib/app/exceptions/ValueOutOfRangeException.d.ts +0 -4
  118. package/lib/app/exceptions/ValueOutOfRangeException.js +0 -28
  119. package/lib/app/exceptions/base/IllegalArgumentException.d.ts +0 -3
  120. package/lib/app/exceptions/base/IllegalArgumentException.js +0 -27
  121. package/lib/app/exceptions/base/IllegalStateException.d.ts +0 -3
  122. package/lib/app/exceptions/base/IllegalStateException.js +0 -27
  123. package/lib/app/types/EnumBinarySearchTreeType.d.ts +0 -4
  124. package/lib/app/types/EnumBinarySearchTreeType.js +0 -9
  125. package/lib/app/types/EnumGraphTraversalType.d.ts +0 -5
  126. package/lib/app/types/EnumGraphTraversalType.js +0 -10
  127. package/lib/app/types/EnumGraphType.d.ts +0 -4
  128. package/lib/app/types/EnumGraphType.js +0 -9
  129. package/lib/app/types/EnumLinkedListType.d.ts +0 -4
  130. package/lib/app/types/EnumLinkedListType.js +0 -9
  131. package/lib/app/types/EnumRandomGenerationFormat.d.ts +0 -4
  132. package/lib/app/types/EnumRandomGenerationFormat.js +0 -9
  133. package/lib/app/types/EnumSortType.d.ts +0 -7
  134. package/lib/app/types/EnumSortType.js +0 -12
  135. package/lib/app/types/EnumTreeTraversalType.d.ts +0 -5
  136. package/lib/app/types/EnumTreeTraversalType.js +0 -10
  137. package/lib/app/types/FnCompareTwo.d.ts +0 -1
  138. package/lib/app/types/FnCompareTwo.js +0 -3
  139. package/lib/app/types/FnToMemoize.d.ts +0 -1
  140. package/lib/app/types/FnToMemoize.js +0 -3
  141. package/lib/app/types/IArrayFacade.d.ts +0 -4
  142. package/lib/app/types/IArrayFacade.js +0 -3
  143. package/lib/app/types/IBiDirectIterable.d.ts +0 -5
  144. package/lib/app/types/IBiDirectIterable.js +0 -3
  145. package/lib/app/types/IBiDirectIterator.d.ts +0 -11
  146. package/lib/app/types/IBiDirectIterator.js +0 -3
  147. package/lib/app/types/IBinaryTree.d.ts +0 -12
  148. package/lib/app/types/IBinaryTree.js +0 -3
  149. package/lib/app/types/IConvertableToArray.d.ts +0 -4
  150. package/lib/app/types/IConvertableToArray.js +0 -3
  151. package/lib/app/types/IGraph.d.ts +0 -14
  152. package/lib/app/types/IGraph.js +0 -3
  153. package/lib/app/types/IGraphIterationStrategy.d.ts +0 -5
  154. package/lib/app/types/IGraphIterationStrategy.js +0 -3
  155. package/lib/app/types/IGraphIterator.d.ts +0 -11
  156. package/lib/app/types/IGraphIterator.js +0 -3
  157. package/lib/app/types/IIterable.d.ts +0 -4
  158. package/lib/app/types/IIterable.js +0 -3
  159. package/lib/app/types/IIterator.d.ts +0 -14
  160. package/lib/app/types/IIterator.js +0 -3
  161. package/lib/app/types/IKeyValueStorage.d.ts +0 -8
  162. package/lib/app/types/IKeyValueStorage.js +0 -3
  163. package/lib/app/types/ILinearStorage.d.ts +0 -11
  164. package/lib/app/types/ILinearStorage.js +0 -3
  165. package/lib/app/types/ILinearStorageRA.d.ts +0 -13
  166. package/lib/app/types/ILinearStorageRA.js +0 -3
  167. package/lib/app/types/ILinkedList.d.ts +0 -4
  168. package/lib/app/types/ILinkedList.js +0 -3
  169. package/lib/app/types/TypeArrayMatrix.d.ts +0 -1
  170. package/lib/app/types/TypeArrayMatrix.js +0 -3
  171. package/lib/app/utils.d.ts +0 -29
  172. package/lib/app/utils.js +0 -61
  173. package/lib/exports/algorithms.d.ts +0 -16
  174. package/lib/exports/algorithms.js +0 -36
  175. package/lib/exports/constants.d.ts +0 -2
  176. package/lib/exports/constants.js +0 -7
  177. package/lib/exports/data-structures.d.ts +0 -13
  178. package/lib/exports/data-structures.js +0 -28
  179. package/lib/exports/helpers.d.ts +0 -6
  180. package/lib/exports/helpers.js +0 -14
  181. package/lib/exports/sorts.d.ts +0 -6
  182. package/lib/exports/sorts.js +0 -14
  183. package/lib/exports/types.d.ts +0 -16
  184. package/lib/exports/types.js +0 -34
  185. package/lib/exports/utils.d.ts +0 -3
  186. package/lib/exports/utils.js +0 -12
  187. package/lib/exports.d.ts +0 -55
  188. package/lib/exports.js +0 -107
  189. package/lib/index.js +0 -5
package/lib/index.d.ts CHANGED
@@ -1,3 +1,1279 @@
1
- /**
2
- * Write your code here
3
- */
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export declare const EDGE_EXISTS_STATE = 1;
4
+ export declare const EDGE_NOT_EXISTS_STATE = 0;
5
+ export type FnToMemoize<Key, Value> = (...args: Array<Key>) => Value;
6
+ /**
7
+ * Time complexity: O(n)
8
+ */
9
+ export declare const factorial: (x: number) => number;
10
+ /**
11
+ * Time complexity: O(n) for the first call, O(1) for cached calls
12
+ */
13
+ export declare const memoizedFactorial: FnToMemoize<number, number>;
14
+ /**
15
+ * Time complexity: O(2^n) - exponential without memoization
16
+ */
17
+ export declare const fibonacci: (n: number) => number;
18
+ /**
19
+ * Time complexity: O(n) - linear due to caching
20
+ */
21
+ export declare const memoizedFibonacci: FnToMemoize<number, number>;
22
+ /**
23
+ * Find element's index in sorted array
24
+ * Time complexity: O(log(n))
25
+ */
26
+ export declare const binarySearch: (elements: Array<number>, searchElement: number) => number | null;
27
+ export type TypeArrayMatrix = Array<Array<number>>;
28
+ /**
29
+ * Will flips a matrix over its diagonal
30
+ * @throws {IllegalArgumentException} when array is not a matrix
31
+ */
32
+ export declare const transposeMatrix: (matrix: TypeArrayMatrix) => TypeArrayMatrix;
33
+ export interface IGraph<T> extends Iterable<T> {
34
+ weight(): number;
35
+ vertices(): Array<T>;
36
+ verticesCount(): number;
37
+ edgesCount(): number;
38
+ addVertex(data: T): this;
39
+ removeVertex(data: T): this;
40
+ hasVertex(data: T): boolean;
41
+ getVertexNeighbors(data: T): Array<T>;
42
+ addEdge(from: T, to: T, weight?: number): this;
43
+ removeEdge(from: T, to: T): this;
44
+ hasEdge(from: T, to: T): boolean;
45
+ getEdgeWeight(from: T, to: T): number;
46
+ }
47
+ export declare const transposeDirectedGraph: <T>(sourceGraph: IGraph<T>) => IGraph<T>;
48
+ export interface IIterator<T> {
49
+ /**
50
+ * Will do one iteration and returns next item value
51
+ */
52
+ next(): T;
53
+ /**
54
+ * Will returns current value
55
+ */
56
+ current(): T;
57
+ /**
58
+ * Check if next element exists
59
+ */
60
+ hasNext(): boolean;
61
+ }
62
+ export interface IGraphIterator<T> extends IIterator<T> {
63
+ /**
64
+ * Get path which passed by iterator between two vertices
65
+ */
66
+ getPath(from: T, to: T): Array<T>;
67
+ /**
68
+ * Initialize iterator by passing start vertex
69
+ */
70
+ initIterator(from: T): void;
71
+ }
72
+ declare abstract class AbstractGraphIterator<T> implements IGraphIterator<T> {
73
+ protected readonly graph: IGraph<T>;
74
+ protected readonly visited: Map<T, boolean>;
75
+ protected readonly parents: Map<T, T>;
76
+ /**
77
+ * Creates empty instance
78
+ */
79
+ protected constructor(graph: IGraph<T>);
80
+ protected abstract currentImpl(): T;
81
+ protected abstract nextImpl(): T;
82
+ protected abstract initIteratorImpl(from: T): void;
83
+ protected abstract hasNextImpl(): boolean;
84
+ /**
85
+ * @inheritDoc
86
+ * @throws {IsNotFoundException} when start vertex was not found
87
+ */
88
+ initIterator(from: T): void;
89
+ /**
90
+ * @inheritDoc
91
+ */
92
+ hasNext(): boolean;
93
+ /**
94
+ * @inheritDoc
95
+ * @throws {IllegalStateException} when next element does not exist
96
+ */
97
+ next(): T;
98
+ /**
99
+ * @inheritDoc
100
+ * @throws {IllegalStateException} when current element does not exist
101
+ */
102
+ current(): T;
103
+ /**
104
+ * @inheritDoc
105
+ * @throws {IllegalStateException} when there is no path between given vertices
106
+ */
107
+ getPath(from: T, to: T): Array<T>;
108
+ }
109
+ /**
110
+ * Breadth first graph traversal
111
+ */
112
+ export declare class GraphIteratorBFS<T> extends AbstractGraphIterator<T> {
113
+ private readonly queue;
114
+ /**
115
+ * @inheritDoc
116
+ */
117
+ constructor(graph: IGraph<T>);
118
+ /**
119
+ * @inheritDoc
120
+ */
121
+ protected currentImpl(): T;
122
+ /**
123
+ @inheritDoc
124
+ */
125
+ initIteratorImpl(startVertex: T): void;
126
+ /**
127
+ * @inheritDoc
128
+ */
129
+ hasNextImpl(): boolean;
130
+ /**
131
+ * @inheritDoc
132
+ */
133
+ protected nextImpl(): T;
134
+ }
135
+ /**
136
+ * Deep first graph traversal
137
+ */
138
+ export declare class GraphIteratorDFS<T> extends AbstractGraphIterator<T> {
139
+ private readonly stack;
140
+ /**
141
+ * @inheritDoc
142
+ */
143
+ constructor(graph: IGraph<T>);
144
+ /**
145
+ * @inheritDoc
146
+ */
147
+ hasNextImpl(): boolean;
148
+ /**
149
+ @inheritDoc
150
+ */
151
+ initIteratorImpl(startVertex: T): void;
152
+ /**
153
+ * @inheritDoc
154
+ */
155
+ currentImpl(): T;
156
+ /**
157
+ * @inheritDoc
158
+ */
159
+ nextImpl(): T;
160
+ }
161
+ /**
162
+ * Dijkstra method graph traversal using a Priority Queue.
163
+ */
164
+ export declare class GraphIteratorDijkstra<T> extends AbstractGraphIterator<T> {
165
+ private readonly costs;
166
+ private readonly queue;
167
+ /**
168
+ * @inheritDoc
169
+ */
170
+ constructor(graph: IGraph<T>);
171
+ /**
172
+ * @inheritDoc
173
+ */
174
+ initIteratorImpl(startVertex: T): void;
175
+ /**
176
+ * @inheritDoc
177
+ */
178
+ hasNextImpl(): boolean;
179
+ /**
180
+ * @inheritDoc
181
+ */
182
+ currentImpl(): T;
183
+ /**
184
+ * @inheritDoc
185
+ */
186
+ nextImpl(): T;
187
+ /**
188
+ * Removes stale entries from the queue top.
189
+ */
190
+ private refreshQueue;
191
+ }
192
+ declare enum EnumGraphTraversalType {
193
+ BFS = "Breadth first traversal",
194
+ DFS = "Deep first traversal",
195
+ DIJKSTRA = "Dijkstra traversal"
196
+ }
197
+ /**
198
+ * Creates a graph iterator based on the specified traversal mode.
199
+ */
200
+ export declare const createGraphIterator: <T>(graph: IGraph<T>, mode: EnumGraphTraversalType) => IGraphIterator<T>;
201
+ /**
202
+ * Check if graph has a path between two vertices
203
+ * @throws {IsNotFoundException} when start vertex was not found
204
+ * @throws {IsNotFoundException} when end vertex was not found
205
+ * @throws {IllegalStateException} when there is no path between two vertices
206
+ */
207
+ export declare const hasPath: <T>({ graph, traversalType, from, to, }: {
208
+ graph: IGraph<T>;
209
+ from: T;
210
+ to: T;
211
+ traversalType: EnumGraphTraversalType;
212
+ }) => boolean;
213
+ /**
214
+ * Find the shortest path between two vertices
215
+ * @throws {IsNotFoundException} when start vertex was not found
216
+ * @throws {IsNotFoundException} when end vertex was not found
217
+ * @throws {IllegalStateException} when there is no path between two vertices
218
+ */
219
+ export declare const shortestPath: <T>({ graph, traversalType, from, to, }: {
220
+ graph: IGraph<T>;
221
+ from: T;
222
+ to: T;
223
+ traversalType: EnumGraphTraversalType;
224
+ }) => Array<T>;
225
+ /**
226
+ * Get graph adjacency matrix N x N
227
+ *
228
+ * @example
229
+ *
230
+ * Directed graph:
231
+ * - Bob [Maria]
232
+ * - Maria [Bob, John]
233
+ * - John []
234
+ *
235
+ * Its matrix:
236
+ * | Bob | Maria | John |
237
+ * Bob | 0 | 1 | 0 |
238
+ * Maria | 1 | 0 | 1 |
239
+ * John | 0 | 0 | 0 |
240
+ *
241
+ * @example
242
+ *
243
+ * Undirected graph:
244
+ * - Bob [Mariaэ
245
+ * - Maria [Bob, John]
246
+ * - John [Maria]
247
+ *
248
+ * Its matrix:
249
+ * | Bob | Maria | John |
250
+ * Bob | 0 | 1 | 0 |
251
+ * Maria | 1 | 0 | 1 |
252
+ * John | 0 | 1 | 0 |
253
+ */
254
+ export declare const presenterAdjacencyMatrix: <T>(graph: IGraph<T>) => TypeArrayMatrix;
255
+ /**
256
+ * Get graph adjacency list
257
+ *
258
+ * @example
259
+ *
260
+ * Directed graph:
261
+ * - Bob [Maria]
262
+ * - Maria [Bob, John]
263
+ * - John []
264
+ *
265
+ * @example
266
+ *
267
+ * Undirected graph:
268
+ * - Bob [Maria]
269
+ * - Maria [Bob, John]
270
+ * - John [Maria]
271
+ **/
272
+ export declare const presenterAdjacencyLists: <T>(graph: IGraph<T>) => Map<T, Array<T>>;
273
+ declare enum EnumLinkedListType {
274
+ DOUBLE = "Double linked list",
275
+ SINGLE = "Single linked list"
276
+ }
277
+ export interface ILinearStorage<T> {
278
+ peek(): T;
279
+ push(value: T): void;
280
+ pop(): T;
281
+ has(value: T): boolean;
282
+ isEmpty(): boolean;
283
+ isFull(): boolean;
284
+ length(): number;
285
+ clear(): void;
286
+ reverse(): void;
287
+ }
288
+ /**
289
+ * Interface extends default linear storage with methods that allows read/write operations for all storage elements
290
+ * RA - randomly accessible
291
+ */
292
+ export interface ILinearStorageRA<T> extends ILinearStorage<T> {
293
+ peekFromStart(): T;
294
+ peekByIndex(index: number): T;
295
+ unshift(value: T): void;
296
+ pushFromIndex(value: T, fromIndex: number): void;
297
+ shift(): T;
298
+ deleteFromIndex(fromIndex: number): T;
299
+ }
300
+ export interface IConvertableToArray<T> {
301
+ pushFromArray(elements: Array<T>): void;
302
+ getAsArray(): Array<T>;
303
+ }
304
+ export interface ILinkedList<T> extends ILinearStorageRA<T>, IConvertableToArray<T>, Iterable<T> {
305
+ }
306
+ export declare const createLinkedList: <T>(type: EnumLinkedListType, isIterable?: boolean, capacity?: number) => ILinkedList<T>;
307
+ declare enum EnumBinarySearchTreeType {
308
+ BST = "Binary Search Tree",
309
+ RANDOMIZED_BST = "Randomized Binary Search Tree"
310
+ }
311
+ declare enum EnumTreeTraversalType {
312
+ IN_ORDER = "IN_ORDER",
313
+ PRE_ORDER = "PRE_ORDER",
314
+ POST_ORDER = "POST_ORDER"
315
+ }
316
+ export interface IBinaryTree<T> {
317
+ has(value: T): boolean;
318
+ insert(value: T): void;
319
+ delete(value: T): void;
320
+ subtree(value: T): IBinaryTree<T>;
321
+ max(): T;
322
+ min(): T;
323
+ length(): number;
324
+ height(): number;
325
+ traverse(type: EnumTreeTraversalType): Array<T>;
326
+ }
327
+ /**
328
+ * Returns binary tree by type
329
+ */
330
+ export declare const createBinaryTree: <T>(type: EnumBinarySearchTreeType) => IBinaryTree<T>;
331
+ declare enum EnumGraphType {
332
+ DIRECTED = "DIRECTED",
333
+ UNDIRECTED = "UNDIRECTED"
334
+ }
335
+ /**
336
+ * Returns graph by type
337
+ */
338
+ export declare const createGraph: <T>(type: EnumGraphType) => IGraph<T>;
339
+ /**
340
+ * Creates a graph from N*N matrix that contains 1 in case of edge exists or 0 in case it does not
341
+ */
342
+ export declare const createGraphFromMatrix: <T>(matrix: TypeArrayMatrix, fieldsList: Array<T>, type: EnumGraphType) => IGraph<T>;
343
+ /**
344
+ * FIFO data structure
345
+ */
346
+ export declare class Queue<T> implements ILinearStorage<T> {
347
+ private readonly _list;
348
+ /**
349
+ * Create a queue instance
350
+ */
351
+ constructor(capacity?: number);
352
+ /**
353
+ * Get first element in queue (without deleting)
354
+ * @throws {CollectionIsEmptyException} when list is empty
355
+ */
356
+ peek(): T;
357
+ /**
358
+ * Add element to queue
359
+ * @throws {CollectionIsFullException} when list is full
360
+ */
361
+ push(item: T): void;
362
+ /**
363
+ * Delete first element in queue
364
+ * @throws {CollectionIsEmptyException} when list is empty
365
+ */
366
+ pop(): T;
367
+ /**
368
+ * Check if element exists in list
369
+ */
370
+ has(item: T): boolean;
371
+ /**
372
+ * Is queue empty
373
+ */
374
+ isEmpty(): boolean;
375
+ /**
376
+ * Is stack full
377
+ */
378
+ isFull(): boolean;
379
+ /**
380
+ * Remove all elements in queue
381
+ */
382
+ clear(): void;
383
+ /**
384
+ * Queue length
385
+ */
386
+ length(): number;
387
+ /**
388
+ * Reverse queue
389
+ */
390
+ reverse(): void;
391
+ }
392
+ export declare class Stack<T> implements ILinearStorage<T>, Iterable<T> {
393
+ private readonly _items;
394
+ private readonly _capacity;
395
+ constructor(capacity?: number);
396
+ length(): number;
397
+ isEmpty(): boolean;
398
+ isFull(): boolean;
399
+ peek(): T;
400
+ push(item: T): void;
401
+ pop(): T;
402
+ has(item: T): boolean;
403
+ clear(): void;
404
+ reverse(): void;
405
+ [Symbol.iterator](): Iterator<T>;
406
+ }
407
+ /**
408
+ * A Priority Queue implementation based on a Min-Binary Heap.
409
+ * Lower priority numbers are dequeued first.
410
+ */
411
+ export declare class PriorityQueue<T> {
412
+ private readonly _heap;
413
+ constructor();
414
+ /** Number of elements in the queue. */
415
+ get size(): number;
416
+ /** Returns true if the queue is empty. */
417
+ isEmpty(): boolean;
418
+ /**
419
+ * Adds an element to the queue with a specific priority.
420
+ * @param value The data to store.
421
+ * @param priority The priority level (lower value = higher priority).
422
+ */
423
+ enqueue(value: T, priority: number): void;
424
+ /**
425
+ * Removes and returns the element with the highest priority (lowest priority number).
426
+ * @throws {CollectionIsEmptyException} If the queue is empty.
427
+ */
428
+ dequeue(): T;
429
+ /**
430
+ * Returns the highest priority element without removing it.
431
+ * @throws {CollectionIsEmptyException} If the queue is empty.
432
+ */
433
+ peek(): T;
434
+ /** Clears all elements from the queue. */
435
+ clear(): void;
436
+ }
437
+ /**
438
+ * A Binary Heap implementation supporting custom priority logic
439
+ */
440
+ export declare class BinaryHeap<T> {
441
+ private readonly _heap;
442
+ private readonly _comparator;
443
+ /**
444
+ * @param comparator Function to determine element priority
445
+ */
446
+ constructor(comparator?: (a: T, b: T) => number);
447
+ /** Current number of elements in the heap */
448
+ get size(): number;
449
+ /** Returns true if the heap contains no elements */
450
+ isEmpty(): boolean;
451
+ /**
452
+ * Retrieves the root element without removing it
453
+ * @throws {CollectionIsEmptyException} If the heap is empty.
454
+ */
455
+ peek(): T;
456
+ /**
457
+ * Adds a new value and restores heap properties
458
+ */
459
+ insert(value: T): void;
460
+ /**
461
+ * Removes and returns the root element (minimum based on comparator)
462
+ * @throws {CollectionIsEmptyException} If the heap is empty.
463
+ */
464
+ extractMin(): T;
465
+ /** Default comparison for primitive types */
466
+ private defaultComparator;
467
+ private parentIndex;
468
+ private leftChildIndex;
469
+ private rightChildIndex;
470
+ private swap;
471
+ /** Moves an element up until heap properties are restored */
472
+ private bubbleUp;
473
+ /** Moves an element down until heap properties are restored */
474
+ private bubbleDown;
475
+ /** Returns an iterator over the underlying array */
476
+ [Symbol.iterator](): IterableIterator<T>;
477
+ }
478
+ export type FnCompareTwo<T> = (firstItem: T, secondItem: T) => boolean;
479
+ declare abstract class AbstractBinaryNode<T> {
480
+ protected _data: T;
481
+ protected _left: AbstractBinaryNode<T> | null;
482
+ protected _right: AbstractBinaryNode<T> | null;
483
+ protected _parent: AbstractBinaryNode<T> | null;
484
+ protected constructor(initialData: T);
485
+ get data(): T;
486
+ set data(value: T);
487
+ get left(): AbstractBinaryNode<T> | null;
488
+ set left(value: AbstractBinaryNode<T> | null);
489
+ get right(): AbstractBinaryNode<T> | null;
490
+ set right(value: AbstractBinaryNode<T> | null);
491
+ get parent(): AbstractBinaryNode<T> | null;
492
+ set parent(value: AbstractBinaryNode<T> | null);
493
+ }
494
+ declare abstract class AbstractBinaryTree<T> implements IBinaryTree<T> {
495
+ /**
496
+ * Function that checks is node A better
497
+ * @default a > b
498
+ * @example 5 > 4
499
+ * @example 'abc' > 'aba'
500
+ */
501
+ protected compare: FnCompareTwo<T>;
502
+ protected _head: AbstractBinaryNode<T> | null;
503
+ protected _length: number;
504
+ /**
505
+ *
506
+ * @param fnCompare
507
+ * @protected
508
+ */
509
+ protected constructor(fnCompare?: FnCompareTwo<T>);
510
+ /**
511
+ * Returns nodes count in the entire tree
512
+ */
513
+ length(): number;
514
+ /**
515
+ * Will create new node and place it according to the type of tree rules
516
+ */
517
+ abstract insert(value: T): void;
518
+ /**
519
+ * Will check if tree has a node with given data
520
+ */
521
+ abstract has(value: T): boolean;
522
+ /**
523
+ * Will delete node from the tree and restructure it
524
+ */
525
+ abstract delete(value: T): void;
526
+ /**
527
+ * Max value of the tree
528
+ */
529
+ abstract max(): T;
530
+ /**
531
+ * Min value of the tree
532
+ */
533
+ abstract min(): T;
534
+ /**
535
+ * Returns same class instance with new head node
536
+ */
537
+ abstract subtree(value: T): IBinaryTree<T>;
538
+ /**
539
+ * Returns the highest branch length in the tree
540
+ */
541
+ abstract height(): number;
542
+ /**
543
+ * In-order/Pre-order/Post-order traversing of the tree
544
+ */
545
+ abstract traverse(type: EnumTreeTraversalType): Array<T>;
546
+ }
547
+ declare class BinarySearchNode<T> extends AbstractBinaryNode<T> {
548
+ protected _left: BinarySearchNode<T> | null;
549
+ protected _right: BinarySearchNode<T> | null;
550
+ protected _parent: BinarySearchNode<T> | null;
551
+ constructor(initialData: T);
552
+ get left(): BinarySearchNode<T> | null;
553
+ set left(value: BinarySearchNode<T> | null);
554
+ get right(): BinarySearchNode<T> | null;
555
+ set right(value: BinarySearchNode<T> | null);
556
+ get parent(): BinarySearchNode<T> | null;
557
+ set parent(value: BinarySearchNode<T> | null);
558
+ }
559
+ /**
560
+ * Unbalanced binary search tree implementation
561
+ */
562
+ export declare class BinarySearchTree<T> extends AbstractBinaryTree<T> {
563
+ /**
564
+ * Override types
565
+ */
566
+ protected _head: BinarySearchNode<T> | null;
567
+ /**
568
+ * @inheritDoc
569
+ */
570
+ constructor(fnCompare?: FnCompareTwo<T>);
571
+ /**
572
+ *
573
+ * @throws {CollectionIsEmptyException} when tree is empty
574
+ */
575
+ protected checkIsEmpty(): void;
576
+ /**
577
+ * Will update left and right links parent with current node
578
+ */
579
+ protected updateLeftRightParents(node: BinarySearchNode<T>): void;
580
+ /**
581
+ * Will return node instance by its data
582
+ */
583
+ protected findNode(value: T): BinarySearchNode<T> | null;
584
+ /**
585
+ * @inheritDoc
586
+ */
587
+ protected insertToLeaf(createdNode: BinarySearchNode<T>): void;
588
+ /**
589
+ * Will join two trees into one */
590
+ protected join(treeLeft: BinarySearchNode<T> | null, treeRight: BinarySearchNode<T> | null): BinarySearchNode<T> | null;
591
+ /**
592
+ * @inheritDoc
593
+ * @throws {CollectionIsEmptyException} when tree is empty
594
+ */
595
+ max(): T;
596
+ /**
597
+ * @inheritDoc
598
+ * @throws {CollectionIsEmptyException} when tree is empty
599
+ */
600
+ min(): T;
601
+ /**
602
+ * @inheritDoc
603
+ * @throws {IsAlreadyExistsException} when node already exists
604
+ */
605
+ insert(value: T): void;
606
+ /**
607
+ * @inheritDoc
608
+ */
609
+ has(value: T): boolean;
610
+ /**
611
+ * @inheritDoc
612
+ * @throws {IsNotFoundException} when node was not found
613
+ */
614
+ delete(value: T): void;
615
+ /**
616
+ * @inheritDoc
617
+ */
618
+ subtree(value: T): IBinaryTree<T>;
619
+ /**
620
+ * @inheritDoc
621
+ * @throws {CollectionIsEmptyException} when tree is empty
622
+ */
623
+ traverse(type: EnumTreeTraversalType, from?: T): Array<T>;
624
+ private storeInOrder;
625
+ private storePreOrder;
626
+ private storePostOrder;
627
+ /**
628
+ * Calc max height of the largest branch of the tree
629
+ */
630
+ height(): number;
631
+ }
632
+ declare class RandBinarySearchNode<T> extends BinarySearchNode<T> {
633
+ private _rank;
634
+ protected _left: RandBinarySearchNode<T> | null;
635
+ protected _right: RandBinarySearchNode<T> | null;
636
+ protected _parent: RandBinarySearchNode<T> | null;
637
+ constructor(initialData: T);
638
+ get rank(): number;
639
+ set rank(value: number);
640
+ get left(): RandBinarySearchNode<T> | null;
641
+ set left(value: RandBinarySearchNode<T> | null);
642
+ get right(): RandBinarySearchNode<T> | null;
643
+ set right(value: RandBinarySearchNode<T> | null);
644
+ get parent(): RandBinarySearchNode<T> | null;
645
+ set parent(value: RandBinarySearchNode<T> | null);
646
+ }
647
+ /**
648
+ * Randomized binary search tree implementation
649
+ */
650
+ export declare class RandBinarySearchTree<T> extends BinarySearchTree<T> {
651
+ /**
652
+ * Override types
653
+ */
654
+ protected _head: RandBinarySearchNode<T> | null;
655
+ /**
656
+ * @inheritDoc
657
+ */
658
+ constructor(fnCompare?: FnCompareTwo<T>);
659
+ /**
660
+ * Will update node rank by summing left and right subtrees tanks and itself rank (1)
661
+ */
662
+ private updateRank;
663
+ /**
664
+ * Will set rank and parent attributes and update tree length
665
+ */
666
+ private addCreatedNode;
667
+ /**
668
+ * Will rotate node to the right side
669
+ */
670
+ private rotateNodeRight;
671
+ /**
672
+ * Will rotate node to the left side
673
+ */
674
+ private rotateNodeLeft;
675
+ /**
676
+ * @inheritDoc
677
+ */
678
+ protected join(treeLeft: RandBinarySearchNode<T> | null, treeRight: RandBinarySearchNode<T> | null): RandBinarySearchNode<T> | null;
679
+ /**
680
+ * @inheritDoc
681
+ */
682
+ protected updateLeftRightParents(node: RandBinarySearchNode<T>): void;
683
+ /**
684
+ * @inheritDoc
685
+ */
686
+ protected insertToRoot(createdNode: RandBinarySearchNode<T>, fromNode?: RandBinarySearchNode<T>): void;
687
+ /**
688
+ * @inheritDoc
689
+ */
690
+ protected insertRandomly(createdNode: RandBinarySearchNode<T>): void;
691
+ /**
692
+ * @inheritDoc
693
+ * @throws {IsAlreadyExistsException} when node already exists
694
+ */
695
+ insert(value: T): void;
696
+ /**
697
+ * @inheritDoc
698
+ */
699
+ delete(value: T): void;
700
+ length(): number;
701
+ }
702
+ declare abstract class AbstractLinkedNode<T> {
703
+ protected _next: AbstractLinkedNode<T> | null;
704
+ protected readonly _data: T;
705
+ /**
706
+ * Will create empty node
707
+ */
708
+ protected constructor(data: T, next?: AbstractLinkedNode<T> | null);
709
+ /**
710
+ * Get data of node
711
+ */
712
+ get data(): T;
713
+ /**
714
+ * Get next node link
715
+ */
716
+ get next(): AbstractLinkedNode<T> | null;
717
+ /**
718
+ * Set next node link
719
+ */
720
+ set next(value: AbstractLinkedNode<T> | null);
721
+ }
722
+ declare abstract class AbstractLinkedList<T> implements ILinkedList<T> {
723
+ protected readonly _capacity: number;
724
+ protected _length: number;
725
+ protected _head: AbstractLinkedNode<T> | null;
726
+ protected _tail: AbstractLinkedNode<T> | null;
727
+ /**
728
+ * Create empty instance
729
+ */
730
+ protected constructor(capacity?: number);
731
+ /**
732
+ * Will calculate real capacity value
733
+ * @throws {ValueOutOfRangeException} when capacity is out of range
734
+ */
735
+ private static calculateCapacity;
736
+ /**
737
+ * Will insert node between nodeLeft and nodeRight
738
+ * @throws {CollectionIsFullException} when list is full
739
+ */
740
+ private insertNodeBetweenTwoNodes;
741
+ /**
742
+ * Will remove the node from its neighbors nodes links
743
+ * @throws {CollectionIsEmptyException} when list is empty
744
+ */
745
+ private deleteNode;
746
+ /**
747
+ * Will find node by its index
748
+ * @throws {CollectionIsEmptyException} when list is empty
749
+ * @throws {IndexOutOfBoundsException} when given index is out of range
750
+ */
751
+ protected getNodeByIndex(index: number): AbstractLinkedNode<T>;
752
+ /**
753
+ * Will set links between target, left and right siblings
754
+ */
755
+ protected abstract insertNodeBetweenTwoNodesImpl(nodeToPush: AbstractLinkedNode<T>, nodeLeft: AbstractLinkedNode<T>, nodeRight: AbstractLinkedNode<T>): void;
756
+ /**
757
+ * Will unset itself links and its neighbors links
758
+ */
759
+ protected abstract deleteNodeImpl(node: AbstractLinkedNode<T>): void;
760
+ /**
761
+ * Update head link
762
+ */
763
+ protected abstract popImpl(): void;
764
+ /**
765
+ * Update tail link
766
+ */
767
+ protected abstract shiftImpl(): void;
768
+ /**
769
+ * Will create empty node instance
770
+ */
771
+ protected abstract createNode(value: T): AbstractLinkedNode<T>;
772
+ /**
773
+ * Push into start
774
+ * @throws {CollectionIsFullException} when there is no space available
775
+ */
776
+ unshift(value: T): void;
777
+ /**
778
+ * Push into end
779
+ * @throws {CollectionIsFullException} when there is no space available
780
+ */
781
+ push(value: T): void;
782
+ /**
783
+ * Push from index
784
+ * @throws {IndexOutOfBoundsException} when given index is out of range
785
+ * @throws {CollectionIsFullException} when there is no space available
786
+ */
787
+ pushFromIndex(value: T, fromIndex: number): void;
788
+ /**
789
+ * Delete node from list's end
790
+ * @throws {CollectionIsEmptyException} when list is empty
791
+ */
792
+ pop(): T;
793
+ /**
794
+ * Delete node from list's start and get its data
795
+ * @throws {CollectionIsEmptyException} when list is empty
796
+ */
797
+ shift(): T;
798
+ /**
799
+ * Delete node from list by index from start
800
+ * @throws {CollectionIsEmptyException} when list is empty
801
+ */
802
+ deleteFromIndex(fromIndex: number): T;
803
+ /**
804
+ * List length
805
+ */
806
+ length(): number;
807
+ /**
808
+ * Is list empty
809
+ */
810
+ isEmpty(): boolean;
811
+ /**
812
+ * Is list full
813
+ */
814
+ isFull(): boolean;
815
+ /**
816
+ * Check if element exists in list
817
+ */
818
+ has(item: T): boolean;
819
+ /**
820
+ * Get head element data
821
+ * @throws {CollectionIsEmptyException} when head does not exist
822
+ */
823
+ peek(): T;
824
+ /**
825
+ * Get tail element data
826
+ * @throws {CollectionIsEmptyException} when tail does not exists
827
+ */
828
+ peekFromStart(): T;
829
+ /**
830
+ * Get list element by index from start
831
+ * @throws {CollectionIsEmptyException} when list is empty
832
+ * @throws {IndexOutOfBoundsException} when given index is out of range
833
+ */
834
+ peekByIndex(index: number): T;
835
+ /**
836
+ * Remove all elements from list
837
+ */
838
+ clear(): void;
839
+ /**
840
+ * Get elements as an array
841
+ */
842
+ getAsArray(): Array<T>;
843
+ /**
844
+ * Add elements to list from array
845
+ * @throws {CollectionIsFullException} when list is full
846
+ * */
847
+ pushFromArray(elements: Array<T>): void;
848
+ /**
849
+ * Reverse list nodes links and swap head with tail
850
+ * @example "4>7>10" will be reversed to "10>7>4"
851
+ */
852
+ abstract reverse(): void;
853
+ /**
854
+ * Iterator
855
+ */
856
+ [Symbol.iterator](): IterableIterator<T>;
857
+ }
858
+ declare class DoubleLinkedNode<T> extends AbstractLinkedNode<T> {
859
+ protected _prev: DoubleLinkedNode<T> | null;
860
+ protected _next: DoubleLinkedNode<T> | null;
861
+ /**
862
+ * Will create empty node
863
+ */
864
+ constructor(data: T, next?: DoubleLinkedNode<T> | null, prev?: DoubleLinkedNode<T> | null);
865
+ /**
866
+ * Set previous node link
867
+ */
868
+ set prev(value: DoubleLinkedNode<T> | null);
869
+ /**
870
+ * Get previous node link
871
+ */
872
+ get prev(): DoubleLinkedNode<T> | null;
873
+ /**
874
+ * @inheritDoc
875
+ */
876
+ set next(value: DoubleLinkedNode<T> | null);
877
+ /**
878
+ * @inheritDoc
879
+ */
880
+ get next(): DoubleLinkedNode<T> | null;
881
+ }
882
+ /**
883
+ * Linear data structure
884
+ * Each node has next and prev sibling
885
+ * Head and tail are linked to each other
886
+ */
887
+ export declare class DoubleLinkedList<T> extends AbstractLinkedList<T> {
888
+ /**
889
+ * Override types
890
+ */
891
+ protected _head: DoubleLinkedNode<T> | null;
892
+ protected _tail: DoubleLinkedNode<T> | null;
893
+ /**
894
+ * @inheritDoc
895
+ */
896
+ constructor(capacity?: number);
897
+ /**
898
+ * @inheritDoc
899
+ */
900
+ protected createNode(value: T): DoubleLinkedNode<T>;
901
+ /**
902
+ * @inheritDoc
903
+ */
904
+ protected insertNodeBetweenTwoNodesImpl(targetNode: DoubleLinkedNode<T>, leftNode: DoubleLinkedNode<T>, rightNode: DoubleLinkedNode<T>): void;
905
+ /**
906
+ * @inheritDoc
907
+ */
908
+ protected deleteNodeImpl(node: DoubleLinkedNode<T>): void;
909
+ /**
910
+ * @inheritDoc
911
+ */
912
+ protected popImpl(): void;
913
+ /**
914
+ * @inheritDoc
915
+ */
916
+ protected shiftImpl(): void;
917
+ /**
918
+ * @inheritDoc
919
+ */
920
+ reverse(): void;
921
+ }
922
+ export interface IIterable<T> {
923
+ iterator(fromIndex?: number): IIterator<T>;
924
+ }
925
+ declare class SingleLinkedNode<T> extends AbstractLinkedNode<T> {
926
+ /**
927
+ * @inheritDoc
928
+ */
929
+ constructor(data: T, next?: SingleLinkedNode<T> | null);
930
+ }
931
+ /**
932
+ * Linear data structure
933
+ * Each node has next
934
+ * Head's next node is tail
935
+ */
936
+ export declare class SingleLinkedList<T> extends AbstractLinkedList<T> {
937
+ /**
938
+ * Override types
939
+ */
940
+ protected _head: SingleLinkedNode<T> | null;
941
+ protected _tail: SingleLinkedNode<T> | null;
942
+ /**
943
+ * @inheritDoc
944
+ */
945
+ constructor(capacity?: number);
946
+ /**
947
+ * Find previous sibling of given node
948
+ */
949
+ private getPrevNode;
950
+ /**
951
+ * @inheritDoc
952
+ */
953
+ protected createNode(value: T): SingleLinkedNode<T>;
954
+ /**
955
+ * @inheritDoc
956
+ */
957
+ protected insertNodeBetweenTwoNodesImpl(targetNode: SingleLinkedNode<T>, leftNode: SingleLinkedNode<T>, rightNode: SingleLinkedNode<T>): void;
958
+ /**
959
+ * @inheritDoc
960
+ */
961
+ protected deleteNodeImpl(node: SingleLinkedNode<T>): void;
962
+ /**
963
+ * @inheritDoc
964
+ */
965
+ protected popImpl(): void;
966
+ /**
967
+ * @inheritDoc
968
+ */
969
+ protected shiftImpl(): void;
970
+ /**
971
+ * @inheritDoc
972
+ */
973
+ reverse(): void;
974
+ }
975
+ /**
976
+ * @inheritDoc
977
+ */
978
+ export declare class IterableSingleLinkedList<T> extends SingleLinkedList<T> implements IIterable<T> {
979
+ /**
980
+ * @inheritDoc
981
+ */
982
+ constructor(capacity?: number);
983
+ /**
984
+ * List iterator
985
+ * @throws {CollectionIsEmptyException} when list is empty
986
+ * @throws {IndexOutOfBoundsException} when given index is out of range
987
+ */
988
+ iterator(fromIndex?: number): IIterator<T>;
989
+ }
990
+ export interface IBiDirectIterator<T> extends IIterator<T> {
991
+ /**
992
+ * Will do one iteration back and returns prev item value
993
+ */
994
+ prev(): T;
995
+ /**
996
+ * Check if next element exists
997
+ */
998
+ hasPrev(): boolean;
999
+ }
1000
+ export interface IBiDirectIterable<T> extends IIterable<T> {
1001
+ iterator(fromIndex?: number): IBiDirectIterator<T>;
1002
+ }
1003
+ /**
1004
+ * @inheritDoc
1005
+ */
1006
+ export declare class IterableDoubleLinkedList<T> extends DoubleLinkedList<T> implements IBiDirectIterable<T> {
1007
+ /**
1008
+ * @inheritDoc
1009
+ */
1010
+ constructor(capacity?: number);
1011
+ /**
1012
+ * List iterator
1013
+ * @throws {CollectionIsEmptyException} when list is empty
1014
+ * @throws {IndexOutOfBoundsException} when given index is out of range
1015
+ */
1016
+ iterator(fromIndex?: number): IBiDirectIterator<T>;
1017
+ }
1018
+ declare class GraphEdge<T> {
1019
+ private readonly _fromVertex;
1020
+ private readonly _toVertex;
1021
+ private _weight;
1022
+ /**
1023
+ * Create instance with linked "from" and "to" vertices
1024
+ */
1025
+ constructor(fromVertex: T, toVertex: T, weight?: number);
1026
+ get fromVertex(): T;
1027
+ get toVertex(): T;
1028
+ get weight(): number;
1029
+ set weight(value: number);
1030
+ }
1031
+ declare abstract class AbstractGraph<T> {
1032
+ protected _vertices: Map<T, Set<T>>;
1033
+ protected _edges: Map<string, GraphEdge<T>>;
1034
+ /**
1035
+ * Created empty instance
1036
+ */
1037
+ protected constructor();
1038
+ protected static readonly EDGE_KEY_SEPARATOR: string;
1039
+ /**
1040
+ * Get edge key string from_to
1041
+ * @example Bob_Maria
1042
+ * @example Maria_Bob
1043
+ */
1044
+ protected getEdgeKey(from: T, to: T): string;
1045
+ /**
1046
+ * Find edge by its from and to vertices
1047
+ */
1048
+ protected abstract getEdgeByValue(from: T, to: T): GraphEdge<T>;
1049
+ /**
1050
+ * Get vertices list in array format
1051
+ */
1052
+ protected getVerticesArrayFormat(): Array<T>;
1053
+ /**
1054
+ * Find vertex in vertices list by its data
1055
+ * @throws {IsNotFoundException} when vertex was not found
1056
+ */
1057
+ protected tryFindVertex(data: T): T;
1058
+ /**
1059
+ * Update edge weight between from and to vertices
1060
+ */
1061
+ protected updateEdgeWeight(from: T, to: T, weight: number): void;
1062
+ /**
1063
+ * Will remove all vertex relations with others vertices
1064
+ */
1065
+ protected cascadeRemoveVertexRelations(vertexToRemove: T): void;
1066
+ /**
1067
+ * Will remove all vertices edges with vertex to remove
1068
+ */
1069
+ protected cascadeRemoveVertexEdges(vertexToRemove: T): void;
1070
+ /**
1071
+ * Get sum of all graph edges
1072
+ */
1073
+ weight(): number;
1074
+ /**
1075
+ * Get array of vertices
1076
+ */
1077
+ vertices(): Array<T>;
1078
+ /**
1079
+ * Get vertices count
1080
+ */
1081
+ verticesCount(): number;
1082
+ /**
1083
+ * Get edges count
1084
+ */
1085
+ edgesCount(): number;
1086
+ /**
1087
+ * Add vertex
1088
+ * @throws {IsAlreadyExistsException} when vertex is already exists
1089
+ */
1090
+ addVertex(data: T): this;
1091
+ /**
1092
+ * Remove vertex
1093
+ * @throws {IsNotFoundException} when vertex is already does not exist
1094
+ */
1095
+ removeVertex(data: T): this;
1096
+ /**
1097
+ * Add edge between two vertices
1098
+ */
1099
+ abstract addEdge(from: T, to: T, weight?: number): this;
1100
+ /**
1101
+ * Remove edge between two vertices
1102
+ */
1103
+ abstract removeEdge(from: T, to: T): this;
1104
+ /**
1105
+ * Get vertex neighbors by its data
1106
+ */
1107
+ getVertexNeighbors(data: T): Array<T>;
1108
+ /**
1109
+ * Check if graph has vertex
1110
+ */
1111
+ hasVertex(data: T): boolean;
1112
+ /**
1113
+ * Check if graph has edge between from and to vertices
1114
+ */
1115
+ hasEdge(from: T, to: T): boolean;
1116
+ /**
1117
+ * Get edge weight between from and to vertices
1118
+ */
1119
+ getEdgeWeight(from: T, to: T): number;
1120
+ /**
1121
+ * Iterator
1122
+ */
1123
+ [Symbol.iterator](): IterableIterator<T>;
1124
+ }
1125
+ /**
1126
+ * Directed graph - data structure where edges with same pair of vertices are not equal
1127
+ * @example A-B is not the same as B-A
1128
+ */
1129
+ export declare class DirectedGraph<T> extends AbstractGraph<T> {
1130
+ /**
1131
+ * @inheritDoc
1132
+ */
1133
+ constructor();
1134
+ /**
1135
+ * @inheritDoc
1136
+ * @throws {IsNotFoundException} when vertex was not found
1137
+ */
1138
+ protected getEdgeByValue(from: T, to: T): GraphEdge<T>;
1139
+ /**
1140
+ * @inheritDoc
1141
+ * @throws {IsNotFoundException} when vertex was not found
1142
+ */
1143
+ addEdge(from: T, to: T, weight?: number): this;
1144
+ /**
1145
+ * @inheritDoc
1146
+ * @throws {IsNotFoundException} when vertex was not found
1147
+ */
1148
+ removeEdge(from: T, to: T): this;
1149
+ /**
1150
+ * @inheritDoc
1151
+ */
1152
+ removeVertex(value: T): this;
1153
+ }
1154
+ /**
1155
+ * Undirected graph - data structure where edges with same pair of vertices are equal
1156
+ * @example A-B is same as B-A
1157
+ */
1158
+ export declare class UndirectedGraph<T> extends AbstractGraph<T> {
1159
+ /**
1160
+ * @inheritDoc
1161
+ */
1162
+ constructor();
1163
+ protected getEdgeKey(from: T, to: T): string;
1164
+ /**
1165
+ * @inheritDoc
1166
+ * @throws {IsNotFoundException} when vertex was not found
1167
+ */
1168
+ protected getEdgeByValue(from: T, to: T): GraphEdge<T>;
1169
+ /**
1170
+ * @inheritDoc
1171
+ */
1172
+ hasEdge(from: T, to: T): boolean;
1173
+ /**
1174
+ * @inheritDoc
1175
+ * @throws {IsNotFoundException} when vertex was not found
1176
+ */
1177
+ addEdge(from: T, to: T, weight?: number): this;
1178
+ /**
1179
+ * @inheritDoc
1180
+ * @throws {IsNotFoundException} when vertex was not found
1181
+ */
1182
+ removeEdge(from: T, to: T): this;
1183
+ }
1184
+ export declare class IllegalStateException extends Error {
1185
+ constructor(message: string);
1186
+ }
1187
+ export declare class IsNotFoundException extends IllegalStateException {
1188
+ constructor(message: string);
1189
+ }
1190
+ export declare class IsAlreadyExistsException extends IllegalStateException {
1191
+ constructor(message: string);
1192
+ }
1193
+ export declare class IllegalArgumentException extends Error {
1194
+ constructor(message: string);
1195
+ }
1196
+ export declare class ValueOutOfRangeException extends IllegalArgumentException {
1197
+ constructor(message: string);
1198
+ }
1199
+ export declare class IndexOutOfBoundsException extends IllegalArgumentException {
1200
+ constructor(message: string);
1201
+ }
1202
+ export declare class CollectionIsEmptyException extends IllegalStateException {
1203
+ constructor(message: string);
1204
+ }
1205
+ export declare class CollectionIsFullException extends IllegalStateException {
1206
+ constructor(message: string);
1207
+ }
1208
+ /**
1209
+ * Bubble sorting algorithm
1210
+ *
1211
+ * @description
1212
+ * Time complexity: Best O(n); Avg O(n \^ 2); Worst O(n \^ 2)
1213
+ * @description
1214
+ * Memory complexity: Worst case: O(1)
1215
+ */
1216
+ export declare const bubbleSort: (arr: Array<number>) => Array<number>;
1217
+ /**
1218
+ * Selection sorting algorithm
1219
+ *
1220
+ * @description
1221
+ * Time complexity: Best O(n \^ 2); Avg O(n \^ 2); Worst O(n \^ 2)
1222
+ * @description
1223
+ * Memory complexity: Worst case: O(1)
1224
+ */
1225
+ export declare const selectSort: (arr: Array<number>) => Array<number>;
1226
+ /**
1227
+ * Merge sorting algorithm
1228
+ *
1229
+ * @description
1230
+ * Time complexity: Best O(n * log(n)); Avg O(n * log(n)); Worst O(n * log(n))
1231
+ * @description
1232
+ * Memory complexity: Worst case: O(n)
1233
+ */
1234
+ export declare const mergeSort: (arr: Array<number>) => Array<number>;
1235
+ /**
1236
+ * Insertion sorting algorithm
1237
+ *
1238
+ * @description
1239
+ * Time complexity: Best O(n); Avg O(n \^ 2); Worst O(n \^ 2);
1240
+ * @description
1241
+ * Memory complexity: Worst case: O(1)
1242
+ */
1243
+ export declare const insertionSort: (arr: Array<number>) => Array<number>;
1244
+ /**
1245
+ * Quick sort algorithm
1246
+ *
1247
+ * @description
1248
+ * Time complexity: Best O(n * log(n)); Avg O(n * log(n)); Worst O(n ^2)
1249
+ * @description
1250
+ * Memory complexity: Worst case: O(1)
1251
+ */
1252
+ export declare const quickSort: (arr: Array<number>) => Array<number>;
1253
+ /**
1254
+ * Wrapper function that storing the results of calls and returning the cached result when the same inputs occur again
1255
+ */
1256
+ export declare const memoize: <Key, Value>(fn: FnToMemoize<Key, Value>) => FnToMemoize<Key, Value>;
1257
+ /**
1258
+ * Will find min value in the whole array and return its index
1259
+ */
1260
+ export declare const getMinIndex: (arr: Array<number>) => number;
1261
+ /**
1262
+ * Will find min value in range between fromIndex and end of array
1263
+ */
1264
+ export declare const getMinIndexFromIndex: (arr: Array<number>, fromIndex: number) => number;
1265
+ /**
1266
+ * Round number to given digits after
1267
+ */
1268
+ export declare const roundNumber: (num: number, digits?: number) => number;
1269
+ /**
1270
+ * Get random number in range
1271
+ */
1272
+ export declare const randomizeNumberInRange: (min: number, max: number) => number;
1273
+ /**
1274
+ * Will swap two items in array
1275
+ * @example swapArrayItems([2,3,5], 1, 2) -> [2,5,3]
1276
+ */
1277
+ export declare const swapArrayItems: <T>(arr: Array<T>, leftIndex: number, rightIndex: number) => void;
1278
+
1279
+ export {};