@raikuxq/alg-ds 1.1.6 → 1.2.1

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 (184) hide show
  1. package/README.md +71 -88
  2. package/lib/app/algorithms/binary-search.d.ts +5 -0
  3. package/lib/app/algorithms/binary-search.js +27 -0
  4. package/lib/app/algorithms/factorial.d.ts +9 -0
  5. package/lib/app/algorithms/factorial.js +17 -0
  6. package/lib/app/algorithms/fibonacci.d.ts +9 -0
  7. package/lib/app/algorithms/fibonacci.js +17 -0
  8. package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.d.ts +35 -0
  9. package/lib/app/algorithms/graph/iterator/AbstractGraphIterator.js +83 -0
  10. package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.d.ts +28 -0
  11. package/lib/app/algorithms/graph/iterator/GraphIteratorBFS.js +70 -0
  12. package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.d.ts +28 -0
  13. package/lib/app/algorithms/graph/iterator/GraphIteratorDFS.js +70 -0
  14. package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.d.ts +32 -0
  15. package/lib/app/algorithms/graph/iterator/GraphIteratorDijkstra.js +97 -0
  16. package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.d.ts +6 -0
  17. package/lib/app/algorithms/graph/iterator-strategy/BFSIterationStrategy.js +13 -0
  18. package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.d.ts +6 -0
  19. package/lib/app/algorithms/graph/iterator-strategy/DFSIterationStrategy.js +13 -0
  20. package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.d.ts +6 -0
  21. package/lib/app/algorithms/graph/iterator-strategy/DijkstraIterationStrategy.js +13 -0
  22. package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.d.ts +19 -0
  23. package/lib/app/algorithms/graph/presenter/presenterAdjacencyLists.js +28 -0
  24. package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.d.ts +32 -0
  25. package/lib/app/algorithms/graph/presenter/presenterAdjacencyMatrix.js +48 -0
  26. package/lib/app/algorithms/graph/searching/hasPath.d.ts +9 -0
  27. package/lib/app/algorithms/graph/searching/hasPath.js +30 -0
  28. package/lib/app/algorithms/graph/searching/shortestPath.d.ts +9 -0
  29. package/lib/app/algorithms/graph/searching/shortestPath.js +30 -0
  30. package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.d.ts +2 -0
  31. package/lib/app/algorithms/graph/transposing/transposeDirectedGraph.js +14 -0
  32. package/lib/app/algorithms/memoize.d.ts +5 -0
  33. package/lib/app/algorithms/memoize.js +22 -0
  34. package/lib/app/algorithms/sorts/bubble-sort.d.ts +9 -0
  35. package/lib/app/algorithms/sorts/bubble-sort.js +23 -0
  36. package/lib/app/algorithms/sorts/insertion-sort.d.ts +9 -0
  37. package/lib/app/algorithms/sorts/insertion-sort.js +25 -0
  38. package/lib/app/algorithms/sorts/merge-sort.d.ts +9 -0
  39. package/lib/app/algorithms/sorts/merge-sort.js +61 -0
  40. package/lib/app/algorithms/sorts/quick-sort.d.ts +9 -0
  41. package/lib/app/algorithms/sorts/quick-sort.js +45 -0
  42. package/lib/app/algorithms/sorts/select-sort.d.ts +9 -0
  43. package/lib/app/algorithms/sorts/select-sort.js +20 -0
  44. package/lib/app/algorithms/transpose-matrix.d.ts +5 -0
  45. package/lib/app/algorithms/transpose-matrix.js +18 -0
  46. package/lib/app/constants.d.ts +2 -0
  47. package/lib/app/constants.js +6 -0
  48. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +15 -0
  49. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +53 -0
  50. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +60 -0
  51. package/lib/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +36 -0
  52. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +13 -0
  53. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +59 -0
  54. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +70 -0
  55. package/lib/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +271 -0
  56. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +16 -0
  57. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +70 -0
  58. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +57 -0
  59. package/lib/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +235 -0
  60. package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.d.ts +6 -0
  61. package/lib/app/data-structures/BinaryTree/_helpers/createBinaryTree.js +22 -0
  62. package/lib/app/data-structures/Graph/AbstractGraph.d.ts +84 -0
  63. package/lib/app/data-structures/Graph/AbstractGraph.js +143 -0
  64. package/lib/app/data-structures/Graph/DirectedGraph.d.ts +24 -0
  65. package/lib/app/data-structures/Graph/DirectedGraph.js +86 -0
  66. package/lib/app/data-structures/Graph/GraphEdge.d.ts +16 -0
  67. package/lib/app/data-structures/Graph/GraphEdge.js +43 -0
  68. package/lib/app/data-structures/Graph/UndirectedGraph.d.ts +28 -0
  69. package/lib/app/data-structures/Graph/UndirectedGraph.js +103 -0
  70. package/lib/app/data-structures/Graph/_helpers/createGraph.d.ts +6 -0
  71. package/lib/app/data-structures/Graph/_helpers/createGraph.js +22 -0
  72. package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.d.ts +7 -0
  73. package/lib/app/data-structures/Graph/_helpers/createGraphFromMatrix.js +42 -0
  74. package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.d.ts +4 -0
  75. package/lib/app/data-structures/Graph/_helpers/generateRandomGraph.js +67 -0
  76. package/lib/app/data-structures/HashTable/HashTable.d.ts +73 -0
  77. package/lib/app/data-structures/HashTable/HashTable.js +171 -0
  78. package/lib/app/data-structures/HashTable/HashTableNode.d.ts +11 -0
  79. package/lib/app/data-structures/HashTable/HashTableNode.js +39 -0
  80. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +125 -0
  81. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +241 -0
  82. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +20 -0
  83. package/lib/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +41 -0
  84. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +48 -0
  85. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +151 -0
  86. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +25 -0
  87. package/lib/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +65 -0
  88. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +52 -0
  89. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +138 -0
  90. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts +7 -0
  91. package/lib/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +29 -0
  92. package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.d.ts +3 -0
  93. package/lib/app/data-structures/LinkedList/_helpers/createLinkedList.js +19 -0
  94. package/lib/app/data-structures/LoopedArray/LoopedArray.d.ts +83 -0
  95. package/lib/app/data-structures/LoopedArray/LoopedArray.js +169 -0
  96. package/lib/app/data-structures/Queue/Queue.d.ts +50 -0
  97. package/lib/app/data-structures/Queue/Queue.js +85 -0
  98. package/lib/app/data-structures/Stack/Stack.d.ts +50 -0
  99. package/lib/app/data-structures/Stack/Stack.js +85 -0
  100. package/lib/app/exceptions/CollectionIsEmptyException.d.ts +4 -0
  101. package/lib/app/exceptions/CollectionIsEmptyException.js +28 -0
  102. package/lib/app/exceptions/CollectionIsFullException.d.ts +4 -0
  103. package/lib/app/exceptions/CollectionIsFullException.js +28 -0
  104. package/lib/app/exceptions/IndexOutOfBoundsException.d.ts +4 -0
  105. package/lib/app/exceptions/IndexOutOfBoundsException.js +28 -0
  106. package/lib/app/exceptions/IsAlreadyExistsException.d.ts +4 -0
  107. package/lib/app/exceptions/IsAlreadyExistsException.js +28 -0
  108. package/lib/app/exceptions/IsNotFoundException.d.ts +4 -0
  109. package/lib/app/exceptions/IsNotFoundException.js +28 -0
  110. package/lib/app/exceptions/ValueOutOfRangeException.d.ts +4 -0
  111. package/lib/app/exceptions/ValueOutOfRangeException.js +28 -0
  112. package/lib/app/exceptions/base/IllegalArgumentException.d.ts +3 -0
  113. package/lib/app/exceptions/base/IllegalArgumentException.js +27 -0
  114. package/lib/app/exceptions/base/IllegalStateException.d.ts +3 -0
  115. package/lib/app/exceptions/base/IllegalStateException.js +27 -0
  116. package/lib/app/types/EnumBinarySearchTreeType.d.ts +4 -0
  117. package/lib/app/types/EnumBinarySearchTreeType.js +9 -0
  118. package/lib/app/types/EnumGraphTraversalType.d.ts +5 -0
  119. package/lib/app/types/EnumGraphTraversalType.js +10 -0
  120. package/lib/app/types/EnumGraphType.d.ts +4 -0
  121. package/lib/app/types/EnumGraphType.js +9 -0
  122. package/lib/app/types/EnumLinkedListType.d.ts +4 -0
  123. package/lib/app/types/EnumLinkedListType.js +9 -0
  124. package/lib/app/types/EnumRandomGenerationFormat.d.ts +4 -0
  125. package/lib/app/types/EnumRandomGenerationFormat.js +9 -0
  126. package/lib/app/types/EnumSortType.d.ts +7 -0
  127. package/lib/app/types/EnumSortType.js +12 -0
  128. package/lib/app/types/EnumTreeTraversalType.d.ts +5 -0
  129. package/lib/app/types/EnumTreeTraversalType.js +10 -0
  130. package/lib/app/types/FnCompareTwo.d.ts +1 -0
  131. package/lib/app/types/FnCompareTwo.js +3 -0
  132. package/lib/app/types/FnToMemoize.d.ts +1 -0
  133. package/lib/app/types/FnToMemoize.js +3 -0
  134. package/lib/app/types/IArrayFacade.d.ts +4 -0
  135. package/lib/app/types/IArrayFacade.js +3 -0
  136. package/lib/app/types/IBiDirectIterable.d.ts +5 -0
  137. package/lib/app/types/IBiDirectIterable.js +3 -0
  138. package/lib/app/types/IBiDirectIterator.d.ts +11 -0
  139. package/lib/app/types/IBiDirectIterator.js +3 -0
  140. package/lib/app/types/IBinaryTree.d.ts +12 -0
  141. package/lib/app/types/IBinaryTree.js +3 -0
  142. package/lib/app/types/IConvertableToArray.d.ts +4 -0
  143. package/lib/app/types/IConvertableToArray.js +3 -0
  144. package/lib/app/types/IGraph.d.ts +14 -0
  145. package/lib/app/types/IGraph.js +3 -0
  146. package/lib/app/types/IGraphIterationStrategy.d.ts +5 -0
  147. package/lib/app/types/IGraphIterationStrategy.js +3 -0
  148. package/lib/app/types/IGraphIterator.d.ts +11 -0
  149. package/lib/app/types/IGraphIterator.js +3 -0
  150. package/lib/app/types/IIterable.d.ts +4 -0
  151. package/lib/app/types/IIterable.js +3 -0
  152. package/lib/app/types/IIterator.d.ts +14 -0
  153. package/lib/app/types/IIterator.js +3 -0
  154. package/lib/app/types/IKeyValueStorage.d.ts +8 -0
  155. package/lib/app/types/IKeyValueStorage.js +3 -0
  156. package/lib/app/types/ILinearStorage.d.ts +11 -0
  157. package/lib/app/types/ILinearStorage.js +3 -0
  158. package/lib/app/types/ILinearStorageRA.d.ts +13 -0
  159. package/lib/app/types/ILinearStorageRA.js +3 -0
  160. package/lib/app/types/ILinkedList.d.ts +4 -0
  161. package/lib/app/types/ILinkedList.js +3 -0
  162. package/lib/app/types/TypeArrayMatrix.d.ts +1 -0
  163. package/lib/app/types/TypeArrayMatrix.js +3 -0
  164. package/lib/app/utils.d.ts +37 -0
  165. package/lib/app/utils.js +114 -0
  166. package/lib/exports/algorithms.d.ts +16 -0
  167. package/lib/exports/algorithms.js +36 -0
  168. package/lib/exports/constants.d.ts +2 -0
  169. package/lib/exports/constants.js +7 -0
  170. package/lib/exports/data-structures.d.ts +11 -0
  171. package/lib/exports/data-structures.js +24 -0
  172. package/lib/exports/helpers.d.ts +6 -0
  173. package/lib/exports/helpers.js +14 -0
  174. package/lib/exports/sorts.d.ts +6 -0
  175. package/lib/exports/sorts.js +14 -0
  176. package/lib/exports/types.d.ts +16 -0
  177. package/lib/exports/types.js +34 -0
  178. package/lib/exports/utils.d.ts +3 -0
  179. package/lib/exports/utils.js +14 -0
  180. package/lib/exports.d.ts +53 -0
  181. package/lib/exports.js +105 -0
  182. package/lib/index.d.ts +3 -0
  183. package/lib/index.js +5 -0
  184. package/package.json +11 -6
package/README.md CHANGED
@@ -2,50 +2,31 @@ Common algorithms and data structures.
2
2
 
3
3
  Written in TypeScript, tested with Jest.
4
4
 
5
+ # Documentation
6
+ Documentation app: [raikuxq-algorithms.netlify.app/guide](https://raikuxq-algorithms.netlify.app/guide)
7
+
5
8
 
6
9
  # Usage as package
7
10
  Install by using any of these commands:
8
11
  + `yarn add @raikuxq/alg-ds`
9
12
  + `npm install @raikuxq/alg-ds --save`
10
13
 
11
- ## Import from root
12
- `import { <anything> } from '@raikuxq/alg-ds'`
13
-
14
- ## Import from sub-paths
15
- ### Data structures
16
- `import {Stack, Queue, SingleLinkedList, DoubleLinkedList, RandBinarySearchTree, BinarySearchTree, DirectedGraph, UndirectedGraph, LoopedArray, HashTable, } from '@raikuxq/alg-ds/lib/exports/data-structures'`
17
- ### Sorting algorithms
18
- `import {bubbleSort, insertionSort, mergeSort, selectSort, quickSort} from '@raikuxq/alg-ds/lib/exports/data-structures `
19
- ### Other algorithms
20
- `import {binarySearch, factorial, memoizedFactorial, memoizedFibonacci, fibonacci, transposeMatrix, GraphIteratorDFS, presenterAdjacencyLists, presenterAdjacencyMatrix, hasPath, shortestPath, DijkstraIterationStrategy, DFSIterationStrategy, BFSIterationStrategy, GraphIteratorBFS, GraphIteratorDijkstra, transposeDirectedGraph} from '@raikuxq/alg-ds/lib/exports/algorithms'`
21
- ### Helpers
22
- `import {createGraph, createGraphFromMatrix, createBinaryTree, createLinkedList, generateRandomGraph} from '@raikuxq/alg-ds/lib/exports/helpers`
23
- ### Utils
24
- `import {perf, getMinIndex, getMinIndexFromIndex, memoize, perfAsync, roundNumber, randomizeNumberInRange, swapArrayItems} from '@raikuxq/alg-ds/lib/exports/utils'`
25
- ### Constants
26
- `import {EDGE_NOT_EXISTS_STATE, EDGE_EXISTS_STATE} from '@raikuxq/alg-ds/lib/exports/constants'`
27
-
28
-
29
14
 
30
15
  # Usage as repository
31
16
 
32
17
  Clone this repository and install dependencies by using `yarn` command.
33
-
34
- + `yarn test` - run all tests via jest
35
-
18
+ + `yarn test` - run all tests via jest
36
19
  + `yarn dev` - run in dev mode via nodemon (src/index.ts is an entrypoint)
37
-
38
20
  + `yarn build` - compile ts sources into js files
39
-
40
21
  + `yarn start` - build and run in production mode
41
-
42
22
  + `yarn lint` - lint check via eslint
43
-
44
23
  + `yarn lint:fix` - fix source files via eslint
45
24
 
46
25
 
47
26
  # Navigation
48
27
  + [Algorithms](#algorithms)
28
+ + [Utils](#utils)
29
+ + [Math](#math)
49
30
  + [Sorting algorithms](#sorting-algorithms)
50
31
  + [Linear data structures](#linear-data-structures)
51
32
  + [Linked list](#linked-list)
@@ -53,35 +34,37 @@ Clone this repository and install dependencies by using `yarn` command.
53
34
  + [Stack](#stack)
54
35
  + [Queue](#queue)
55
36
  + [Non-linear data structures](#non-linear-data-structures)
56
- + [Hash table](#hash-table)
37
+ + [HASH table](#hash-table)
57
38
  + [Graph](#graph)
58
39
  + [Binary tree](#binary-trees)
59
40
 
60
41
 
61
42
  # Algorithms
62
43
 
63
- ## Uncategorized algorithms
64
- [memoize](src/algorithms/memoize.ts) — Memoization util function.
44
+ ## Utils
45
+ [memoize](src/app/algorithms/memoize.ts) — Memoization util function.
65
46
 
66
- [binary-search](src/algorithms/binary-search.ts) [[ tests ](test/unit/algorithms/binary-search.test.ts)] — Binary searching algorithm. Time: O(log(n)).
47
+ ## Searching
48
+ [binary-search](src/app/algorithms/binary-search.ts) [[ tests ](test/unit/algorithms/binary-search.test.ts)] — Binary searching algorithm. Time: O(log(n)).
67
49
 
68
- [factorial](src/algorithms/factorial.ts) [[ tests ](test/unit/algorithms/factorial.test.ts)] — Recursive O(n!) and memoized O(n) factorial implementation.
50
+ ## Math
51
+ [factorial](src/app/algorithms/factorial.ts) [[ tests ](test/unit/algorithms/factorial.test.ts)] — Recursive O(n!) and memoized O(n) factorial implementation.
69
52
 
70
- [fibonacci](src/algorithms/fibonacci.ts) [[ tests ](test/unit/algorithms/fibonacci.test.ts)] — Recursive O(n!) and memoized O(n) factorial implementation.
53
+ [fibonacci](src/app/algorithms/fibonacci.ts) [[ tests ](test/unit/algorithms/fibonacci.test.ts)] — Recursive O(n!) and memoized O(n) factorial implementation.
71
54
 
72
- [transpose-matrix](src/algorithms/transpose-matrix.ts) [[ tests ](test/unit/algorithms/transpose-matrix.test.ts)] — Transpose N*N matrix util function.
55
+ [transpose-matrix](src/app/algorithms/transpose-matrix.ts) [[ tests ](test/unit/algorithms/transpose-matrix.test.ts)] — Transpose N*N matrix util function.
73
56
 
74
57
 
75
58
  ## Sorting algorithms
76
- [bubble-sort](src/algorithms/sorts/bubble-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n) best. Memory: O(1) worst.
59
+ [bubble-sort](src/app/algorithms/sorts/bubble-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n) best. Memory: O(1) worst.
77
60
 
78
- [selection-sort](src/algorithms/sorts/select-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n^2) best. Memory: O(1) worst.
61
+ [selection-sort](src/app/algorithms/sorts/select-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n^2) best. Memory: O(1) worst.
79
62
 
80
- [insertion-sort](src/algorithms/sorts/insertion-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n) best. Memory: O(1) worst.
63
+ [insertion-sort](src/app/algorithms/sorts/insertion-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n^2) avg, O(n) best. Memory: O(1) worst.
81
64
 
82
- [merge-sort](src/algorithms/sorts/merge-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n*log(n)) worst, O(n*log(n)) avg, O(n*log(n)) best. Memory: O(n) worst.
65
+ [merge-sort](src/app/algorithms/sorts/merge-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n*log(n)) worst, O(n*log(n)) avg, O(n*log(n)) best. Memory: O(n) worst.
83
66
 
84
- [quick-sort](src/algorithms/sorts/quick-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n*log(n)) avg, O(n*log(n)) best. Memory: O(1) worst.
67
+ [quick-sort](src/app/algorithms/sorts/quick-sort.ts) [[ tests ](test/unit/algorithms/sorts.test.ts)] — Time: O(n^2) worst, O(n*log(n)) avg, O(n*log(n)) best. Memory: O(1) worst.
85
68
 
86
69
 
87
70
 
@@ -90,154 +73,154 @@ Clone this repository and install dependencies by using `yarn` command.
90
73
  # Linear data structures
91
74
 
92
75
  ### Interfaces
93
- [ILinearStorage](src/types/ILinearStorage.ts) — Contains common methods of linear data structures.
76
+ [ILinearStorage](src/app/types/ILinearStorage.ts) — Contains common methods of linear data structures.
94
77
 
95
- [ILinearStorageRA](src/types/ILinearStorageRA.ts) — Allows random access (from end, from start, by index).
96
- Extends [ILinearStorage](src/types/ILinearStorage.ts) interface.
78
+ [ILinearStorageRA](src/app/types/ILinearStorageRA.ts) — Allows random access (from end, from start, by index).
79
+ Extends [ILinearStorage](src/app/types/ILinearStorage.ts) interface.
97
80
 
98
- [IConvertableToArray](src/types/IConvertableToArray.ts) — Contain methods for converting from/into array.
81
+ [IConvertableToArray](src/app/types/IConvertableToArray.ts) — Contain methods for converting from/into array.
99
82
 
100
83
 
101
84
  ## Linked List
102
85
 
103
86
  ### Interfaces
104
- [ILinkedList](src/types/ILinkedList.ts) — Contains basic linked lists operations.
105
- Extends [ILinearStorageRA](src/types/ILinearStorageRA.ts) and [IConvertableToArray](src/types/IConvertableToArray.ts) interface.
87
+ [ILinkedList](src/app/types/ILinkedList.ts) — Contains basic linked lists operations.
88
+ Extends [ILinearStorageRA](src/app/types/ILinearStorageRA.ts) and [IConvertableToArray](src/app/types/IConvertableToArray.ts) interface.
106
89
 
107
90
  ### Implementation
108
- [AbstractLinkedList](src/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.ts) — Common logic for both single and double linked lists.
109
- Implements [ILinearStorageRA](src/types/ILinearStorageRA.ts) interface.
91
+ [AbstractLinkedList](src/app/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.ts) — Common logic for both single and double linked lists.
92
+ Implements [ILinearStorageRA](src/app/types/ILinearStorageRA.ts) interface.
110
93
 
111
- [SingleLinkedList](src/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.ts)
94
+ [SingleLinkedList](src/app/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.ts)
112
95
  [ [ tests ] ](test/unit/data-structures/linked-list/linked-list.test.ts)
113
96
  — Extends abstract linked list with implementation of one-way linking.
114
- Implements [IIterable](src/types/IIterable.ts) interface.
97
+ Implements [IIterable](src/app/types/IIterable.ts) interface.
115
98
 
116
- [DoubleLinkedList](src/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.ts)
99
+ [DoubleLinkedList](src/app/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.ts)
117
100
  [ [ tests ] ](test/unit/data-structures/linked-list/linked-list.test.ts)
118
101
  — Extends abstract linked list with implementation of two-way linking.
119
- Implements [IBiDirectIterable](src/types/IBiDirectIterable.ts) interface.
102
+ Implements [IBiDirectIterable](src/app/types/IBiDirectIterable.ts) interface.
120
103
 
121
104
 
122
105
  ## Looped Array
123
106
 
124
107
  ### Interfaces
125
- [IArrayFacade](src/types/IArrayFacade.ts) — Contains basic array operations.
126
- Extends [ILinearStorageRA](src/types/ILinearStorageRA.ts) interface.
127
- Extends [IConvertableToArray](src/types/IConvertableToArray.ts) interface.
108
+ [IArrayFacade](src/app/types/IArrayFacade.ts) — Contains basic array operations.
109
+ Extends [ILinearStorageRA](src/app/types/ILinearStorageRA.ts) interface.
110
+ Extends [IConvertableToArray](src/app/types/IConvertableToArray.ts) interface.
128
111
 
129
112
  ### Implementation
130
- [LoopedArray](src/data-structures/LoopedArray/LoopedArray.ts)[ [ tests ]](test/unit/data-structures/looped-array/looped-array.test.ts)
113
+ [LoopedArray](src/app/data-structures/LoopedArray/LoopedArray.ts)[ [ tests ]](test/unit/data-structures/looped-array/looped-array.test.ts)
131
114
  — Overwrites data on capacity overflow.
132
115
 
133
116
  ## Stack
134
117
 
135
118
  ### Implementation
136
- [Stack](src/data-structures/Stack/Stack.ts) [[ tests ](test/unit/data-structures/stack/stack.test.ts)]
137
- — LIFO data structure. Implements [ILinearStorage](src/types/ILinearStorage.ts) interface.
119
+ [Stack](src/app/data-structures/Stack/Stack.ts) [[ tests ](test/unit/data-structures/stack/stack.test.ts)]
120
+ — LIFO data structure. Implements [ILinearStorage](src/app/types/ILinearStorage.ts) interface.
138
121
 
139
122
  ## Queue
140
123
 
141
124
  ### Implementation
142
- [Queue](src/data-structures/Queue/Queue.ts) [[ tests ](test/unit/data-structures/queue/queue.test.ts)]
143
- — FIFO data structure. Implements [ILinearStorage](src/types/ILinearStorage.ts) interface.
125
+ [Queue](src/app/data-structures/Queue/Queue.ts) [[ tests ](test/unit/data-structures/queue/queue.test.ts)]
126
+ — FIFO data structure. Implements [ILinearStorage](src/app/types/ILinearStorage.ts) interface.
144
127
 
145
128
 
146
129
 
147
130
  # Non linear data structures
148
131
 
149
- ## Hash Table
132
+ ## HASH Table
150
133
  ### Interfaces
151
- [IKeyValueStorage](src/types/IKeyValueStorage.ts) — Contains basic key-value storages operations.
134
+ [IKeyValueStorage](src/app/types/IKeyValueStorage.ts) — Contains basic key-value storages operations.
152
135
 
153
136
  ### Implementation
154
- [HashTableNode](src/data-structures/HashTable/HashTableNode.ts) — Contains key, data and isDeleted properties.
137
+ [HashTableNode](src/app/data-structures/HashTable/HashTableNode.ts) — Contains key, data and isDeleted properties.
155
138
 
156
- [HashTable](src/data-structures/HashTable/HashTable.ts) [ [ tests ] ](test/unit/data-structures/hash-table/hash-table.test.ts) — Implementation of open addressing hash table using quadratic probing
139
+ [HashTable](src/app/data-structures/HashTable/HashTable.ts) [ [ tests ] ](test/unit/data-structures/hash-table/hash-table.test.ts) — Implementation of open addressing hash table using quadratic probing
157
140
 
158
141
 
159
142
 
160
143
  ## Graph
161
144
  ### Interfaces
162
- [IGraph](src/types/IGraph.ts) — Contains basic graph operations.
145
+ [IGraph](src/app/types/IGraph.ts) — Contains basic graph operations.
163
146
 
164
- [IGraphIterator](src/types/IGraphIterator.ts) — Extends default iterator with init and getPath methods.
147
+ [IGraphIterator](src/app/types/IGraphIterator.ts) — Extends default iterator with init and getPath methods.
165
148
 
166
- [IGraphIterationStrategy](src/types/IGraphIterationStrategy.ts) — Iteration strategies which are used in shortest-path, has-path.
149
+ [IGraphIterationStrategy](src/app/types/IGraphIterationStrategy.ts) — Iteration strategies which are used in shortest-path, has-path.
167
150
 
168
151
  ### Implementation
169
- [GraphEdge](src/data-structures/Graph/GraphEdge.ts) — Contains from/to links and edge weight.
152
+ [GraphEdge](src/app/data-structures/Graph/GraphEdge.ts) — Contains from/to links and edge weight.
170
153
 
171
- [AbstractGraph](src/data-structures/Graph/AbstractGraph.ts) — Common logic for both directed and undirected graphs.
154
+ [AbstractGraph](src/app/data-structures/Graph/AbstractGraph.ts) — Common logic for both directed and undirected graphs.
172
155
 
173
156
 
174
- [DirectedGraph](src/data-structures/Graph/DirectedGraph.ts) [ [ tests ] ](test/unit/data-structures/graph/graph.test.ts)
157
+ [DirectedGraph](src/app/data-structures/Graph/DirectedGraph.ts) [ [ tests ] ](test/unit/data-structures/graph/graph.test.ts)
175
158
  — In case of directed graph A->B and B->A edges are not the same.
176
159
 
177
- [UndirectedGraph](src/data-structures/Graph/UndirectedGraph.ts) [ [ tests ] ](test/unit/data-structures/graph/graph.test.ts)
160
+ [UndirectedGraph](src/app/data-structures/Graph/UndirectedGraph.ts) [ [ tests ] ](test/unit/data-structures/graph/graph.test.ts)
178
161
  — In case of undirected graph A->B and B->A are equal.
179
162
 
180
163
 
181
164
  ### Graph Iterators
182
165
 
183
- [BreadthFirstSearchIterator](src/data-structures/Graph/iterator/GraphIteratorBFS.ts)
166
+ [BreadthFirstSearchIterator](src/app/algorithms/graph/iterator/GraphIteratorBFS.ts)
184
167
  — Traversal method for unweighted graphs, built on queue.
185
168
 
186
- [DepthFirstSearchIterator](src/data-structures/Graph/iterator/GraphIteratorDFS.ts)
169
+ [DepthFirstSearchIterator](src/app/algorithms/graph/iterator/GraphIteratorDFS.ts)
187
170
  — Traversal method for unweighted graphs, built on stack.
188
171
 
189
- [DijkstraMethodIterator](src/data-structures/Graph/iterator/GraphIteratorDijkstra.ts)
172
+ [DijkstraMethodIterator](src/app/algorithms/graph/iterator/GraphIteratorDijkstra.ts)
190
173
  — Traversal method for weighted graphs, built on finding the minimal cost.
191
174
 
192
175
 
193
176
  ### Graph Presenter
194
- [presenter-adjacency-lists](src/data-structures/Graph/presenter/presenterAdjacencyLists.ts) [[ tests ](test/unit/data-structures/graph/graph.presenter.lists.test.ts)]
177
+ [presenter-adjacency-lists](src/app/algorithms/graph/presenter/presenterAdjacencyLists.ts) [[ tests ](test/unit/data-structures/graph/graph.presenter.lists.test.ts)]
195
178
  — Representation of graph as an adjacency list (using Map).
196
179
 
197
- [presenter-adjacency-matrix](src/data-structures/Graph/presenter/presenterAdjacencyMatrix.ts) [[ tests ](test/unit/data-structures/graph/graph.presenter.matrix.test.ts)]
180
+ [presenter-adjacency-matrix](src/app/algorithms/graph/presenter/presenterAdjacencyMatrix.ts) [[ tests ](test/unit/data-structures/graph/graph.presenter.matrix.test.ts)]
198
181
  — Representation of graph as an adjacency matrix (using Array N*N).
199
182
 
200
183
 
201
184
  ### Graph Searching
202
- [has-path (BFS/DFS)](src/data-structures/Graph/searching/hasPath.ts) [[ tests ](test/unit/data-structures/graph/graph.has-path.test.ts)]
185
+ [has-path (BFS/DFS)](src/app/algorithms/graph/searching/hasPath.ts) [[ tests ](test/unit/data-structures/graph/graph.has-path.test.ts)]
203
186
  — Search for the existence of a path between two vertices.
204
187
 
205
- [shortest-path (BFS/Dijkstra)](src/data-structures/Graph/searching/shortestPath.ts) [[ tests ](test/unit/data-structures/graph/graph.shortest-path.test.ts)]
188
+ [shortest-path (BFS/Dijkstra)](src/app/algorithms/graph/searching/shortestPath.ts) [[ tests ](test/unit/data-structures/graph/graph.shortest-path.test.ts)]
206
189
  — Search for one of several shortest paths between two vertices.
207
190
 
208
191
  ### Graph Creators
209
- [create-graph-from-matrix](src/helpers/createGraphFromMatrix.ts) [[ tests ](test/unit/data-structures/graph/graph.create-from-matrix.test.ts)]
192
+ [create-graph-from-matrix](src/app/data-structures/Graph/_helpers/createGraphFromMatrix.ts) [[ tests ](test/unit/data-structures/graph/graph.create-from-matrix.test.ts)]
210
193
  — Convert a matrix N*N into a graph instance.
211
194
 
212
195
 
213
196
  ### Graph Transposing
214
- [transpose-directed-graph](src/data-structures/Graph/transposing/transposeDirectedGraph.ts) [ [ tests ](test/unit/data-structures/graph/graph.transpose.test.ts)]
197
+ [transpose-directed-graph](src/app/algorithms/graph/transposing/transposeDirectedGraph.ts) [ [ tests ](test/unit/data-structures/graph/graph.transpose.test.ts)]
215
198
  — Transpose a directed graph (undirected graphs are symmetrical already).
216
199
 
217
200
 
218
201
 
219
202
  ## Binary trees
220
- [IBinaryTree](src/types/IBinaryTree.ts) — Contains basic binary tree operations.
203
+ [IBinaryTree](src/app/types/IBinaryTree.ts) — Contains basic binary tree operations.
221
204
 
222
205
  ### Implementation
223
206
 
224
- [AbstractBinaryNode](src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.ts) — Contains left/right/parent links and node data.
207
+ [AbstractBinaryNode](src/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.ts) — Contains left/right/parent links and node data.
225
208
 
226
- [AbstractBinaryTree](src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts) — Common logic for all types of binary trees.
209
+ [AbstractBinaryTree](src/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts) — Common logic for all types of binary trees.
227
210
 
228
211
 
229
- [BinarySearchNode](src/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts) — Same as abstract binary node.
212
+ [BinarySearchNode](src/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts) — Same as abstract binary node.
230
213
 
231
- [BinarySearchTree](src/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts) — Implementation of unbalanced binary search tree.
214
+ [BinarySearchTree](src/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts) — Implementation of unbalanced binary search tree.
232
215
  Each node in left subtree is smaller and each node in right subtree is larger than the node data.
233
- Extends [AbstractSearchTree](src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts).
216
+ Extends [AbstractSearchTree](src/app/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts).
234
217
 
235
218
 
236
219
 
237
- [RandBinarySearchNode](src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.ts) — Have a rank attribute.
238
- Extends [BinarySearchNode](src/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts).
220
+ [RandBinarySearchNode](src/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.ts) — Have a rank attribute.
221
+ Extends [BinarySearchNode](src/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts).
239
222
 
240
- [RandBinarySearchTree](src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.ts)
223
+ [RandBinarySearchTree](src/app/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.ts)
241
224
  — Implementation of randomized binary search tree, which gives expected log(N) height.
242
- Insertion have a 1/N+1 probability of inserting into root.
243
- Extends [BinarySearchTree](src/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts).
225
+ INSERTION have a 1/N+1 probability of inserting into root.
226
+ Extends [BinarySearchTree](src/app/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts).
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Find element's index in sorted array
3
+ * Time complexity: O(log(n))
4
+ */
5
+ export declare const binarySearch: (elements: Array<number>, searchElement: number) => number | null;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.binarySearch = void 0;
4
+ /**
5
+ * Find element's index in sorted array
6
+ * Time complexity: O(log(n))
7
+ */
8
+ exports.binarySearch = function (elements, searchElement) {
9
+ var length = elements.length;
10
+ var leftIndex = 0;
11
+ var rightIndex = length - 1;
12
+ while (leftIndex <= rightIndex) {
13
+ var midIndex = Math.ceil((leftIndex + rightIndex) / 2);
14
+ var midEl = elements[midIndex];
15
+ if (searchElement == midEl) {
16
+ return midIndex;
17
+ }
18
+ else if (midEl > searchElement) {
19
+ rightIndex = midIndex - 1;
20
+ }
21
+ else if (midEl < searchElement) {
22
+ leftIndex = midIndex + 1;
23
+ }
24
+ }
25
+ return null;
26
+ };
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmluYXJ5LXNlYXJjaC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcHAvYWxnb3JpdGhtcy9iaW5hcnktc2VhcmNoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7R0FHRztBQUNVLFFBQUEsWUFBWSxHQUFHLFVBQzFCLFFBQXVCLEVBQ3ZCLGFBQXFCO0lBRXJCLElBQU0sTUFBTSxHQUFXLFFBQVEsQ0FBQyxNQUFNLENBQUM7SUFFdkMsSUFBSSxTQUFTLEdBQUcsQ0FBQyxDQUFDO0lBQ2xCLElBQUksVUFBVSxHQUFXLE1BQU0sR0FBRyxDQUFDLENBQUM7SUFFcEMsT0FBTyxTQUFTLElBQUksVUFBVSxFQUFFO1FBQzlCLElBQU0sUUFBUSxHQUFXLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxTQUFTLEdBQUcsVUFBVSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7UUFDakUsSUFBTSxLQUFLLEdBQVcsUUFBUSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBRXpDLElBQUksYUFBYSxJQUFJLEtBQUssRUFBRTtZQUMxQixPQUFPLFFBQVEsQ0FBQztTQUNqQjthQUFNLElBQUksS0FBSyxHQUFHLGFBQWEsRUFBRTtZQUNoQyxVQUFVLEdBQUcsUUFBUSxHQUFHLENBQUMsQ0FBQztTQUMzQjthQUFNLElBQUksS0FBSyxHQUFHLGFBQWEsRUFBRTtZQUNoQyxTQUFTLEdBQUcsUUFBUSxHQUFHLENBQUMsQ0FBQztTQUMxQjtLQUNGO0lBRUQsT0FBTyxJQUFJLENBQUM7QUFDZCxDQUFDLENBQUMifQ==
@@ -0,0 +1,9 @@
1
+ import { FnToMemoize } from "../types/FnToMemoize";
2
+ /**
3
+ * Time complexity: O(n!)
4
+ */
5
+ export declare const factorial: (x: number) => number;
6
+ /**
7
+ * Time complexity: O(n) - due to caching
8
+ */
9
+ export declare const memoizedFactorial: FnToMemoize<number, number>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoizedFactorial = exports.factorial = void 0;
4
+ var memoize_1 = require("./memoize");
5
+ /**
6
+ * Time complexity: O(n!)
7
+ */
8
+ exports.factorial = function (x) {
9
+ return x > 1 ? x * exports.factorial(x - 1) : x;
10
+ };
11
+ /**
12
+ * Time complexity: O(n) - due to caching
13
+ */
14
+ exports.memoizedFactorial = memoize_1.memoize(function (n) {
15
+ return n > 1 ? n * exports.memoizedFactorial(n - 1) : n;
16
+ });
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yaWFsLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwcC9hbGdvcml0aG1zL2ZhY3RvcmlhbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxxQ0FBb0M7QUFHcEM7O0dBRUc7QUFDVSxRQUFBLFNBQVMsR0FBRyxVQUFDLENBQVM7SUFDakMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcsaUJBQVMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUMxQyxDQUFDLENBQUM7QUFFRjs7R0FFRztBQUNVLFFBQUEsaUJBQWlCLEdBQWdDLGlCQUFPLENBQ25FLFVBQUMsQ0FBUztJQUNSLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHLHlCQUFpQixDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ2xELENBQUMsQ0FDRixDQUFDIn0=
@@ -0,0 +1,9 @@
1
+ import { FnToMemoize } from "../types/FnToMemoize";
2
+ /**
3
+ * Time complexity: O(n!)
4
+ */
5
+ export declare const fibonacci: (n: number) => number;
6
+ /**
7
+ * Time complexity: O(n) - due to caching
8
+ */
9
+ export declare const memoizedFibonacci: FnToMemoize<number, number>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoizedFibonacci = exports.fibonacci = void 0;
4
+ var memoize_1 = require("./memoize");
5
+ /**
6
+ * Time complexity: O(n!)
7
+ */
8
+ exports.fibonacci = function (n) {
9
+ return n > 1 ? exports.fibonacci(n - 1) + exports.fibonacci(n - 2) : n;
10
+ };
11
+ /**
12
+ * Time complexity: O(n) - due to caching
13
+ */
14
+ exports.memoizedFibonacci = memoize_1.memoize(function (n) {
15
+ return n > 1 ? exports.memoizedFibonacci(n - 1) + exports.memoizedFibonacci(n - 2) : n;
16
+ });
17
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlib25hY2NpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2FwcC9hbGdvcml0aG1zL2ZpYm9uYWNjaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFDQSxxQ0FBb0M7QUFFcEM7O0dBRUc7QUFDVSxRQUFBLFNBQVMsR0FBRyxVQUFDLENBQVM7SUFDakMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxpQkFBUyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsR0FBRyxpQkFBUyxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3pELENBQUMsQ0FBQztBQUVGOztHQUVHO0FBQ1UsUUFBQSxpQkFBaUIsR0FBZ0MsaUJBQU8sQ0FDbkUsVUFBQyxDQUFTO0lBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyx5QkFBaUIsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxDQUFDLEdBQUcseUJBQWlCLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7QUFDekUsQ0FBQyxDQUNGLENBQUMifQ==
@@ -0,0 +1,35 @@
1
+ import IGraphIterator from "../../../types/IGraphIterator";
2
+ import IGraph from "../../../types/IGraph";
3
+ export default abstract class AbstractGraphIterator<T> implements IGraphIterator<T> {
4
+ protected readonly graph: IGraph<T>;
5
+ protected readonly visited: Map<T, boolean>;
6
+ protected readonly parents: Map<T, T>;
7
+ /**
8
+ * Creates empty instance
9
+ */
10
+ protected constructor(graph: IGraph<T>);
11
+ protected abstract currentImpl(): T;
12
+ protected abstract nextImpl(): T;
13
+ protected abstract initIteratorImpl(from: T): void;
14
+ protected abstract hasNextImpl(): boolean;
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ initIterator(from: T): void;
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ hasNext(): boolean;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ next(): T;
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ current(): T;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ getPath(from: T, to: T): Array<T>;
35
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ var IsNotFoundException_1 = require("../../../exceptions/IsNotFoundException");
11
+ var IllegalStateException_1 = require("../../../exceptions/base/IllegalStateException");
12
+ var AbstractGraphIterator = /** @class */ (function () {
13
+ /**
14
+ * Creates empty instance
15
+ */
16
+ function AbstractGraphIterator(graph) {
17
+ this.graph = graph;
18
+ this.visited = new Map();
19
+ this.parents = new Map();
20
+ }
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ AbstractGraphIterator.prototype.initIterator = function (from) {
25
+ if (!this.graph.hasVertex(from)) {
26
+ throw new IsNotFoundException_1.default("Start vertex does not exist");
27
+ }
28
+ this.initIteratorImpl(from);
29
+ };
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ AbstractGraphIterator.prototype.hasNext = function () {
34
+ return this.hasNextImpl();
35
+ };
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ AbstractGraphIterator.prototype.next = function () {
40
+ if (!this.hasNext()) {
41
+ throw new IllegalStateException_1.default("Next element does not exist");
42
+ }
43
+ return this.nextImpl();
44
+ };
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ AbstractGraphIterator.prototype.current = function () {
49
+ try {
50
+ return this.currentImpl();
51
+ }
52
+ catch (e) {
53
+ throw new IllegalStateException_1.default("Current element does not exist");
54
+ }
55
+ };
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ AbstractGraphIterator.prototype.getPath = function (from, to) {
60
+ var path = new Array();
61
+ var isLinkedDirectly = this.graph.hasEdge(from, to);
62
+ var currentVertex = this.parents.get(to);
63
+ if (isLinkedDirectly) {
64
+ return [from, to];
65
+ }
66
+ else {
67
+ while (currentVertex) {
68
+ if (currentVertex === from) {
69
+ break;
70
+ }
71
+ path.push(currentVertex);
72
+ currentVertex = this.parents.get(currentVertex);
73
+ }
74
+ if (path.length === 0) {
75
+ throw new IllegalStateException_1.default("There is no path found");
76
+ }
77
+ return __spreadArrays([from], path.reverse(), [to]);
78
+ }
79
+ };
80
+ return AbstractGraphIterator;
81
+ }());
82
+ exports.default = AbstractGraphIterator;
83
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWJzdHJhY3RHcmFwaEl0ZXJhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vc3JjL2FwcC9hbGdvcml0aG1zL2dyYXBoL2l0ZXJhdG9yL0Fic3RyYWN0R3JhcGhJdGVyYXRv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";
3
+ /**
4
+ * Breadth first graph traversal
5
+ */
6
+ export default class GraphIteratorBFS<T> extends AbstractGraphIterator<T> {
7
+ private readonly queue;
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ constructor(graph: IGraph<T>);
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ protected currentImpl(): T;
16
+ /**
17
+ @inheritDoc
18
+ */
19
+ initIteratorImpl(startVertex: T): void;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ hasNextImpl(): boolean;
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ protected nextImpl(): T;
28
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var Queue_1 = require("../../../data-structures/Queue/Queue");
17
+ var AbstractGraphIterator_1 = require("./AbstractGraphIterator");
18
+ /**
19
+ * Breadth first graph traversal
20
+ */
21
+ var GraphIteratorBFS = /** @class */ (function (_super) {
22
+ __extends(GraphIteratorBFS, _super);
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ function GraphIteratorBFS(graph) {
27
+ var _this = _super.call(this, graph) || this;
28
+ _this.queue = new Queue_1.default();
29
+ return _this;
30
+ }
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ GraphIteratorBFS.prototype.currentImpl = function () {
35
+ return this.queue.peek();
36
+ };
37
+ /**
38
+ @inheritDoc
39
+ */
40
+ GraphIteratorBFS.prototype.initIteratorImpl = function (startVertex) {
41
+ this.queue.push(startVertex);
42
+ this.visited.set(startVertex, true);
43
+ };
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ GraphIteratorBFS.prototype.hasNextImpl = function () {
48
+ return !this.queue.isEmpty();
49
+ };
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ GraphIteratorBFS.prototype.nextImpl = function () {
54
+ var _this = this;
55
+ var next = this.queue.pop();
56
+ var nextNeighbors = this.graph.getVertexNeighbors(next);
57
+ nextNeighbors.forEach(function (neighbor) {
58
+ var isNotVisited = !_this.visited.get(neighbor);
59
+ if (isNotVisited) {
60
+ _this.queue.push(neighbor);
61
+ _this.visited.set(neighbor, true);
62
+ _this.parents.set(neighbor, next);
63
+ }
64
+ });
65
+ return next;
66
+ };
67
+ return GraphIteratorBFS;
68
+ }(AbstractGraphIterator_1.default));
69
+ exports.default = GraphIteratorBFS;
70
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJdGVyYXRvckJGUy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hcHAvYWxnb3JpdGhtcy9ncmFwaC9pdGVyYXRvci9HcmFwaEl0ZXJhdG9yQkZTLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhEQUF5RDtBQUV6RCxpRUFBNEQ7QUFFNUQ7O0dBRUc7QUFDSDtJQUFpRCxvQ0FBd0I7SUFHdkU7O09BRUc7SUFDSCwwQkFBbUIsS0FBZ0I7UUFBbkMsWUFDRSxrQkFBTSxLQUFLLENBQUMsU0FFYjtRQURDLEtBQUksQ0FBQyxLQUFLLEdBQUcsSUFBSSxlQUFLLEVBQUUsQ0FBQzs7SUFDM0IsQ0FBQztJQUVEOztPQUVHO0lBQ08sc0NBQVcsR0FBckI7UUFDRSxPQUFPLElBQUksQ0FBQyxLQUFL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