@raikuxq/alg-ds 1.2.4 → 2.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 +0 -25
  2. package/lib/index.d.ts +1216 -3
  3. package/lib/index.mjs +1 -0
  4. package/package.json +78 -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 -37
  172. package/lib/app/utils.js +0 -115
  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 -14
  187. package/lib/exports.d.ts +0 -55
  188. package/lib/exports.js +0 -109
  189. package/lib/index.js +0 -5
package/lib/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const t=t=>{const e=/* @__PURE__ */new Map;return(...s)=>{const r=JSON.stringify(s);if(!e.has(r)){const i=t(...s);e.set(r,i)}return e.get(r)}},e=t=>t>1?t*e(t-1):t,s=t(t=>t>1?t*s(t-1):t),r=t=>t>1?r(t-1)+r(t-2):t,i=t(t=>t>1?i(t-1)+i(t-2):t),n=(t,e)=>{let s=0,r=t.length-1;for(;s<=r;){const i=Math.ceil((s+r)/2),n=t[i];if(e==n)return i;n>e?r=i-1:n<e&&(s=i+1)}return null};class h extends Error{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,h.prototype)}}const a=t=>t.reduce((e,s,r)=>s<t[e]?r:e,0),o=(t,e)=>e+a(t.slice(e)),l=(t,e,s)=>{if(e!==s){const r=t[e];t[e]=t[s],t[s]=r}},d=(t,e)=>Math.floor(Math.random()*(e-t))+t,u=(t,e=3)=>Math.round(t*10**e)/10**e,c=t=>{for(let e=0;e<t.length;e++){if(!(t[e].length===t.length))return!1}return!0},p=t=>{if(!c(t))throw new h("Given array is not a matrix");return t.reduce((e,s,r)=>(e[r]=t.map(t=>t[r]),e),new Array(t.length))};var g=/* @__PURE__ */(t=>(t.DIRECTED="DIRECTED",t.UNDIRECTED="UNDIRECTED",t))(g||{});class _ extends Error{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,_.prototype)}}class f extends _{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,f.prototype)}}class x extends _{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,x.prototype)}}class w{_vertices;_edges;constructor(){this._vertices=/* @__PURE__ */new Map,this._edges=new Array}getVerticesArrayFormat(){return Array.from(this._vertices.keys())}tryFindVertex(t){if(!this._vertices.has(t))throw new f("Vertex not found");return t}updateEdgeWeight(t,e,s){this.getEdgeByValue(t,e).weight=s}cascadeRemoveVertexRelations(t){this.getVerticesArrayFormat().forEach(e=>{const s=this._vertices.get(e);if(s){const r=s.filter(e=>e!==t);this._vertices.set(e,r)}})}cascadeRemoveVertexEdges(t){this._edges=this._edges.filter(e=>!(e.toVertex===t||e.fromVertex===t))}weight(){return this._edges.reduce((t,e)=>t+e.weight,0)}vertices(){return this.getVerticesArrayFormat().map(t=>t)}verticesCount(){return this.vertices().length}edgesCount(){return this._edges.length}addVertex(t){if(this.hasVertex(t))throw new x("Vertex is already exist");return this._vertices.set(t,new Array),this}removeVertex(t){try{const e=this.tryFindVertex(t);this.cascadeRemoveVertexEdges(e),this.cascadeRemoveVertexRelations(e),this._vertices.delete(e)}catch(e){throw new f("Vertex does not exist already")}return this}getVertexNeighbors(t){const e=this.tryFindVertex(t);return this._vertices.get(e)||[]}hasVertex(t){return this._vertices.has(t)}hasEdge(t,e){return Boolean(this._edges.find(s=>s.fromVertex===t&&s.toVertex===e))}getEdgeWeight(t,e){const s=this.tryFindVertex(t),r=this.tryFindVertex(e);return this.getEdgeByValue(s,r).weight}}class m{_fromVertex;_toVertex;_weight;constructor(t,e,s=0){this._fromVertex=t,this._toVertex=e,this._weight=s}get fromVertex(){return this._fromVertex}get toVertex(){return this._toVertex}get weight(){return this._weight}set weight(t){this._weight=t}}class E extends w{constructor(){super()}getEdgeByValue(t,e){const s=this._edges.find(s=>s.fromVertex===t&&s.toVertex===e);if(!s)throw new f("Edge not found");return s}addEdge(t,e,s){try{const r=this.tryFindVertex(t),i=this.tryFindVertex(e);if(this.hasEdge(r,i))"number"==typeof s&&this.updateEdgeWeight(r,i,s);else{const t=new m(r,i,s);this._edges.push(t),this._vertices.get(r)?.push(i)}}catch{throw new f("Edge cannot be added because one of vertices was not found")}return this}removeEdge(t,e){try{const s=this.tryFindVertex(t),r=this.tryFindVertex(e),i=this.getEdgeByValue(s,r),n=(this._vertices.get(s)||[]).filter(t=>r!==t);this._vertices.set(s,n),this._edges=this._edges.filter(t=>t!==i)}catch{throw new f("Edge cannot be removed because one of vertices was not found")}return this}}class y extends w{constructor(){super()}getEdgeByValue(t,e){const s=this._edges.find(s=>s.fromVertex===t&&s.toVertex===e||s.fromVertex===e&&s.toVertex===t);if(!s)throw new f("Edge not found");return s}hasEdge(t,e){return Boolean(this._edges.find(s=>s.fromVertex===t&&s.toVertex===e||s.fromVertex===e&&s.toVertex===t))}addEdge(t,e,s){try{const r=this.tryFindVertex(t),i=this.tryFindVertex(e);if(this.hasEdge(r,i))"number"==typeof s&&this.updateEdgeWeight(r,i,s);else{const t=new m(r,i,s);this._edges.push(t),this._vertices.get(r)?.push(i),this._vertices.get(i)?.push(r)}}catch{throw new f("Edge cannot be added because one of vertices was not found")}return this}removeEdge(t,e){try{const s=this.tryFindVertex(t),r=this.tryFindVertex(e),i=this.getEdgeByValue(s,r),n=this._vertices.get(s)||[],h=this._vertices.get(r)||[],a=n.filter(t=>r!==t),o=h.filter(t=>s!==t);this._vertices.set(s,a),this._vertices.set(r,o),this._edges=this._edges.filter(t=>t!==i)}catch{throw new f("Edge cannot be removed because one of vertices was not found")}return this}}const v=t=>{let e;switch(t){case g.DIRECTED:e=new E;break;case g.UNDIRECTED:e=new y}return e},N=1,I=0,V=(t,e,s)=>{if(!c(t))throw new h("Given array is not a matrix");const r=v(s);return e.forEach(t=>{r.addVertex(t)}),t.forEach((i,n)=>{i.forEach((i,h)=>{const a=t[n][h],o=t[h][n];s===g.UNDIRECTED&&1===a&&1===o&&r.addEdge(e[n],e[h]),s===g.DIRECTED&&(1===a&&r.addEdge(e[n],e[h]),1===o&&r.addEdge(e[h],e[n]))})}),r},R=t=>{const e=t.vertices(),s=new Array(t.verticesCount());return e.forEach((r,i)=>{s[i]=new Array(t.verticesCount()),e.forEach((e,n)=>{const h=t.hasEdge(r,e);s[i][n]=h?1:0})}),s},k=t=>{const e=t.vertices(),s=R(t),r=p(s);return V(r,e,g.DIRECTED)};class b extends h{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,b.prototype)}}class D extends _{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,D.prototype)}}class B extends _{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,B.prototype)}}class C extends h{constructor(t){super(t),this.name=this.constructor.name,Object.setPrototypeOf(this,C.prototype)}}class O{_capacity;_length;_head;_tail;constructor(t){this._capacity=O.calculateCapacity(t),this._head=null,this._tail=null,this._length=0}static calculateCapacity(t){if(void 0===t)return Number.MAX_VALUE;if(t<=0)throw new b("Capacity must be larger than 0");return t}insertNodeBetweenTwoNodes(t,e,s){if(this.isFull())throw new D("List is full, no more space available");null===this._head&&(this._head=t),null===this._tail&&(this._tail=t),e||(e=this._tail),s||(s=this._head),this.insertNodeBetweenTwoNodesImpl(t,e,s),this._length++}deleteNode(t){if(this.isEmpty())throw new B("cannot delete because list is empty");return this.deleteNodeImpl(t),this._length--,this.isEmpty()&&this.clear(),t}getNodeByIndex(t){const e=t<0||t>this._length;if(this.isEmpty())throw new B("List is empty");if(e)throw new C("Index exceed list length");let s=this._tail,r=0;for(;s&&r<t;)s=s.next,r++;return s}unshift(t){const e=this.createNode(t);this.insertNodeBetweenTwoNodes(e,this._head,this._tail),this._tail=e}push(t){const e=this.createNode(t);this.insertNodeBetweenTwoNodes(e,this._head,this._tail),this._head=e}pushFromIndex(t,e){const s=e<0||e>this._length,r=this.isEmpty()&&0===e;if(s)throw new C("index must be in range between 0 and list length");if(r)this.push(t);else{const s=this.createNode(t),r=this.getNodeByIndex(e-1),i=this.getNodeByIndex(e);this.insertNodeBetweenTwoNodes(s,r,i)}}pop(){const t=this.deleteNode(this._head);return this.popImpl(),t.data}shift(){const t=this.deleteNode(this._tail);return this.shiftImpl(),t.data}deleteFromIndex(t){const e=this.getNodeByIndex(t);return this.deleteNode(e).data}length(){return this._length}isEmpty(){return 0===this._length||null===this._head||null===this._tail}isFull(){return this._length>=this._capacity}has(t){return this.getAsArray().includes(t)}peek(){if(this.isEmpty()||!this._head)throw new B("head does not exist");return this._head.data}peekFromStart(){if(this.isEmpty()||!this._tail)throw new B("tail does not exist");return this._tail.data}peekByIndex(t){return this.getNodeByIndex(t).data}clear(){this._head=null,this._tail=null,this._length=0}getAsArray(){const t=[];let e=this._tail,s=0;for(;e&&s<this._length;)e&&t.push(e.data),e=e.next,s++;return t}pushFromArray(t){t.forEach(t=>{if(this.isFull())throw new D("List is full, no more space available");this.push(t)})}}class T{_next;_data;constructor(t,e=null){this._data=t,this._next=e}get data(){return this._data}get next(){return this._next}set next(t){this._next=t}}class F extends T{_prev;_next;constructor(t,e=null,s=null){super(t),this._prev=s,this._next=e}set prev(t){this._prev=t}get prev(){return this._prev}set next(t){this._next=t}get next(){return this._next}}class P extends O{_head;_tail;constructor(t){super(t),this._head=null,this._tail=null}createNode(t){return new F(t)}insertNodeBetweenTwoNodesImpl(t,e,s){t.next=s,t.prev=e,t.prev&&(t.prev.next=t),t.next&&(t.next.prev=t)}deleteNodeImpl(t){t.prev.next=t.next,t.next.prev=t.prev,t.next=null,t.prev=null}popImpl(){this._head=this._tail?.prev||null}shiftImpl(){this._tail=this._head?.next||null}reverse(){let t=this._tail,e=0;for(;t&&e<this._length;){const s=t.next,r=t.prev;t.prev=s,t.next=r,e++,t=r}t&&(this._tail=t.next,this._head=t)}}class S{_list;constructor(t){this._list=new P(t)}peek(){if(this.isEmpty())throw new B("Cannot peek when list is empty");return this._list.peek()}push(t){if(this._list.isFull())throw new D("Cannot push when queue is full");this._list.unshift(t)}pop(){if(this.isEmpty())throw new B("Cannot pop when list is empty");return this._list.pop()}has(t){return this._list.has(t)}isEmpty(){return this._list.isEmpty()}isFull(){return this._list.isFull()}clear(){this._list.clear()}length(){return this._list.length()}reverse(){this._list.reverse()}}class A{graph;visited;parents;constructor(t){this.graph=t,this.visited=/* @__PURE__ */new Map,this.parents=/* @__PURE__ */new Map}initIterator(t){if(!this.graph.hasVertex(t))throw new f("Start vertex does not exist");this.initIteratorImpl(t)}hasNext(){return this.hasNextImpl()}next(){if(!this.hasNext())throw new _("Next element does not exist");return this.nextImpl()}current(){try{return this.currentImpl()}catch(t){throw new _("Current element does not exist")}}getPath(t,e){const s=new Array,r=this.graph.hasEdge(t,e);let i=this.parents.get(e);if(r)return[t,e];for(;i&&i!==t;)s.push(i),i=this.parents.get(i);if(0===s.length)throw new _("There is no path found");return[t,...s.reverse(),e]}}class M extends A{queue;constructor(t){super(t),this.queue=new S}currentImpl(){return this.queue.peek()}initIteratorImpl(t){this.queue.push(t),this.visited.set(t,!0)}hasNextImpl(){return!this.queue.isEmpty()}nextImpl(){const t=this.queue.pop();return this.graph.getVertexNeighbors(t).forEach(e=>{!this.visited.get(e)&&(this.queue.push(e),this.visited.set(e,!0),this.parents.set(e,t))}),t}}class L{createIterator(t){return new M(t)}}class j{_list;constructor(t){this._list=new P(t)}peek(){if(this.isEmpty())throw new B("Cannot peek when list is empty");return this._list.peek()}push(t){if(this.isFull())throw new D("Stack is full");this._list.push(t)}pop(){if(this.isEmpty())throw new B("Cannot pop when stack is empty");return this._list.pop()}has(t){return this._list.has(t)}isEmpty(){return this._list.isEmpty()}isFull(){return this._list.isFull()}clear(){this._list.clear()}length(){return this._list.length()}reverse(){this._list.reverse()}}class U extends A{stack;constructor(t){super(t),this.stack=new j}hasNextImpl(){return!this.stack.isEmpty()}initIteratorImpl(t){this.stack.push(t),this.visited.set(t,!0)}currentImpl(){return this.stack.peek()}nextImpl(){const t=this.stack.pop();return this.graph.getVertexNeighbors(t).forEach(e=>{!this.visited.get(e)&&(this.stack.push(e),this.visited.set(e,!0),this.parents.set(e,t))}),t}}class q{createIterator(t){return new U(t)}}class H extends A{costs;constructor(t){super(t),this.costs=/* @__PURE__ */new Map}getClosestNotVisited(){const t=Array.from(this.costs.keys()).filter(t=>!this.visited.get(t)).sort((t,e)=>(this.costs.get(t)||0)-(this.costs.get(e)||0));if(void 0===t[0])throw new _("No more vertices found");return t[0]}initIteratorImpl(t){this.visited.set(t,!0),this.costs.set(t,0),this.graph.getVertexNeighbors(t).forEach(e=>{const s=this.graph.getEdgeWeight(t,e);this.costs.set(e,s),this.parents.set(e,t)})}hasNextImpl(){return!(null===this.getClosestNotVisited())}currentImpl(){return this.getClosestNotVisited()}nextImpl(){const t=this.getClosestNotVisited();this.visited.set(t,!0);const e=this.graph.getVertexNeighbors(t),s=this.costs.get(t);return e.forEach(e=>{const r=this.graph.getEdgeWeight(t,e),i=this.costs.get(e)||1/0,n=(s||0)+r;n<i&&(this.costs.set(e,n),this.parents.set(e,t))}),t}}class W{createIterator(t){return new H(t)}}const G=(t,e,s,r)=>{if(!t.hasVertex(e))throw new f("Start vertex was not found");if(!t.hasVertex(s))throw new f("End vertex was not found");const i=r.createIterator(t);for(i.initIterator(e);i.hasNext();){if(i.next()===s)return!0}return!1},Z=(t,e,s,r)=>{if(!t.hasVertex(e))throw new f("Start vertex was not found");if(!t.hasVertex(s))throw new f("End vertex was not found");const i=r.createIterator(t);for(i.initIterator(e);i.hasNext();){if(i.next()===s)break}return i.getPath(e,s)},z=t=>t.vertices().reduce((e,s)=>{const r=t.getVertexNeighbors(s);return e.set(s,r),e},/* @__PURE__ */new Map);var J=/* @__PURE__ */(t=>(t.NUMBERS="NUMBERS",t.HASH="HASH",t))(J||{});const X=()=>"_"+Math.random().toString(36).substr(2,9),$=(t,e,s=g.UNDIRECTED,r=J.NUMBERS)=>{const i=v(s),n=((t,e)=>{let s=e*(e-1);switch(t){case g.DIRECTED:break;case g.UNDIRECTED:s=Math.floor(s/2)}return s})(s,t);if(e<=0||e>n)throw new b(`Edges count must be in range between 0 and ${n}`);((t,e,s)=>{switch(e){case J.HASH:for(let e=0;e<s;e++)t.addVertex(X());break;case J.NUMBERS:for(let e=0;e<s;e++)t.addVertex((e+1).toString())}})(i,r,t);const h=i.vertices();let a=0;for(;a<e;){const t=()=>d(0,h.length),e=h[t()],s=h[t()],r=i.hasEdge(e,s);e===s||r||(i.addEdge(e,s),a++)}return i};var K=/* @__PURE__ */(t=>(t.DOUBLE="Double linked list",t.SINGLE="Single linked list",t))(K||{});class Q extends T{constructor(t,e=null){super(t,e)}}class Y extends O{_head;_tail;constructor(t){super(t),this._head=null,this._tail=null}getPrevNode(t){let e=this._tail;for(;e?.next!==t;)e=e?.next||null;return e}createNode(t){return new Q(t)}insertNodeBetweenTwoNodesImpl(t,e,s){t.next=s,e&&(e.next=t)}deleteNodeImpl(t){this.getPrevNode(t).next=t.next,t.next=null}popImpl(){this._head=this.getPrevNode(this._tail)}shiftImpl(){this._tail=this._head?.next||null}reverse(){let t=this._tail,e=this._head,s=0;for(;s<this._length;){const r=t?.next||null;t&&(t.next=e),s++,e=t,t=r}t&&(this._head=t,this._tail=t.next)}}class tt extends P{constructor(t){super(t)}iterator(t=0){const e=this._head,s=this._tail;let r=this.getNodeByIndex(t);const i={current:()=>r.data,hasNext:()=>Boolean(r.next)&&r!==e,hasPrev:()=>Boolean(r.prev)&&r!==s,next:()=>{if(!i.hasNext())throw new f("Next element does not exist");return r=r.next,r.data},prev:()=>{if(!i.hasPrev())throw new f("Prev element does not exist");return r=r.prev,r.data}};return i}}class et extends Y{constructor(t){super(t)}iterator(t=0){const e=this._head;let s=this.getNodeByIndex(t);const r={current:()=>s.data,hasNext:()=>Boolean(s.next)&&s!==e,next:()=>{if(!r.hasNext())throw new f("Next element does not exist");return s=s.next,s.data}};return r}}const st=(t,e=!1,s)=>{let r;if(e)switch(t){case K.DOUBLE:r=new tt(s);break;case K.SINGLE:r=new et(s)}else switch(t){case K.DOUBLE:r=new P(s);break;case K.SINGLE:r=new Y(s)}return r};var rt=/* @__PURE__ */(t=>(t.BST="Binary Search Tree",t.RANDOMIZED_BST="Randomized Binary Search Tree",t))(rt||{}),it=/* @__PURE__ */(t=>(t.IN_ORDER="IN_ORDER",t.PRE_ORDER="PRE_ORDER",t.POST_ORDER="POST_ORDER",t))(it||{});class nt{compare=(t,e)=>t>e;_head;_length;constructor(t){t&&(this.compare=t),this._head=null,this._length=0}length(){return this._length}}class ht{_data;_left;_right;_parent;constructor(t){this._data=t,this._left=null,this._right=null,this._parent=null}get data(){return this._data}set data(t){this._data=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}get parent(){return this._parent}set parent(t){this._parent=t}}class at extends ht{_left;_right;_parent;constructor(t){super(t),this._left=null,this._right=null,this._parent=null}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}get parent(){return this._parent}set parent(t){this._parent=t}}class ot extends nt{_head;constructor(t){super(t),this._head=null}checkIsEmpty(){if(null===this._head)throw new B("Tree is empty")}updateLeftRightParents(t){t.left&&t.left.parent!==t&&(t.left.parent=t),t.right&&t.right.parent!==t&&(t.right.parent=t)}findNode(t){let e=this._head;for(;e&&e.data!==t;)e=this.compare(e.data,t)?e.left:e.right;return e}insertToLeaf(t){let e=null,s=this._head;for(;s;)e=s,s=this.compare(s.data,t.data)?s.left:s.right;t.parent=e,null===e?this._head=t:this.compare(e.data,t.data)?e.left=t:e.right=t,this._length++}join(t,e){return null===t?e:null===e?t:(e.left=this.join(t,e.left),e.left&&this.updateLeftRightParents(e),e)}max(){this.checkIsEmpty();let t=this._head;for(;t?.right;)t=t.right;return t.data}min(){this.checkIsEmpty();let t=this._head;for(;t?.left;)t=t.left;return t.data}insert(t){if(this.has(t))throw new x("Node already exists");const e=new at(t);this.insertToLeaf(e)}has(t){const e=this.findNode(t);return e?.data===t}delete(t){if(!this.has(t))throw new f("Value does not exist in the tree");const e=(t,s)=>{if(null===t)return t;if(t.data===s){const e=this.join(t.left,t.right);return e&&(e.parent=t.parent),e}return this.compare(t.data,s)?t.left=e(t.left,s):t.right=e(t.right,s),this.updateLeftRightParents(t),t};this._head=e(this._head,t),this._length--}subtree(t){const e=new ot,s=this.findNode(t),r=new S,i=[];for(r.push(s);!r.isEmpty();){const t=r.pop();i.push(t),t?.left&&r.push(t.left),t?.right&&r.push(t.right)}return i.forEach(t=>{null!==t&&e.insert(t.data)}),e}traverse(t,e){this.checkIsEmpty();const s=new Array(this.length()),r=void 0!==e?this.findNode(e):this._head,i=t=>{null!==t&&(i(t.left),s.push(t.data),i(t.right))};switch(t){case it.IN_ORDER:i(r);break;case it.POST_ORDER:null!==(n=r)&&(i(n.left),i(n.right),s.push(n.data));break;case it.PRE_ORDER:(t=>{null!==t&&(s.push(t.data),i(t.left),i(t.right))})(r)}var n;return s.filter(t=>void 0!==t)}height(){const t=e=>{if(null===e)return 0;const s=null===e.left?-1:t(e.left),r=null===e.right?-1:t(e.right);return(s>r?s:r)+1};return null===this._head?0:t(this._head)+1}}class lt extends at{_rank;_left;_right;_parent;constructor(t){super(t),this._rank=0,this._left=null,this._right=null,this._parent=null}get rank(){return this._rank}set rank(t){this._rank=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}get parent(){return this._parent}set parent(t){this._parent=t}}class dt extends ot{_head;constructor(t){super(t),this._head=null}updateRank(t){t.rank=(t.right?.rank||0)+(t.left?.rank||0)+1}addCreatedNode(t,e=null){return t.rank=1,null!==e&&(t.parent=e),t}rotateNodeRight(t){const e=t.left;null!==e&&(t.left=e.right,null!==e.right&&(e.right.parent=t),e.parent=t.parent,null===t.parent?this._head=e:t===t.parent.right?t.parent.right=e:t.parent.left=e,e.right=t,t.parent=e,this.updateRank(t),this.updateRank(e))}rotateNodeLeft(t){const e=t.right;null!==e&&(t.right=e.left,null!==e.left&&(e.left.parent=t),e.parent=t.parent,null===t.parent?this._head=e:t===t.parent.left?t.parent.left=e:t.parent.right=e,e.left=t,t.parent=e,this.updateRank(t),this.updateRank(e))}join(t,e){return null===t?e:null===e?t:Math.random()<t.rank/(t.rank+e.rank)?(t.right=this.join(t.right,e),t.right&&this.updateLeftRightParents(t),this.updateRank(t),t):(e.left=this.join(t,e.left),e.left&&this.updateLeftRightParents(e),this.updateRank(e),e)}updateLeftRightParents(t){super.updateLeftRightParents(t),this.updateRank(t)}insertToRoot(t,e){const s=e=>{this.compare(e.data,t.data)?(null===e.left?e.left=this.addCreatedNode(t,e):s(e.left),this.rotateNodeRight(e)):(null===e.right?e.right=this.addCreatedNode(t,e):s(e.right),this.rotateNodeLeft(e))};null===this._head?this._head=this.addCreatedNode(t):s(e||this._head)}insertRandomly(t){const e=s=>{Math.random()<1/(s.rank+1)?this.insertToRoot(t,s):(s.rank=s.rank+1,this.compare(s.data,t.data)?null===s.left?s.left=this.addCreatedNode(t,s):e(s.left):null===s.right?s.right=this.addCreatedNode(t,s):e(s.right))};null===this._head?this._head=this.addCreatedNode(t):e(this._head)}insert(t){if(this.has(t))throw new x("Node already exists");const e=new lt(t);this.insertRandomly(e)}delete(t){super.delete(t),this._length=this.length()}length(){return this._head?.rank||0}}const ut=t=>{let e;switch(t){case rt.BST:e=new ot;break;case rt.RANDOMIZED_BST:e=new dt}return e},ct=t=>{for(let e=0;e<t.length-1;e++)for(let s=0;s<t.length-1;s++)t[s]>t[s+1]&&l(t,s,s+1);return t},pt=t=>{for(let e=0;e<t.length;e++){const s=o(t,e);l(t,s,e)}return t},gt=(t,e,s)=>{if(s>e){const r=Math.floor(e+(s-e)/2);gt(t,e,r),gt(t,r+1,s),((t,e,s,r)=>{const i=t.slice(e,r+1);let n=e,h=e,a=s+1;for(;h<=s&&a<=r;){const s=i[h-e],r=i[a-e];s<r?(t[n]=s,h++):(t[n]=r,a++),n++}for(;h<=s;)t[n]=i[h-e],n++,h++;for(;a<=r;)t[n]=i[a-e],n++,a++})(t,e,r,s)}},_t=t=>(gt(t,0,t.length-1),t),ft=t=>{for(let e=1;e<t.length;e++){const s=t[e];let r=e-1;for(;r>=0&&t[r]>s;)l(t,r+1,r),r--;t[r+1]=s}return t},xt=t=>{const e=(t,s=0,r=t.length-1)=>{if(s<r){const i=((t,e,s)=>{const r=t[e];let i=e,n=s;for(;i<=n;){for(;t[n]>r;)n--;for(;t[i]<r;)i++;i<=n&&(l(t,i,n),n--,i++)}return i})(t,s,r);e(t,s,i-1),e(t,i,r)}return t};return e(t)};export{L as BFSIterationStrategy,ot as BinarySearchTree,B as CollectionIsEmptyException,D as CollectionIsFullException,q as DFSIterationStrategy,W as DijkstraIterationStrategy,E as DirectedGraph,P as DoubleLinkedList,N as EDGE_EXISTS_STATE,I as EDGE_NOT_EXISTS_STATE,M as GraphIteratorBFS,U as GraphIteratorDFS,H as GraphIteratorDijkstra,h as IllegalArgumentException,_ as IllegalStateException,C as IndexOutOfBoundsException,x as IsAlreadyExistsException,f as IsNotFoundException,tt as IterableDoubleLinkedList,et as IterableSingleLinkedList,S as Queue,dt as RandBinarySearchTree,Y as SingleLinkedList,j as Stack,y as UndirectedGraph,b as ValueOutOfRangeException,n as binarySearch,ct as bubbleSort,ut as createBinaryTree,v as createGraph,V as createGraphFromMatrix,st as createLinkedList,e as factorial,r as fibonacci,$ as generateRandomGraph,a as getMinIndex,o as getMinIndexFromIndex,G as hasPath,ft as insertionSort,t as memoize,s as memoizedFactorial,i as memoizedFibonacci,_t as mergeSort,z as presenterAdjacencyLists,R as presenterAdjacencyMatrix,xt as quickSort,d as randomizeNumberInRange,u as roundNumber,pt as selectSort,Z as shortestPath,l as swapArrayItems,k as transposeDirectedGraph,p as transposeMatrix};
package/package.json CHANGED
@@ -1,72 +1,78 @@
1
- {
2
- "name": "@raikuxq/alg-ds",
3
- "scripts": {
4
- "test": "jest",
5
- "dev": "nodemon",
6
- "build": "rimraf ./lib && tsc",
7
- "start": "npm run build && node lib/index.js",
8
- "lint": "yarn eslint . --ext .ts",
9
- "lint:fix": "yarn eslint --fix . --ext .ts",
10
- "docs:dev": "vuepress dev docs",
11
- "docs:build": "vuepress build docs"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/raikuxq/lab-ts-algorithms"
16
- },
17
- "keywords": [
18
- "algorithms",
19
- "data structures",
20
- "graph",
21
- "undirected graph",
22
- "directed graph",
23
- "breadth-first",
24
- "depth-first",
25
- "BFS",
26
- "DFS",
27
- "shortest path",
28
- "binary search tree",
29
- "randomized binary search tree",
30
- "BST",
31
- "dijkstra",
32
- "quick sort",
33
- "merge sort",
34
- "binary search",
35
- "linked list",
36
- "doubly linked list",
37
- "singly linked list",
38
- "stack",
39
- "queue",
40
- "hash table"
41
- ],
42
- "main": "./lib/src/exports.js",
43
- "types": "./lib/src/exports.d.ts",
44
- "files": [
45
- "lib",
46
- "README.md",
47
- "LICENSE"
48
- ],
49
- "devDependencies": {
50
- "@types/jest": "^26.0.14",
51
- "@types/node": "^14.0.24",
52
- "@typescript-eslint/eslint-plugin": "^4.4.0",
53
- "@typescript-eslint/parser": "^4.4.0",
54
- "@vuepress/plugin-search": "^2.0.0-beta.48",
55
- "@vuepress/theme-default": "^2.0.0-beta.48",
56
- "eslint": "^7.11.0",
57
- "eslint-config-prettier": "^6.12.0",
58
- "eslint-config-recommended": "^4.1.0",
59
- "eslint-plugin-prettier": "^3.1.4",
60
- "jest": "^26.1.0",
61
- "nodemon": "^2.0.4",
62
- "prettier": "^2.1.2",
63
- "rimraf": "^3.0.2",
64
- "ts-jest": "^26.4.1",
65
- "ts-node": "^10.7.0",
66
- "ts-node-esm": "^0.0.6",
67
- "typescript": "^4.0.3",
68
- "vuepress": "^2.0.0-beta.48"
69
- },
70
- "dependencies": {},
71
- "version": "1.2.4"
72
- }
1
+ {
2
+ "name": "@raikuxq/alg-ds",
3
+ "scripts": {
4
+ "test": "jest",
5
+ "dev": "nodemon",
6
+ "build:lib": "rimraf ./lib && vite build",
7
+ "build:dts": "dts-bundle-generator -o lib/index.d.ts src/index.ts --no-check --inline-declare-externals false --external-inlines @babel/types",
8
+ "build:full": "yarn build:lib && yarn build:dts",
9
+ "start": "npm run build && node lib/index.js",
10
+ "lint": "yarn eslint . --ext .ts",
11
+ "lint:fix": "yarn eslint --fix . --ext .ts",
12
+ "docs:dev": "vuepress dev docs",
13
+ "docs:build": "vuepress build docs"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/raikuxq/lab-ts-algorithms"
18
+ },
19
+ "keywords": [
20
+ "algorithms",
21
+ "data structures",
22
+ "graph",
23
+ "undirected graph",
24
+ "directed graph",
25
+ "breadth-first",
26
+ "depth-first",
27
+ "BFS",
28
+ "DFS",
29
+ "shortest path",
30
+ "binary search tree",
31
+ "randomized binary search tree",
32
+ "BST",
33
+ "dijkstra",
34
+ "quick sort",
35
+ "merge sort",
36
+ "binary search",
37
+ "linked list",
38
+ "doubly linked list",
39
+ "singly linked list",
40
+ "stack",
41
+ "queue"
42
+ ],
43
+ "main": "./lib/index.mjs",
44
+ "module": "./lib/index.mjs",
45
+ "types": "./lib/index.d.ts",
46
+ "files": [
47
+ "lib",
48
+ "README.md",
49
+ "LICENSE"
50
+ ],
51
+ "devDependencies": {
52
+ "@types/jest": "^30.0.0",
53
+ "@types/node": "^25.0.9",
54
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
55
+ "@typescript-eslint/parser": "^8.53.0",
56
+ "@vuepress/plugin-search": "^2.0.0-beta.48",
57
+ "@vuepress/theme-default": "^2.0.0-beta.48",
58
+ "dts-bundle-generator": "^9.5.1",
59
+ "eslint": "^9.39.2",
60
+ "eslint-config-prettier": "^10.1.8",
61
+ "eslint-config-recommended": "^4.1.0",
62
+ "eslint-plugin-prettier": "^5.5.5",
63
+ "jest": "^30.2.0",
64
+ "nodemon": "^3.1.11",
65
+ "prettier": "^3.8.0",
66
+ "rimraf": "^6.1.2",
67
+ "terser": "^5.46.0",
68
+ "ts-jest": "^29.4.6",
69
+ "ts-node": "^10.9.2",
70
+ "ts-node-esm": "^0.0.6",
71
+ "typescript": "5.8.2",
72
+ "vite": "^7.3.1",
73
+ "vuepress": "^2.0.0-beta.48"
74
+ },
75
+ "dependencies": {},
76
+ "version": "2.0.0",
77
+ "sideEffects": false
78
+ }
@@ -1,5 +0,0 @@
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;
@@ -1,27 +0,0 @@
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==
@@ -1,9 +0,0 @@
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>;
@@ -1,17 +0,0 @@
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=
@@ -1,9 +0,0 @@
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>;
@@ -1,17 +0,0 @@
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==
@@ -1,39 +0,0 @@
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
- * @throws {IsNotFoundException} when start vertex was not found
18
- */
19
- initIterator(from: T): void;
20
- /**
21
- * @inheritDoc
22
- */
23
- hasNext(): boolean;
24
- /**
25
- * @inheritDoc
26
- * @throws {IllegalStateException} when next element does not exist
27
- */
28
- next(): T;
29
- /**
30
- * @inheritDoc
31
- * @throws {IllegalStateException} when current element does not exist
32
- */
33
- current(): T;
34
- /**
35
- * @inheritDoc
36
- * @throws {IllegalStateException} when there is no path between given vertices
37
- */
38
- getPath(from: T, to: T): Array<T>;
39
- }
@@ -1,87 +0,0 @@
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
- * @throws {IsNotFoundException} when start vertex was not found
24
- */
25
- AbstractGraphIterator.prototype.initIterator = function (from) {
26
- if (!this.graph.hasVertex(from)) {
27
- throw new IsNotFoundException_1.default("Start vertex does not exist");
28
- }
29
- this.initIteratorImpl(from);
30
- };
31
- /**
32
- * @inheritDoc
33
- */
34
- AbstractGraphIterator.prototype.hasNext = function () {
35
- return this.hasNextImpl();
36
- };
37
- /**
38
- * @inheritDoc
39
- * @throws {IllegalStateException} when next element does not exist
40
- */
41
- AbstractGraphIterator.prototype.next = function () {
42
- if (!this.hasNext()) {
43
- throw new IllegalStateException_1.default("Next element does not exist");
44
- }
45
- return this.nextImpl();
46
- };
47
- /**
48
- * @inheritDoc
49
- * @throws {IllegalStateException} when current element does not exist
50
- */
51
- AbstractGraphIterator.prototype.current = function () {
52
- try {
53
- return this.currentImpl();
54
- }
55
- catch (e) {
56
- throw new IllegalStateException_1.default("Current element does not exist");
57
- }
58
- };
59
- /**
60
- * @inheritDoc
61
- * @throws {IllegalStateException} when there is no path between given vertices
62
- */
63
- AbstractGraphIterator.prototype.getPath = function (from, to) {
64
- var path = new Array();
65
- var isLinkedDirectly = this.graph.hasEdge(from, to);
66
- var currentVertex = this.parents.get(to);
67
- if (isLinkedDirectly) {
68
- return [from, to];
69
- }
70
- else {
71
- while (currentVertex) {
72
- if (currentVertex === from) {
73
- break;
74
- }
75
- path.push(currentVertex);
76
- currentVertex = this.parents.get(currentVertex);
77
- }
78
- if (path.length === 0) {
79
- throw new IllegalStateException_1.default("There is no path found");
80
- }
81
- return __spreadArrays([from], path.reverse(), [to]);
82
- }
83
- };
84
- return AbstractGraphIterator;
85
- }());
86
- exports.default = AbstractGraphIterator;
87
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWJzdHJhY3RHcmFwaEl0ZXJhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vc3JjL2FwcC9hbGdvcml0aG1zL2dyYXBoL2l0Z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"../../../types/IGraph";
2
- import AbstractGraphIterator from "./AbstractGraphIterator";
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
- }
@@ -1,70 +0,0 @@
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJdGVyYXRvckJGUy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hcHAvYWxnb3JpdGhtcy9ncmFwaC9pdGVyYXRvci9HcmFwaEl0ZXJhdG9yQkZTLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhEQUF5RDtBQUV6RCxpRUFBNEQ7QUFFNUQ7O0dBRUc7QUFDSDtJQUFpRCxvQ0FBd0I7SUFHdkU7O09BRUc7SUFDSCwwQkFBbUIsS0FBZ0I7UUFBbkMsWUFDRSxrQkFBTSxLQUFLLENBQUMsU0FFYjtRQURDLEtBQUksQ0FBQyxLQUFLLEdBQUcsSUFBSSxlQUFLLEVBQUUsQ0FBQzs7SUFDM0IsQ0FBQztJQUVEOztPQUVHO0lBQ08sc0NBQVcsR0FBckI7UUFDRSxPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxFQUFFLENBQUM7SUFDM0IsQ0FBQztJQUVEOztPQUVHO0lB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CxDQUFpRCwrQkFBcUIsR0FvRHJFIn0=
@@ -1,28 +0,0 @@
1
- import IGraph from "../../../types/IGraph";
2
- import AbstractGraphIterator from "./AbstractGraphIterator";
3
- /**
4
- * Deep first graph traversal
5
- */
6
- export default class GraphIteratorDFS<T> extends AbstractGraphIterator<T> {
7
- private readonly stack;
8
- /**
9
- * @inheritDoc
10
- */
11
- constructor(graph: IGraph<T>);
12
- /**
13
- * @inheritDoc
14
- */
15
- hasNextImpl(): boolean;
16
- /**
17
- @inheritDoc
18
- */
19
- initIteratorImpl(startVertex: T): void;
20
- /**
21
- * @inheritDoc
22
- */
23
- currentImpl(): T;
24
- /**
25
- * @inheritDoc
26
- */
27
- nextImpl(): T;
28
- }
@@ -1,70 +0,0 @@
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 Stack_1 = require("../../../data-structures/Stack/Stack");
17
- var AbstractGraphIterator_1 = require("./AbstractGraphIterator");
18
- /**
19
- * Deep first graph traversal
20
- */
21
- var GraphIteratorDFS = /** @class */ (function (_super) {
22
- __extends(GraphIteratorDFS, _super);
23
- /**
24
- * @inheritDoc
25
- */
26
- function GraphIteratorDFS(graph) {
27
- var _this = _super.call(this, graph) || this;
28
- _this.stack = new Stack_1.default();
29
- return _this;
30
- }
31
- /**
32
- * @inheritDoc
33
- */
34
- GraphIteratorDFS.prototype.hasNextImpl = function () {
35
- return !this.stack.isEmpty();
36
- };
37
- /**
38
- @inheritDoc
39
- */
40
- GraphIteratorDFS.prototype.initIteratorImpl = function (startVertex) {
41
- this.stack.push(startVertex);
42
- this.visited.set(startVertex, true);
43
- };
44
- /**
45
- * @inheritDoc
46
- */
47
- GraphIteratorDFS.prototype.currentImpl = function () {
48
- return this.stack.peek();
49
- };
50
- /**
51
- * @inheritDoc
52
- */
53
- GraphIteratorDFS.prototype.nextImpl = function () {
54
- var _this = this;
55
- var next = this.stack.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.stack.push(neighbor);
61
- _this.visited.set(neighbor, true);
62
- _this.parents.set(neighbor, next);
63
- }
64
- });
65
- return next;
66
- };
67
- return GraphIteratorDFS;
68
- }(AbstractGraphIterator_1.default));
69
- exports.default = GraphIteratorDFS;
70
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiR3JhcGhJdGVyYXRvckRGUy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9hcHAvYWxnb3JpdGhtcy9ncmFwaC9pdGVyYXRvci9HcmFwaEl0ZXJhdG9yREZTLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhEQUF5RDtBQUV6RCxpRUFBNEQ7QUFFNUQ7O0dBRUc7QUFDSDtJQUFpRCxvQ0FBd0I7SUFHdkU7O09BRUc7SUFDSCwwQkFBbUIsS0FBZ0I7UUFBbkMsWUFDRSxrQkFBTSxLQUFLLENBQUMsU0FFYjtRQURDLEtBQUksQ0FBQyxLQUFLLEdBQUcsSUFBSSxlQUFLLEVBQUUsQ0FBQzs7SUFDM0IsQ0FBQztJQUVEOztPQUVHO0lBQ0ksc0NBQVcsR0FBbEI7UUFDRSxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQ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