@raikuxq/alg-ds 1.1.2 → 1.1.5

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 (257) hide show
  1. package/README.md +26 -2
  2. package/lib/algorithms/binary-search.d.ts +5 -0
  3. package/lib/algorithms/binary-search.js +27 -0
  4. package/lib/algorithms/factorial.d.ts +9 -0
  5. package/lib/algorithms/factorial.js +17 -0
  6. package/lib/algorithms/fibonacci.d.ts +9 -0
  7. package/lib/algorithms/fibonacci.js +17 -0
  8. package/lib/algorithms/memoize.d.ts +5 -0
  9. package/lib/algorithms/memoize.js +22 -0
  10. package/lib/algorithms/sorts/bubble-sort.d.ts +9 -0
  11. package/lib/algorithms/sorts/bubble-sort.js +23 -0
  12. package/lib/algorithms/sorts/insertion-sort.d.ts +9 -0
  13. package/lib/algorithms/sorts/insertion-sort.js +25 -0
  14. package/lib/algorithms/sorts/merge-sort.d.ts +9 -0
  15. package/lib/algorithms/sorts/merge-sort.js +61 -0
  16. package/lib/algorithms/sorts/quick-sort.d.ts +9 -0
  17. package/lib/algorithms/sorts/quick-sort.js +45 -0
  18. package/lib/algorithms/sorts/select-sort.d.ts +9 -0
  19. package/lib/algorithms/sorts/select-sort.js +20 -0
  20. package/lib/algorithms/transpose-matrix.d.ts +5 -0
  21. package/lib/algorithms/transpose-matrix.js +20 -0
  22. package/lib/constants.d.ts +2 -0
  23. package/lib/constants.js +6 -0
  24. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +15 -0
  25. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +53 -0
  26. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +60 -0
  27. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +36 -0
  28. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +13 -0
  29. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +59 -0
  30. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +70 -0
  31. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +268 -0
  32. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +16 -0
  33. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +70 -0
  34. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +57 -0
  35. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +234 -0
  36. package/lib/data-structures/Graph/AbstractGraph.d.ts +84 -0
  37. package/lib/data-structures/Graph/AbstractGraph.js +141 -0
  38. package/lib/data-structures/Graph/DirectedGraph.d.ts +24 -0
  39. package/lib/data-structures/Graph/DirectedGraph.js +85 -0
  40. package/lib/data-structures/Graph/GraphEdge.d.ts +16 -0
  41. package/lib/data-structures/Graph/GraphEdge.js +43 -0
  42. package/lib/data-structures/Graph/UndirectedGraph.d.ts +28 -0
  43. package/lib/data-structures/Graph/UndirectedGraph.js +102 -0
  44. package/lib/data-structures/Graph/demo/generateRandomGraph.d.ts +4 -0
  45. package/lib/data-structures/Graph/demo/generateRandomGraph.js +72 -0
  46. package/lib/data-structures/Graph/iterator/AbstractGraphIterator.d.ts +35 -0
  47. package/lib/data-structures/Graph/iterator/AbstractGraphIterator.js +90 -0
  48. package/lib/data-structures/Graph/iterator/GraphIteratorBFS.d.ts +28 -0
  49. package/lib/data-structures/Graph/iterator/GraphIteratorBFS.js +70 -0
  50. package/lib/data-structures/Graph/iterator/GraphIteratorDFS.d.ts +28 -0
  51. package/lib/data-structures/Graph/iterator/GraphIteratorDFS.js +70 -0
  52. package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.d.ts +32 -0
  53. package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.js +99 -0
  54. package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.d.ts +19 -0
  55. package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.js +28 -0
  56. package/{src/data-structures/Graph/presenter/presenterAdjacencyMatrix.ts → lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.d.ts} +32 -51
  57. package/lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.js +48 -0
  58. package/lib/data-structures/Graph/searching/hasPath.d.ts +9 -0
  59. package/lib/data-structures/Graph/searching/hasPath.js +29 -0
  60. package/lib/data-structures/Graph/searching/shortestPath.d.ts +9 -0
  61. package/lib/data-structures/Graph/searching/shortestPath.js +29 -0
  62. package/lib/data-structures/Graph/strategy/BFSIterationStrategy.d.ts +6 -0
  63. package/lib/data-structures/Graph/strategy/BFSIterationStrategy.js +13 -0
  64. package/lib/data-structures/Graph/strategy/DFSIterationStrategy.d.ts +6 -0
  65. package/lib/data-structures/Graph/strategy/DFSIterationStrategy.js +13 -0
  66. package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.d.ts +6 -0
  67. package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.js +13 -0
  68. package/lib/data-structures/Graph/transposing/transposeDirectedGraph.d.ts +2 -0
  69. package/lib/data-structures/Graph/transposing/transposeDirectedGraph.js +14 -0
  70. package/lib/data-structures/HashTable/HashTable.d.ts +73 -0
  71. package/lib/data-structures/HashTable/HashTable.js +169 -0
  72. package/lib/data-structures/HashTable/HashTableNode.d.ts +11 -0
  73. package/lib/data-structures/HashTable/HashTableNode.js +39 -0
  74. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +125 -0
  75. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +236 -0
  76. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +20 -0
  77. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +41 -0
  78. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +48 -0
  79. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +150 -0
  80. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +25 -0
  81. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +65 -0
  82. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +52 -0
  83. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +137 -0
  84. package/{src/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.ts → lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts} +7 -10
  85. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +29 -0
  86. package/lib/data-structures/LoopedArray/LoopedArray.d.ts +86 -0
  87. package/lib/data-structures/LoopedArray/LoopedArray.js +161 -0
  88. package/lib/data-structures/Queue/Queue.d.ts +50 -0
  89. package/lib/data-structures/Queue/Queue.js +83 -0
  90. package/lib/data-structures/Stack/Stack.d.ts +50 -0
  91. package/lib/data-structures/Stack/Stack.js +83 -0
  92. package/lib/exports/algorithms.d.ts +16 -0
  93. package/lib/exports/algorithms.js +36 -0
  94. package/lib/exports/constants.d.ts +2 -0
  95. package/lib/exports/constants.js +7 -0
  96. package/lib/exports/data-structures.d.ts +11 -0
  97. package/lib/exports/data-structures.js +24 -0
  98. package/lib/exports/helpers.d.ts +6 -0
  99. package/lib/exports/helpers.js +14 -0
  100. package/lib/exports/sorts.d.ts +6 -0
  101. package/lib/exports/sorts.js +14 -0
  102. package/lib/exports/utils.d.ts +3 -0
  103. package/lib/exports/utils.js +14 -0
  104. package/lib/exports.d.ts +44 -0
  105. package/lib/exports.js +89 -0
  106. package/lib/helpers/createBinaryTree.d.ts +6 -0
  107. package/lib/helpers/createBinaryTree.js +22 -0
  108. package/lib/helpers/createGraph.d.ts +6 -0
  109. package/lib/helpers/createGraph.js +24 -0
  110. package/lib/helpers/createGraphFromMatrix.d.ts +7 -0
  111. package/lib/helpers/createGraphFromMatrix.js +37 -0
  112. package/lib/helpers/createLinkedList.d.ts +3 -0
  113. package/lib/helpers/createLinkedList.js +21 -0
  114. package/lib/index.d.ts +3 -0
  115. package/lib/index.js +6 -0
  116. package/lib/types/ArrayMatrix.d.ts +1 -0
  117. package/lib/types/ArrayMatrix.js +3 -0
  118. package/lib/types/EnumBinarySearchTreeType.d.ts +4 -0
  119. package/lib/types/EnumBinarySearchTreeType.js +9 -0
  120. package/lib/types/EnumGraphType.d.ts +4 -0
  121. package/lib/types/EnumGraphType.js +9 -0
  122. package/lib/types/EnumLinkedListType.d.ts +4 -0
  123. package/lib/types/EnumLinkedListType.js +9 -0
  124. package/lib/types/EnumRandomGenerationFormat.d.ts +4 -0
  125. package/lib/types/EnumRandomGenerationFormat.js +9 -0
  126. package/lib/types/EnumTreeTraversalType.d.ts +5 -0
  127. package/lib/types/EnumTreeTraversalType.js +10 -0
  128. package/lib/types/FnCompareTwo.d.ts +1 -0
  129. package/lib/types/FnCompareTwo.js +3 -0
  130. package/lib/types/FnToMemoize.d.ts +1 -0
  131. package/lib/types/FnToMemoize.js +3 -0
  132. package/{src/types/ILinkedList.ts → lib/types/IArrayFacade.d.ts} +4 -6
  133. package/lib/types/IArrayFacade.js +3 -0
  134. package/{src/types/IBiDirectIterable.ts → lib/types/IBiDirectIterable.d.ts} +5 -6
  135. package/lib/types/IBiDirectIterable.js +3 -0
  136. package/lib/types/IBiDirectIterator.d.ts +11 -0
  137. package/lib/types/IBiDirectIterator.js +3 -0
  138. package/lib/types/IBinaryTree.d.ts +12 -0
  139. package/lib/types/IBinaryTree.js +3 -0
  140. package/lib/types/IConvertableToArray.d.ts +4 -0
  141. package/lib/types/IConvertableToArray.js +3 -0
  142. package/lib/types/IGraph.d.ts +14 -0
  143. package/lib/types/IGraph.js +3 -0
  144. package/{src/types/IGraphIterationStrategy.ts → lib/types/IGraphIterationStrategy.d.ts} +5 -6
  145. package/lib/types/IGraphIterationStrategy.js +3 -0
  146. package/lib/types/IGraphIterator.d.ts +11 -0
  147. package/lib/types/IGraphIterator.js +3 -0
  148. package/{src/types/IIterable.ts → lib/types/IIterable.d.ts} +4 -5
  149. package/lib/types/IIterable.js +3 -0
  150. package/lib/types/IIterator.d.ts +14 -0
  151. package/lib/types/IIterator.js +3 -0
  152. package/lib/types/IKeyValueStorage.d.ts +8 -0
  153. package/lib/types/IKeyValueStorage.js +3 -0
  154. package/lib/types/ILinearStorage.d.ts +11 -0
  155. package/lib/types/ILinearStorage.js +3 -0
  156. package/{src/types/ILinearStorageRA.ts → lib/types/ILinearStorageRA.d.ts} +13 -14
  157. package/lib/types/ILinearStorageRA.js +3 -0
  158. package/{src/types/IArrayFacade.ts → lib/types/ILinkedList.d.ts} +4 -6
  159. package/lib/types/ILinkedList.js +3 -0
  160. package/lib/utils.d.ts +29 -0
  161. package/lib/utils.js +95 -0
  162. package/package.json +9 -3
  163. package/.idea/algorythmes.iml +0 -15
  164. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  165. package/.idea/deployment.xml +0 -14
  166. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  167. package/.idea/jsLinters/eslint.xml +0 -6
  168. package/.idea/misc.xml +0 -6
  169. package/.idea/modules.xml +0 -8
  170. package/.idea/vcs.xml +0 -6
  171. package/lib/algotirhms.ts +0 -35
  172. package/lib/constants.ts +0 -3
  173. package/lib/data-structures.ts +0 -23
  174. package/lib/helpers.ts +0 -13
  175. package/lib/sorts.ts +0 -7
  176. package/lib/types.ts +0 -53
  177. package/lib/utils.ts +0 -21
  178. package/src/algorithms/binary-search.ts +0 -28
  179. package/src/algorithms/factorial.ts +0 -18
  180. package/src/algorithms/fibonacci.ts +0 -18
  181. package/src/algorithms/memoize.ts +0 -21
  182. package/src/algorithms/sorts/bubble-sort.ts +0 -21
  183. package/src/algorithms/sorts/insertion-sort.ts +0 -25
  184. package/src/algorithms/sorts/merge-sort.ts +0 -74
  185. package/src/algorithms/sorts/quick-sort.ts +0 -54
  186. package/src/algorithms/sorts/select-sort.ts +0 -19
  187. package/src/algorithms/transpose-matrix.ts +0 -19
  188. package/src/constants.ts +0 -2
  189. package/src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.ts +0 -45
  190. package/src/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.ts +0 -80
  191. package/src/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.ts +0 -38
  192. package/src/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.ts +0 -286
  193. package/src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.ts +0 -48
  194. package/src/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.ts +0 -228
  195. package/src/data-structures/Graph/AbstractGraph.ts +0 -189
  196. package/src/data-structures/Graph/DirectedGraph.ts +0 -84
  197. package/src/data-structures/Graph/GraphEdge.ts +0 -33
  198. package/src/data-structures/Graph/UndirectedGraph.ts +0 -108
  199. package/src/data-structures/Graph/demo/generateRandomGraph.ts +0 -93
  200. package/src/data-structures/Graph/iterator/AbstractGraphIterator.ts +0 -99
  201. package/src/data-structures/Graph/iterator/GraphIteratorBFS.ts +0 -60
  202. package/src/data-structures/Graph/iterator/GraphIteratorDFS.ts +0 -60
  203. package/src/data-structures/Graph/iterator/GraphIteratorDijkstra.ts +0 -94
  204. package/src/data-structures/Graph/presenter/presenterAdjacencyLists.ts +0 -29
  205. package/src/data-structures/Graph/searching/hasPath.ts +0 -38
  206. package/src/data-structures/Graph/searching/shortestPath.ts +0 -38
  207. package/src/data-structures/Graph/strategy/BFSIterationStrategy.ts +0 -11
  208. package/src/data-structures/Graph/strategy/DFSIterationStrategy.ts +0 -11
  209. package/src/data-structures/Graph/strategy/DijkstraIterationStrategy.ts +0 -11
  210. package/src/data-structures/Graph/transposing/transposeDirectedGraph.ts +0 -19
  211. package/src/data-structures/HashTable/HashTable.ts +0 -202
  212. package/src/data-structures/HashTable/HashTableNode.ts +0 -31
  213. package/src/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.ts +0 -310
  214. package/src/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.ts +0 -33
  215. package/src/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.ts +0 -156
  216. package/src/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.ts +0 -47
  217. package/src/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.ts +0 -147
  218. package/src/data-structures/LoopedArray/LoopedArray.ts +0 -182
  219. package/src/data-structures/Queue/Queue.ts +0 -92
  220. package/src/data-structures/Stack/Stack.ts +0 -92
  221. package/src/demo/demo.bst.ts +0 -67
  222. package/src/demo/demo.graph.ts +0 -246
  223. package/src/demo/demo.hashtable.ts +0 -28
  224. package/src/demo/demo.linked-list.ts +0 -78
  225. package/src/demo/demo.looped-array.ts +0 -104
  226. package/src/demo/demo.queue.ts +0 -40
  227. package/src/demo/demo.stack.ts +0 -40
  228. package/src/demo/performance/bst-compare.ts +0 -35
  229. package/src/demo/performance/ds-compare.ts +0 -58
  230. package/src/demo/performance/hash-table.compare.ts +0 -40
  231. package/src/demo/performance/sort-compare.ts +0 -60
  232. package/src/helpers/createBinaryTree.ts +0 -24
  233. package/src/helpers/createGraph.ts +0 -24
  234. package/src/helpers/createGraphFromMatrix.ts +0 -47
  235. package/src/helpers/createLinkedList.ts +0 -24
  236. package/src/index.ts +0 -44
  237. package/src/types/ArrayMatrix.ts +0 -1
  238. package/src/types/EnumBinarySearchTreeType.ts +0 -4
  239. package/src/types/EnumGraphTraversalType.ts +0 -5
  240. package/src/types/EnumGraphType.ts +0 -4
  241. package/src/types/EnumLinkedListType.ts +0 -4
  242. package/src/types/EnumRandomGenerationFormat.ts +0 -4
  243. package/src/types/EnumSortType.ts +0 -7
  244. package/src/types/EnumTreeTraversalType.ts +0 -5
  245. package/src/types/FnCompareTwo.ts +0 -1
  246. package/src/types/FnSort.ts +0 -1
  247. package/src/types/FnToMemoize.ts +0 -1
  248. package/src/types/IBiDirectIterator.ts +0 -12
  249. package/src/types/IBinaryTree.ts +0 -13
  250. package/src/types/IConvertableToArray.ts +0 -4
  251. package/src/types/IGraph.ts +0 -16
  252. package/src/types/IGraphCreator.ts +0 -5
  253. package/src/types/IGraphIterator.ts +0 -13
  254. package/src/types/IIterator.ts +0 -14
  255. package/src/types/IKeyValueStorage.ts +0 -8
  256. package/src/types/ILinearStorage.ts +0 -11
  257. package/src/utils.ts +0 -65
@@ -0,0 +1,59 @@
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 AbstractBinaryNode_1 = require("../AbstractBinaryTree/AbstractBinaryNode");
17
+ var BinarySearchNode = /** @class */ (function (_super) {
18
+ __extends(BinarySearchNode, _super);
19
+ function BinarySearchNode(initialData) {
20
+ var _this = _super.call(this, initialData) || this;
21
+ _this._left = null;
22
+ _this._right = null;
23
+ _this._parent = null;
24
+ return _this;
25
+ }
26
+ Object.defineProperty(BinarySearchNode.prototype, "left", {
27
+ get: function () {
28
+ return this._left;
29
+ },
30
+ set: function (value) {
31
+ this._left = value;
32
+ },
33
+ enumerable: false,
34
+ configurable: true
35
+ });
36
+ Object.defineProperty(BinarySearchNode.prototype, "right", {
37
+ get: function () {
38
+ return this._right;
39
+ },
40
+ set: function (value) {
41
+ this._right = value;
42
+ },
43
+ enumerable: false,
44
+ configurable: true
45
+ });
46
+ Object.defineProperty(BinarySearchNode.prototype, "parent", {
47
+ get: function () {
48
+ return this._parent;
49
+ },
50
+ set: function (value) {
51
+ this._parent = value;
52
+ },
53
+ enumerable: false,
54
+ configurable: true
55
+ });
56
+ return BinarySearchNode;
57
+ }(AbstractBinaryNode_1.default));
58
+ exports.default = BinarySearchNode;
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmluYXJ5U2VhcmNoTm9kZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9kYXRhLXN0cnVjdHVyZXMvQmluYXJ5VHJlZS9CaW5hcnlTZWFyY2hUcmVlL0JpbmFyeVNlYXJjaE5vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsK0VBQTBFO0FBRTFFO0lBQWlELG9DQUFxQjtJQUtwRSwwQkFBbUIsV0FBYztRQUFqQyxZQUNFLGtCQUFNLFdBQVcsQ0FBQyxTQUluQjtRQUhDLEtBQUksQ0FBQyxLQUFLLEdBQUcsSUFBSSxDQUFDO1FBQ2xCLEtBQUksQ0FBQyxNQUFNLEdBQUcsSUFBSSxDQUFDO1FBQ25CLEtBQUksQ0FBQyxPQUFPLEdBQUcsSUFBSSxDQUFDOztJQUN0QixDQUFDO0lBRUQsc0JBQVcsa0NBQUk7YUFBZjtZQUNFLE9BQU8sSUFBSSxDQUFDLEtBQUssQ0FBQztRQUNwQixDQUFDO2FBRUQsVUFBZ0IsS0FBaUM7WUFDL0MsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDckIsQ0FBQzs7O09BSkE7SUFNRCxzQkFBVyxtQ0FBSzthQUFoQjtZQUNFLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQztRQUNyQixDQUFDO2FBRUQsVUFBaUIsS0FBaUM7WUFDaEQsSUFBSSxDQUFDLE1BQU0sR0FBRyxLQUFLLENBQUM7UUFDdEIsQ0FBQzs7O09BSkE7SUFNRCxzQkFBVyxvQ0FBTTthQUFqQjtZQUNFLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQztRQUN0QixDQUFDO2FBRUQsVUFBa0IsS0FBaUM7WUFDakQsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFDdkIsQ0FBQzs7O09BSkE7SUFLSCx1QkFBQztBQUFELENBQUMsQUFuQ0QsQ0FBaUQsNEJBQWtCLEdBbUNsRSJ9
@@ -0,0 +1,70 @@
1
+ import { FnCompareTwo } from "../../../types/FnCompareTwo";
2
+ import { EnumTreeTraversalType } from "../../../types/EnumTreeTraversalType";
3
+ import IBinaryTree from "../../../types/IBinaryTree";
4
+ import AbstractBinaryTree from "../AbstractBinaryTree/AbstractBinaryTree";
5
+ import BinarySearchNode from "./BinarySearchNode";
6
+ /**
7
+ * Unbalanced binary search tree implementation
8
+ */
9
+ export default class BinarySearchTree<T> extends AbstractBinaryTree<T> {
10
+ /**
11
+ * Override types
12
+ */
13
+ protected _head: BinarySearchNode<T> | null;
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ constructor(fnCompare?: FnCompareTwo<T>);
18
+ /**
19
+ *
20
+ * @throws when head is empty
21
+ */
22
+ protected checkIsEmpty(): void;
23
+ /**
24
+ * Will update left and right links parent with current node
25
+ */
26
+ protected updateLeftRightParents(node: BinarySearchNode<T>): void;
27
+ /**
28
+ * Will return node instance by its data
29
+ */
30
+ protected findNode(value: T): BinarySearchNode<T> | null;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ protected insertToLeaf(createdNode: BinarySearchNode<T>): void;
35
+ /**
36
+ * Will join two trees into one */
37
+ protected join(treeLeft: BinarySearchNode<T> | null, treeRight: BinarySearchNode<T> | null): BinarySearchNode<T> | null;
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ max(): T;
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ min(): T;
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ insert(value: T): void;
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ has(value: T): boolean;
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ delete(value: T): void;
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ subtree(value: T): IBinaryTree<T>;
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ traverse(type: EnumTreeTraversalType, from?: T): Array<T>;
66
+ /**
67
+ * Calc max height of the largest branch of the tree
68
+ */
69
+ height(): number;
70
+ }
@@ -0,0 +1,268 @@
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 EnumTreeTraversalType_1 = require("../../../types/EnumTreeTraversalType");
17
+ var AbstractBinaryTree_1 = require("../AbstractBinaryTree/AbstractBinaryTree");
18
+ var BinarySearchNode_1 = require("./BinarySearchNode");
19
+ var Queue_1 = require("../../Queue/Queue");
20
+ /**
21
+ * Unbalanced binary search tree implementation
22
+ */
23
+ var BinarySearchTree = /** @class */ (function (_super) {
24
+ __extends(BinarySearchTree, _super);
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ function BinarySearchTree(fnCompare) {
29
+ var _this = _super.call(this, fnCompare) || this;
30
+ _this._head = null;
31
+ return _this;
32
+ }
33
+ /**
34
+ *
35
+ * @throws when head is empty
36
+ */
37
+ BinarySearchTree.prototype.checkIsEmpty = function () {
38
+ if (this._head === null) {
39
+ throw new Error("Tree is empty");
40
+ }
41
+ };
42
+ /**
43
+ * Will update left and right links parent with current node
44
+ */
45
+ BinarySearchTree.prototype.updateLeftRightParents = function (node) {
46
+ if (node.left && node.left.parent !== node) {
47
+ node.left.parent = node;
48
+ }
49
+ if (node.right && node.right.parent !== node) {
50
+ node.right.parent = node;
51
+ }
52
+ };
53
+ /**
54
+ * Will return node instance by its data
55
+ */
56
+ BinarySearchTree.prototype.findNode = function (value) {
57
+ var current = this._head;
58
+ while (current && current.data !== value) {
59
+ current = this.compare(current.data, value)
60
+ ? current.left
61
+ : current.right;
62
+ }
63
+ return current;
64
+ };
65
+ /**
66
+ * @inheritDoc
67
+ */
68
+ BinarySearchTree.prototype.insertToLeaf = function (createdNode) {
69
+ var parent = null;
70
+ var current = this._head;
71
+ while (current) {
72
+ parent = current;
73
+ current = this.compare(current.data, createdNode.data)
74
+ ? current.left
75
+ : current.right;
76
+ }
77
+ createdNode.parent = parent;
78
+ if (parent === null) {
79
+ this._head = createdNode;
80
+ }
81
+ else {
82
+ if (this.compare(parent.data, createdNode.data)) {
83
+ parent.left = createdNode;
84
+ }
85
+ else {
86
+ parent.right = createdNode;
87
+ }
88
+ }
89
+ this._length++;
90
+ };
91
+ /**
92
+ * Will join two trees into one */
93
+ BinarySearchTree.prototype.join = function (treeLeft, treeRight) {
94
+ if (treeLeft === null) {
95
+ return treeRight;
96
+ }
97
+ if (treeRight === null) {
98
+ return treeLeft;
99
+ }
100
+ treeRight.left = this.join(treeLeft, treeRight.left);
101
+ if (treeRight.left) {
102
+ this.updateLeftRightParents(treeRight);
103
+ }
104
+ return treeRight;
105
+ };
106
+ /**
107
+ * @inheritDoc
108
+ */
109
+ BinarySearchTree.prototype.max = function () {
110
+ this.checkIsEmpty();
111
+ var currentNode = this._head;
112
+ while (currentNode === null || currentNode === void 0 ? void 0 : currentNode.right) {
113
+ currentNode = currentNode.right;
114
+ }
115
+ return currentNode.data;
116
+ };
117
+ /**
118
+ * @inheritDoc
119
+ */
120
+ BinarySearchTree.prototype.min = function () {
121
+ this.checkIsEmpty();
122
+ var currentNode = this._head;
123
+ while (currentNode === null || currentNode === void 0 ? void 0 : currentNode.left) {
124
+ currentNode = currentNode.left;
125
+ }
126
+ return currentNode.data;
127
+ };
128
+ /**
129
+ * @inheritDoc
130
+ */
131
+ BinarySearchTree.prototype.insert = function (value) {
132
+ if (this.has(value)) {
133
+ throw new Error("Node already exists");
134
+ }
135
+ var createdNode = new BinarySearchNode_1.default(value);
136
+ this.insertToLeaf(createdNode);
137
+ };
138
+ /**
139
+ * @inheritDoc
140
+ */
141
+ BinarySearchTree.prototype.has = function (value) {
142
+ var current = this.findNode(value);
143
+ return (current === null || current === void 0 ? void 0 : current.data) === value;
144
+ };
145
+ /**
146
+ * @inheritDoc
147
+ */
148
+ BinarySearchTree.prototype.delete = function (value) {
149
+ var _this = this;
150
+ if (!this.has(value)) {
151
+ throw new Error("Value does not exist in the tree");
152
+ }
153
+ var recursiveDelete = function (node, value) {
154
+ if (node === null) {
155
+ return node;
156
+ }
157
+ if (node.data === value) {
158
+ var updatedNode = _this.join(node.left, node.right);
159
+ if (updatedNode) {
160
+ updatedNode.parent = node.parent;
161
+ }
162
+ return updatedNode;
163
+ }
164
+ else if (_this.compare(node.data, value)) {
165
+ node.left = recursiveDelete(node.left, value);
166
+ }
167
+ else {
168
+ node.right = recursiveDelete(node.right, value);
169
+ }
170
+ _this.updateLeftRightParents(node);
171
+ return node;
172
+ };
173
+ this._head = recursiveDelete(this._head, value);
174
+ this._length--;
175
+ };
176
+ /**
177
+ * @inheritDoc
178
+ */
179
+ BinarySearchTree.prototype.subtree = function (value) {
180
+ var tree = new BinarySearchTree();
181
+ var node = this.findNode(value);
182
+ var queue = new Queue_1.default();
183
+ var traverse = [];
184
+ queue.push(node);
185
+ while (!queue.isEmpty()) {
186
+ var currentNode = queue.pop();
187
+ traverse.push(currentNode);
188
+ if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.left) {
189
+ queue.push(currentNode.left);
190
+ }
191
+ if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.right) {
192
+ queue.push(currentNode.right);
193
+ }
194
+ }
195
+ traverse.forEach(function (elem) {
196
+ if (elem !== null) {
197
+ tree.insert(elem.data);
198
+ }
199
+ });
200
+ return tree;
201
+ };
202
+ /**
203
+ * @inheritDoc
204
+ */
205
+ BinarySearchTree.prototype.traverse = function (type, from) {
206
+ this.checkIsEmpty();
207
+ var array = new Array(this.length());
208
+ var root = from !== undefined ? this.findNode(from) : this._head;
209
+ var storeInOrder = function (node) {
210
+ if (node === null) {
211
+ return;
212
+ }
213
+ storeInOrder(node.left);
214
+ array.push(node.data);
215
+ storeInOrder(node.right);
216
+ };
217
+ var storePostOrder = function (node) {
218
+ if (node === null) {
219
+ return;
220
+ }
221
+ storeInOrder(node.left);
222
+ storeInOrder(node.right);
223
+ array.push(node.data);
224
+ };
225
+ var storePreOrder = function (node) {
226
+ if (node === null) {
227
+ return;
228
+ }
229
+ array.push(node.data);
230
+ storeInOrder(node.left);
231
+ storeInOrder(node.right);
232
+ };
233
+ switch (type) {
234
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.InOrder:
235
+ storeInOrder(root);
236
+ break;
237
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.PostOrder:
238
+ storePostOrder(root);
239
+ break;
240
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.PreOrder:
241
+ storePreOrder(root);
242
+ break;
243
+ }
244
+ return array.filter(function (item) { return item !== undefined; });
245
+ };
246
+ /**
247
+ * Calc max height of the largest branch of the tree
248
+ */
249
+ BinarySearchTree.prototype.height = function () {
250
+ var calcHeight = function (node) {
251
+ if (node === null)
252
+ return 0;
253
+ var left = node.left === null ? -1 : calcHeight(node.left);
254
+ var right = node.right === null ? -1 : calcHeight(node.right);
255
+ var max = left > right ? left : right;
256
+ return max + 1;
257
+ };
258
+ if (this._head === null) {
259
+ return 0;
260
+ }
261
+ else {
262
+ return calcHeight(this._head) + 1;
263
+ }
264
+ };
265
+ return BinarySearchTree;
266
+ }(AbstractBinaryTree_1.default));
267
+ exports.default = BinarySearchTree;
268
+ //# sourceMapp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QUFHLEtBQUssQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUM7WUFDeEMsT0FBTyxHQUFHLEdBQUcsQ0FBQyxDQUFDO1FBQ2pCLENBQUMsQ0FBQztRQUVGLElBQUksSUFBSSxDQUFDLEtBQUssS0FBSyxJQUFJLEVBQUU7WUFDdkIsT0FBTyxDQUFDLENBQUM7U0FDVjthQUFNO1lBQ0wsT0FBTyxVQUFVLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxHQUFHLENBQUMsQ0FBQztTQUNuQztJQUNILENBQUM7SUFDSCx1QkFBQztBQUFELENBQUMsQUFuUkQsQ0FBaUQsNEJBQWtCLEdBbVJsRSJ9
@@ -0,0 +1,16 @@
1
+ import BinarySearchNode from "../BinarySearchTree/BinarySearchNode";
2
+ export default class RandBinarySearchNode<T> extends BinarySearchNode<T> {
3
+ private _rank;
4
+ protected _left: RandBinarySearchNode<T> | null;
5
+ protected _right: RandBinarySearchNode<T> | null;
6
+ protected _parent: RandBinarySearchNode<T> | null;
7
+ constructor(initialData: T);
8
+ get rank(): number;
9
+ set rank(value: number);
10
+ get left(): RandBinarySearchNode<T> | null;
11
+ set left(value: RandBinarySearchNode<T> | null);
12
+ get right(): RandBinarySearchNode<T> | null;
13
+ set right(value: RandBinarySearchNode<T> | null);
14
+ get parent(): RandBinarySearchNode<T> | null;
15
+ set parent(value: RandBinarySearchNode<T> | null);
16
+ }
@@ -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 BinarySearchNode_1 = require("../BinarySearchTree/BinarySearchNode");
17
+ var RandBinarySearchNode = /** @class */ (function (_super) {
18
+ __extends(RandBinarySearchNode, _super);
19
+ function RandBinarySearchNode(initialData) {
20
+ var _this = _super.call(this, initialData) || this;
21
+ _this._rank = 0;
22
+ _this._left = null;
23
+ _this._right = null;
24
+ _this._parent = null;
25
+ return _this;
26
+ }
27
+ Object.defineProperty(RandBinarySearchNode.prototype, "rank", {
28
+ get: function () {
29
+ return this._rank;
30
+ },
31
+ set: function (value) {
32
+ this._rank = value;
33
+ },
34
+ enumerable: false,
35
+ configurable: true
36
+ });
37
+ Object.defineProperty(RandBinarySearchNode.prototype, "left", {
38
+ get: function () {
39
+ return this._left;
40
+ },
41
+ set: function (value) {
42
+ this._left = value;
43
+ },
44
+ enumerable: false,
45
+ configurable: true
46
+ });
47
+ Object.defineProperty(RandBinarySearchNode.prototype, "right", {
48
+ get: function () {
49
+ return this._right;
50
+ },
51
+ set: function (value) {
52
+ this._right = value;
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ Object.defineProperty(RandBinarySearchNode.prototype, "parent", {
58
+ get: function () {
59
+ return this._parent;
60
+ },
61
+ set: function (value) {
62
+ this._parent = value;
63
+ },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
67
+ return RandBinarySearchNode;
68
+ }(BinarySearchNode_1.default));
69
+ exports.default = RandBinarySearchNode;
70
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmFuZEJpbmFyeVNlYXJjaE5vZGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvZGF0YS1zdHJ1Y3R1cmVzL0JpbmFyeVRyZWUvUmFuZEJpbmFyeVNlYXJjaFRyZWUvUmFuZEJpbmFyeVNlY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BSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFDdkIsQ0FBQzs7O09BSkE7SUFLSCwyQkFBQztBQUFELENBQUMsQUE3Q0QsQ0FBcUQsMEJBQWdCLEdBNkNwRSJ9
@@ -0,0 +1,57 @@
1
+ import { FnCompareTwo } from "../../../types/FnCompareTwo";
2
+ import RandBinarySearchNode from "./RandBinarySearchNode";
3
+ import BinarySearchTree from "../BinarySearchTree/BinarySearchTree";
4
+ /**
5
+ * Randomized binary search tree implementation
6
+ */
7
+ export default class RandBinarySearchTree<T> extends BinarySearchTree<T> {
8
+ /**
9
+ * Override types
10
+ */
11
+ protected _head: RandBinarySearchNode<T> | null;
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ constructor(fnCompare?: FnCompareTwo<T>);
16
+ /**
17
+ * Will update node rank by summing left and right subtrees tanks and itself rank (1)
18
+ */
19
+ private updateRank;
20
+ /**
21
+ * Will set rank and parent attributes and update tree length
22
+ */
23
+ private addCreatedNode;
24
+ /**
25
+ * Will rotate node to the right side
26
+ */
27
+ private rotateNodeRight;
28
+ /**
29
+ * Will rotate node to the left side
30
+ */
31
+ private rotateNodeLeft;
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ protected join(treeLeft: RandBinarySearchNode<T> | null, treeRight: RandBinarySearchNode<T> | null): RandBinarySearchNode<T> | null;
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ protected updateLeftRightParents(node: RandBinarySearchNode<T>): void;
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ protected insertToRoot(createdNode: RandBinarySearchNode<T>, fromNode?: RandBinarySearchNode<T>): void;
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ protected insertRandomly(createdNode: RandBinarySearchNode<T>): void;
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ insert(value: T): void;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ delete(value: T): void;
56
+ length(): number;
57
+ }