@gabrielrufino/cube 1.0.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 (240) hide show
  1. package/.github/workflows/cd.yml +26 -0
  2. package/.github/workflows/ci.yml +23 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1695 -0
  5. package/build/Algorithms/index.d.ts +3 -0
  6. package/build/Algorithms/index.js +24 -0
  7. package/build/Array/IArray.d.ts +9 -0
  8. package/build/Array/IArray.js +2 -0
  9. package/build/Array/index.d.ts +12 -0
  10. package/build/Array/index.js +79 -0
  11. package/build/BinarySearchTree/BinarySearchTreeNode.d.ts +7 -0
  12. package/build/BinarySearchTree/BinarySearchTreeNode.js +22 -0
  13. package/build/BinarySearchTree/IBinarySearchNodeOptions.d.ts +5 -0
  14. package/build/BinarySearchTree/IBinarySearchNodeOptions.js +2 -0
  15. package/build/BinarySearchTree/IBinarySearchTree.d.ts +14 -0
  16. package/build/BinarySearchTree/IBinarySearchTree.js +2 -0
  17. package/build/BinarySearchTree/IBinarySearchTreeData.d.ts +7 -0
  18. package/build/BinarySearchTree/IBinarySearchTreeData.js +2 -0
  19. package/build/BinarySearchTree/index.d.ts +24 -0
  20. package/build/BinarySearchTree/index.js +199 -0
  21. package/build/DataStructure/index.d.ts +6 -0
  22. package/build/DataStructure/index.js +32 -0
  23. package/build/Deck/IDeck.d.ts +9 -0
  24. package/build/Deck/IDeck.js +2 -0
  25. package/build/Deck/index.d.ts +12 -0
  26. package/build/Deck/index.js +76 -0
  27. package/build/Dictionary/IDictionary.d.ts +16 -0
  28. package/build/Dictionary/IDictionary.js +2 -0
  29. package/build/Dictionary/IDictionaryData.d.ts +4 -0
  30. package/build/Dictionary/IDictionaryData.js +2 -0
  31. package/build/Dictionary/index.d.ts +21 -0
  32. package/build/Dictionary/index.js +110 -0
  33. package/build/DoublyLinkedList/IDoublyLinkedList.d.ts +16 -0
  34. package/build/DoublyLinkedList/IDoublyLinkedList.js +2 -0
  35. package/build/DoublyLinkedList/Node.d.ts +6 -0
  36. package/build/DoublyLinkedList/Node.js +11 -0
  37. package/build/DoublyLinkedList/index.d.ts +32 -0
  38. package/build/DoublyLinkedList/index.js +221 -0
  39. package/build/Graph/GraphNodeNotFoundError.d.ts +3 -0
  40. package/build/Graph/GraphNodeNotFoundError.js +27 -0
  41. package/build/Graph/GraphSearchNodeStates.d.ts +6 -0
  42. package/build/Graph/GraphSearchNodeStates.js +10 -0
  43. package/build/Graph/IGraph.d.ts +16 -0
  44. package/build/Graph/IGraph.js +2 -0
  45. package/build/Graph/IGraphOptions.d.ts +7 -0
  46. package/build/Graph/IGraphOptions.js +2 -0
  47. package/build/Graph/index.d.ts +20 -0
  48. package/build/Graph/index.js +187 -0
  49. package/build/HashTable/IHashTable.d.ts +9 -0
  50. package/build/HashTable/IHashTable.js +2 -0
  51. package/build/HashTable/IHashTableData.d.ts +4 -0
  52. package/build/HashTable/IHashTableData.js +2 -0
  53. package/build/HashTable/IHashTableInputs.d.ts +4 -0
  54. package/build/HashTable/IHashTableInputs.js +2 -0
  55. package/build/HashTable/IHashTableOptions.d.ts +4 -0
  56. package/build/HashTable/IHashTableOptions.js +2 -0
  57. package/build/HashTable/index.d.ts +16 -0
  58. package/build/HashTable/index.js +83 -0
  59. package/build/HashTableLinearProbing/HashTableLinearProbingElement.d.ts +6 -0
  60. package/build/HashTableLinearProbing/HashTableLinearProbingElement.js +19 -0
  61. package/build/HashTableLinearProbing/IHashTableLinearProbing.d.ts +9 -0
  62. package/build/HashTableLinearProbing/IHashTableLinearProbing.js +2 -0
  63. package/build/HashTableLinearProbing/IHashTableLinearProbingData.d.ts +5 -0
  64. package/build/HashTableLinearProbing/IHashTableLinearProbingData.js +2 -0
  65. package/build/HashTableLinearProbing/IHashTableLinearProbingInputs.d.ts +4 -0
  66. package/build/HashTableLinearProbing/IHashTableLinearProbingInputs.js +2 -0
  67. package/build/HashTableLinearProbing/IHashTableLinearProbingOptions.d.ts +4 -0
  68. package/build/HashTableLinearProbing/IHashTableLinearProbingOptions.js +2 -0
  69. package/build/HashTableLinearProbing/index.d.ts +20 -0
  70. package/build/HashTableLinearProbing/index.js +120 -0
  71. package/build/HashTableSeparateChaining/HashTableSeparateChainingElement.d.ts +6 -0
  72. package/build/HashTableSeparateChaining/HashTableSeparateChainingElement.js +21 -0
  73. package/build/HashTableSeparateChaining/IHashTableSeparateChaining.d.ts +10 -0
  74. package/build/HashTableSeparateChaining/IHashTableSeparateChaining.js +2 -0
  75. package/build/HashTableSeparateChaining/IHashTableSeparateChainingData.d.ts +5 -0
  76. package/build/HashTableSeparateChaining/IHashTableSeparateChainingData.js +2 -0
  77. package/build/HashTableSeparateChaining/IHashTableSeparateChainingInputs.d.ts +4 -0
  78. package/build/HashTableSeparateChaining/IHashTableSeparateChainingInputs.js +2 -0
  79. package/build/HashTableSeparateChaining/IHashTableSeparateChainingOptions.d.ts +4 -0
  80. package/build/HashTableSeparateChaining/IHashTableSeparateChainingOptions.js +2 -0
  81. package/build/HashTableSeparateChaining/index.d.ts +19 -0
  82. package/build/HashTableSeparateChaining/index.js +104 -0
  83. package/build/LinkedList/ILinkedList.d.ts +13 -0
  84. package/build/LinkedList/ILinkedList.js +2 -0
  85. package/build/LinkedList/ILinkedListItem.d.ts +5 -0
  86. package/build/LinkedList/ILinkedListItem.js +2 -0
  87. package/build/LinkedList/Node.d.ts +5 -0
  88. package/build/LinkedList/Node.js +10 -0
  89. package/build/LinkedList/index.d.ts +24 -0
  90. package/build/LinkedList/index.js +169 -0
  91. package/build/List/index.d.ts +1 -0
  92. package/build/List/index.js +8 -0
  93. package/build/MaxHeap/IMaxHeap.d.ts +9 -0
  94. package/build/MaxHeap/IMaxHeap.js +2 -0
  95. package/build/MaxHeap/IMaxHeapOptions.d.ts +5 -0
  96. package/build/MaxHeap/IMaxHeapOptions.js +2 -0
  97. package/build/MaxHeap/index.d.ts +19 -0
  98. package/build/MaxHeap/index.js +102 -0
  99. package/build/MinHeap/IMinHeap.d.ts +9 -0
  100. package/build/MinHeap/IMinHeap.js +2 -0
  101. package/build/MinHeap/IMinHeapOptions.d.ts +5 -0
  102. package/build/MinHeap/IMinHeapOptions.js +2 -0
  103. package/build/MinHeap/index.d.ts +19 -0
  104. package/build/MinHeap/index.js +102 -0
  105. package/build/Queue/IQueue.d.ts +8 -0
  106. package/build/Queue/IQueue.js +2 -0
  107. package/build/Queue/index.d.ts +11 -0
  108. package/build/Queue/index.js +74 -0
  109. package/build/Set/ISet.d.ts +15 -0
  110. package/build/Set/ISet.js +2 -0
  111. package/build/Set/index.d.ts +21 -0
  112. package/build/Set/index.js +132 -0
  113. package/build/Stack/IStack.d.ts +8 -0
  114. package/build/Stack/IStack.js +2 -0
  115. package/build/Stack/index.d.ts +11 -0
  116. package/build/Stack/index.js +64 -0
  117. package/build/index.d.ts +17 -0
  118. package/build/index.js +40 -0
  119. package/coverage/clover.xml +706 -0
  120. package/coverage/coverage-final.json +19 -0
  121. package/coverage/lcov-report/base.css +224 -0
  122. package/coverage/lcov-report/block-navigation.js +87 -0
  123. package/coverage/lcov-report/favicon.png +0 -0
  124. package/coverage/lcov-report/index.html +327 -0
  125. package/coverage/lcov-report/prettify.css +1 -0
  126. package/coverage/lcov-report/prettify.js +2 -0
  127. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  128. package/coverage/lcov-report/sorter.js +196 -0
  129. package/coverage/lcov-report/src/Algorithms/index.html +117 -0
  130. package/coverage/lcov-report/src/Algorithms/index.ts.html +149 -0
  131. package/coverage/lcov-report/src/Array/index.html +117 -0
  132. package/coverage/lcov-report/src/Array/index.ts.html +290 -0
  133. package/coverage/lcov-report/src/DataStructure/index.html +117 -0
  134. package/coverage/lcov-report/src/DataStructure/index.ts.html +131 -0
  135. package/coverage/lcov-report/src/Deck/index.html +117 -0
  136. package/coverage/lcov-report/src/Deck/index.ts.html +239 -0
  137. package/coverage/lcov-report/src/Dictionary/index.html +117 -0
  138. package/coverage/lcov-report/src/Dictionary/index.ts.html +350 -0
  139. package/coverage/lcov-report/src/DoublyLinkedList/Node.ts.html +113 -0
  140. package/coverage/lcov-report/src/DoublyLinkedList/index.html +132 -0
  141. package/coverage/lcov-report/src/DoublyLinkedList/index.ts.html +836 -0
  142. package/coverage/lcov-report/src/HashTable/index.html +117 -0
  143. package/coverage/lcov-report/src/HashTable/index.ts.html +320 -0
  144. package/coverage/lcov-report/src/HashTableLinearProbing/index.html +117 -0
  145. package/coverage/lcov-report/src/HashTableLinearProbing/index.ts.html +95 -0
  146. package/coverage/lcov-report/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts.html +149 -0
  147. package/coverage/lcov-report/src/HashTableSeparateChaining/index.html +132 -0
  148. package/coverage/lcov-report/src/HashTableSeparateChaining/index.ts.html +398 -0
  149. package/coverage/lcov-report/src/LinkedList/Node.ts.html +110 -0
  150. package/coverage/lcov-report/src/LinkedList/index.html +132 -0
  151. package/coverage/lcov-report/src/LinkedList/index.ts.html +641 -0
  152. package/coverage/lcov-report/src/List/index.html +117 -0
  153. package/coverage/lcov-report/src/List/index.ts.html +89 -0
  154. package/coverage/lcov-report/src/Queue/index.html +117 -0
  155. package/coverage/lcov-report/src/Queue/index.ts.html +218 -0
  156. package/coverage/lcov-report/src/Set/index.html +117 -0
  157. package/coverage/lcov-report/src/Set/index.ts.html +488 -0
  158. package/coverage/lcov-report/src/Stack/index.html +117 -0
  159. package/coverage/lcov-report/src/Stack/index.ts.html +215 -0
  160. package/coverage/lcov-report/src/index.html +117 -0
  161. package/coverage/lcov-report/src/index.ts.html +125 -0
  162. package/coverage/lcov.info +1346 -0
  163. package/package.json +42 -0
  164. package/src/Algorithms/index.spec.ts +15 -0
  165. package/src/Algorithms/index.ts +21 -0
  166. package/src/Array/IArray.ts +10 -0
  167. package/src/Array/index.spec.ts +151 -0
  168. package/src/Array/index.ts +68 -0
  169. package/src/BinarySearchTree/BinarySearchTreeNode.spec.ts +29 -0
  170. package/src/BinarySearchTree/BinarySearchTreeNode.ts +23 -0
  171. package/src/BinarySearchTree/IBinarySearchNodeOptions.ts +6 -0
  172. package/src/BinarySearchTree/IBinarySearchTree.ts +16 -0
  173. package/src/BinarySearchTree/IBinarySearchTreeData.ts +9 -0
  174. package/src/BinarySearchTree/index.spec.ts +486 -0
  175. package/src/BinarySearchTree/index.ts +198 -0
  176. package/src/DataStructure/index.spec.ts +25 -0
  177. package/src/DataStructure/index.ts +15 -0
  178. package/src/Deck/IDeck.ts +10 -0
  179. package/src/Deck/index.spec.ts +131 -0
  180. package/src/Deck/index.ts +51 -0
  181. package/src/Dictionary/IDictionary.ts +18 -0
  182. package/src/Dictionary/IDictionaryData.ts +5 -0
  183. package/src/Dictionary/index.spec.ts +310 -0
  184. package/src/Dictionary/index.ts +88 -0
  185. package/src/DoublyLinkedList/IDoublyLinkedList.ts +18 -0
  186. package/src/DoublyLinkedList/Node.ts +9 -0
  187. package/src/DoublyLinkedList/index.spec.ts +478 -0
  188. package/src/DoublyLinkedList/index.ts +250 -0
  189. package/src/Graph/GraphNodeNotFoundError.ts +7 -0
  190. package/src/Graph/GraphSearchNodeStates.ts +8 -0
  191. package/src/Graph/IGraph.ts +15 -0
  192. package/src/Graph/IGraphOptions.ts +6 -0
  193. package/src/Graph/index.spec.ts +318 -0
  194. package/src/Graph/index.ts +170 -0
  195. package/src/HashTable/IHashTable.ts +11 -0
  196. package/src/HashTable/IHashTableData.ts +5 -0
  197. package/src/HashTable/IHashTableInputs.ts +5 -0
  198. package/src/HashTable/IHashTableOptions.ts +5 -0
  199. package/src/HashTable/index.spec.ts +136 -0
  200. package/src/HashTable/index.ts +78 -0
  201. package/src/HashTableLinearProbing/HashTableLinearProbingElement.spec.ts +28 -0
  202. package/src/HashTableLinearProbing/HashTableLinearProbingElement.ts +18 -0
  203. package/src/HashTableLinearProbing/IHashTableLinearProbing.ts +11 -0
  204. package/src/HashTableLinearProbing/IHashTableLinearProbingData.ts +7 -0
  205. package/src/HashTableLinearProbing/IHashTableLinearProbingInputs.ts +5 -0
  206. package/src/HashTableLinearProbing/IHashTableLinearProbingOptions.ts +5 -0
  207. package/src/HashTableLinearProbing/index.spec.ts +266 -0
  208. package/src/HashTableLinearProbing/index.ts +128 -0
  209. package/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts +21 -0
  210. package/src/HashTableSeparateChaining/IHashTableSeparateChaining.ts +12 -0
  211. package/src/HashTableSeparateChaining/IHashTableSeparateChainingData.ts +7 -0
  212. package/src/HashTableSeparateChaining/IHashTableSeparateChainingInputs.ts +5 -0
  213. package/src/HashTableSeparateChaining/IHashTableSeparateChainingOptions.ts +5 -0
  214. package/src/HashTableSeparateChaining/index.spec.ts +173 -0
  215. package/src/HashTableSeparateChaining/index.ts +104 -0
  216. package/src/LinkedList/ILinkedList.ts +15 -0
  217. package/src/LinkedList/ILinkedListItem.ts +6 -0
  218. package/src/LinkedList/Node.ts +8 -0
  219. package/src/LinkedList/index.spec.ts +355 -0
  220. package/src/LinkedList/index.ts +185 -0
  221. package/src/List/index.ts +1 -0
  222. package/src/MaxHeap/IMaxHeap.ts +10 -0
  223. package/src/MaxHeap/IMaxHeapOptions.ts +6 -0
  224. package/src/MaxHeap/index.spec.ts +161 -0
  225. package/src/MaxHeap/index.ts +91 -0
  226. package/src/MinHeap/IMinHeap.ts +10 -0
  227. package/src/MinHeap/IMinHeapOptions.ts +6 -0
  228. package/src/MinHeap/index.spec.ts +161 -0
  229. package/src/MinHeap/index.ts +91 -0
  230. package/src/Queue/IQueue.ts +9 -0
  231. package/src/Queue/index.spec.ts +92 -0
  232. package/src/Queue/index.ts +44 -0
  233. package/src/Set/ISet.ts +17 -0
  234. package/src/Set/index.spec.ts +246 -0
  235. package/src/Set/index.ts +134 -0
  236. package/src/Stack/IStack.ts +9 -0
  237. package/src/Stack/index.spec.ts +108 -0
  238. package/src/Stack/index.ts +43 -0
  239. package/src/index.ts +17 -0
  240. package/tsconfig.json +104 -0
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var Dictionary = /** @class */ (function () {
15
+ function Dictionary(inputs) {
16
+ if (inputs === void 0) { inputs = {}; }
17
+ this._data = {};
18
+ this._data = inputs;
19
+ }
20
+ Object.defineProperty(Dictionary.prototype, "data", {
21
+ get: function () {
22
+ return __assign({}, this._data);
23
+ },
24
+ enumerable: false,
25
+ configurable: true
26
+ });
27
+ Object.defineProperty(Dictionary.prototype, "size", {
28
+ get: function () {
29
+ return Reflect.ownKeys(this.data).length;
30
+ },
31
+ enumerable: false,
32
+ configurable: true
33
+ });
34
+ Object.defineProperty(Dictionary.prototype, "isEmpty", {
35
+ get: function () {
36
+ return this.size === 0;
37
+ },
38
+ enumerable: false,
39
+ configurable: true
40
+ });
41
+ Object.defineProperty(Dictionary.prototype, "keys", {
42
+ get: function () {
43
+ return Reflect
44
+ .ownKeys(this.data)
45
+ .map(function (key) { return String(key); });
46
+ },
47
+ enumerable: false,
48
+ configurable: true
49
+ });
50
+ Object.defineProperty(Dictionary.prototype, "values", {
51
+ get: function () {
52
+ return Object.values(this.data);
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ Object.defineProperty(Dictionary.prototype, "pairs", {
58
+ get: function () {
59
+ return Object.entries(this.data);
60
+ },
61
+ enumerable: false,
62
+ configurable: true
63
+ });
64
+ Dictionary.prototype.set = function (key, value) {
65
+ Reflect.set(this._data, key, value);
66
+ return [key, value];
67
+ };
68
+ Dictionary.prototype.remove = function (key) {
69
+ if (this.hasKey(key)) {
70
+ var value = Reflect.get(this.data, key);
71
+ Reflect.deleteProperty(this._data, key);
72
+ return [key, value];
73
+ }
74
+ return null;
75
+ };
76
+ Dictionary.prototype.hasKey = function (key) {
77
+ return Reflect.has(this.data, key);
78
+ };
79
+ Dictionary.prototype.get = function (key) {
80
+ if (this.hasKey(key)) {
81
+ return Reflect.get(this.data, key);
82
+ }
83
+ return null;
84
+ };
85
+ Dictionary.prototype.clear = function () {
86
+ var dictionary = __assign({}, this.data);
87
+ this._data = {};
88
+ return dictionary;
89
+ };
90
+ Dictionary.prototype.forEach = function (func) {
91
+ for (var _i = 0, _a = this.pairs; _i < _a.length; _i++) {
92
+ var _b = _a[_i], key = _b[0], value = _b[1];
93
+ func(key, value);
94
+ }
95
+ };
96
+ Dictionary.prototype[Symbol.toPrimitive] = function (type) {
97
+ if (type === 'string') {
98
+ return "{ ".concat(this.pairs.map(function (_a) {
99
+ var key = _a[0], value = _a[1];
100
+ return "".concat(key, " => ").concat(value);
101
+ }).join(', '), " }");
102
+ }
103
+ if (type === 'number') {
104
+ return this.size;
105
+ }
106
+ return null;
107
+ };
108
+ return Dictionary;
109
+ }());
110
+ exports.default = Dictionary;
@@ -0,0 +1,16 @@
1
+ export interface IDoublyLinkedListItem<T> {
2
+ previous: T | null;
3
+ value: T;
4
+ next: T | null;
5
+ }
6
+ interface IDoublyLinkedList<T> {
7
+ get data(): IDoublyLinkedListItem<T>[];
8
+ get size(): number;
9
+ push(_element: T): T;
10
+ getFromPosition(_position: number): IDoublyLinkedListItem<T> | undefined;
11
+ positionOf(_element: T): number | undefined;
12
+ insertInPosition(_element: T, _position: number): T | undefined;
13
+ remove(_element: T): T | undefined;
14
+ removeFromPosition(_position: number): T | undefined;
15
+ }
16
+ export default IDoublyLinkedList;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export default class Node<T> {
2
+ value: T;
3
+ previous: Node<T> | null;
4
+ next: Node<T> | null;
5
+ constructor(value: T);
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Node = /** @class */ (function () {
4
+ function Node(value) {
5
+ this.previous = null;
6
+ this.next = null;
7
+ this.value = value;
8
+ }
9
+ return Node;
10
+ }());
11
+ exports.default = Node;
@@ -0,0 +1,32 @@
1
+ import IDoublyLinkedList, { IDoublyLinkedListItem } from './IDoublyLinkedList';
2
+ export default class DoublyLinkedList<T = number> implements IDoublyLinkedList<T> {
3
+ private _head;
4
+ private _tail;
5
+ private _size;
6
+ constructor(...inputs: T[]);
7
+ get data(): IDoublyLinkedListItem<T>[];
8
+ get size(): number;
9
+ /**
10
+ * Complexity: O(1)
11
+ */
12
+ push(element: T): T;
13
+ /**
14
+ * Complexity: O(n/2)
15
+ */
16
+ getFromPosition(position: number): IDoublyLinkedListItem<T> | undefined;
17
+ positionOf(element: T): number | undefined;
18
+ /**
19
+ * Complexity: O(n)
20
+ */
21
+ insertInPosition(element: T, position: number): T | undefined;
22
+ /**
23
+ * Complexity: O(n)
24
+ */
25
+ remove(element: T): T | undefined;
26
+ /**
27
+ * Complexity: O(n)
28
+ */
29
+ removeFromPosition(position: number): T | undefined;
30
+ private _findFasterWayToPosition;
31
+ private [Symbol.toPrimitive];
32
+ }
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var Node_1 = __importDefault(require("./Node"));
7
+ var DoublyLinkedList = /** @class */ (function () {
8
+ function DoublyLinkedList() {
9
+ var inputs = [];
10
+ for (var _i = 0; _i < arguments.length; _i++) {
11
+ inputs[_i] = arguments[_i];
12
+ }
13
+ this._head = null;
14
+ this._tail = null;
15
+ this._size = 0;
16
+ if (inputs.length) {
17
+ var nodes = inputs.map(function (input) { return new Node_1.default(input); });
18
+ for (var i = 0; i < inputs.length; i++) {
19
+ nodes[i].previous = nodes[i - 1] || null;
20
+ nodes[i].next = nodes[i + 1] || null;
21
+ }
22
+ this._head = nodes[0];
23
+ this._tail = nodes[nodes.length - 1];
24
+ this._size = inputs.length;
25
+ }
26
+ }
27
+ Object.defineProperty(DoublyLinkedList.prototype, "data", {
28
+ get: function () {
29
+ var _a, _b;
30
+ var current = this._head;
31
+ var data = [];
32
+ while (current) {
33
+ data.push({
34
+ previous: ((_a = current.previous) === null || _a === void 0 ? void 0 : _a.value) || null,
35
+ value: current.value,
36
+ next: ((_b = current.next) === null || _b === void 0 ? void 0 : _b.value) || null,
37
+ });
38
+ current = current.next;
39
+ }
40
+ return data;
41
+ },
42
+ enumerable: false,
43
+ configurable: true
44
+ });
45
+ Object.defineProperty(DoublyLinkedList.prototype, "size", {
46
+ get: function () {
47
+ return this._size;
48
+ },
49
+ enumerable: false,
50
+ configurable: true
51
+ });
52
+ /**
53
+ * Complexity: O(1)
54
+ */
55
+ DoublyLinkedList.prototype.push = function (element) {
56
+ var node = new Node_1.default(element);
57
+ if (this._tail) {
58
+ this._tail.next = node;
59
+ node.previous = this._tail;
60
+ }
61
+ else {
62
+ this._head = node;
63
+ this._tail = node;
64
+ }
65
+ this._size += 1;
66
+ return element;
67
+ };
68
+ /**
69
+ * Complexity: O(n/2)
70
+ */
71
+ DoublyLinkedList.prototype.getFromPosition = function (position) {
72
+ var _a, _b;
73
+ if (position < 0 || position >= this._size) {
74
+ return undefined;
75
+ }
76
+ var distanceToTheHead = position;
77
+ var distanceToTheTail = this.size - position - 1;
78
+ var current;
79
+ if (distanceToTheTail > distanceToTheHead) {
80
+ current = this._head;
81
+ for (var i = 0; i < position; i++) {
82
+ current = (current === null || current === void 0 ? void 0 : current.next) || null;
83
+ }
84
+ }
85
+ else {
86
+ current = this._tail;
87
+ for (var i = this.size - 1; i > position; i--) {
88
+ current = (current === null || current === void 0 ? void 0 : current.previous) || null;
89
+ }
90
+ }
91
+ if (current === null || current === void 0 ? void 0 : current.value) {
92
+ return {
93
+ previous: ((_a = current === null || current === void 0 ? void 0 : current.previous) === null || _a === void 0 ? void 0 : _a.value) || null,
94
+ value: current === null || current === void 0 ? void 0 : current.value,
95
+ next: ((_b = current === null || current === void 0 ? void 0 : current.next) === null || _b === void 0 ? void 0 : _b.value) || null,
96
+ };
97
+ }
98
+ };
99
+ DoublyLinkedList.prototype.positionOf = function (element) {
100
+ var current = this._head;
101
+ var position = 0;
102
+ while (current && current.value !== element) {
103
+ current = current.next;
104
+ position += 1;
105
+ }
106
+ return position === this.size ? undefined : position;
107
+ };
108
+ /**
109
+ * Complexity: O(n)
110
+ */
111
+ DoublyLinkedList.prototype.insertInPosition = function (element, position) {
112
+ var _a;
113
+ if (position < 0 || position > this.size) {
114
+ return undefined;
115
+ }
116
+ var node = new Node_1.default(element);
117
+ if (position === 0 && this._head) {
118
+ node.next = this._head;
119
+ this._head.previous = node;
120
+ this._head = node;
121
+ this._size += 1;
122
+ return element;
123
+ }
124
+ if (position === this.size - 1 && this._tail && this._tail.previous) {
125
+ this._tail.previous.next = node;
126
+ node.previous = ((_a = this._tail) === null || _a === void 0 ? void 0 : _a.previous) || null;
127
+ node.next = this._tail;
128
+ this._tail.previous = node;
129
+ this._size += 1;
130
+ return element;
131
+ }
132
+ if (position === this.size && this._tail) {
133
+ node.previous = this._tail;
134
+ this._tail.next = node;
135
+ this._tail = node;
136
+ this._size += 1;
137
+ return element;
138
+ }
139
+ var way = this._findFasterWayToPosition(position);
140
+ var current;
141
+ if (way === 'ASC') {
142
+ current = this._head;
143
+ for (var i = 0; i < position; i++) {
144
+ current = (current === null || current === void 0 ? void 0 : current.next) || null;
145
+ }
146
+ }
147
+ else {
148
+ current = this._tail;
149
+ for (var i = this.size - 1; i > position; i--) {
150
+ current = (current === null || current === void 0 ? void 0 : current.previous) || null;
151
+ }
152
+ }
153
+ if (current && current.previous) {
154
+ current.previous.next = node;
155
+ node.previous = current.previous;
156
+ node.next = current;
157
+ current.previous = node;
158
+ }
159
+ this._size += 1;
160
+ return element;
161
+ };
162
+ /**
163
+ * Complexity: O(n)
164
+ */
165
+ DoublyLinkedList.prototype.remove = function (element) {
166
+ var current = this._head;
167
+ while (current && current.value !== element) {
168
+ current = current.next;
169
+ }
170
+ if (current) {
171
+ if (current.previous) {
172
+ current.previous.next = current.next;
173
+ }
174
+ if (current.next) {
175
+ current.next.previous = current.previous;
176
+ }
177
+ if (current === this._head) {
178
+ this._head = current.next;
179
+ }
180
+ if (current === this._tail) {
181
+ this._tail = current.previous;
182
+ }
183
+ this._size -= 1;
184
+ return current.value;
185
+ }
186
+ return undefined;
187
+ };
188
+ /**
189
+ * Complexity: O(n)
190
+ */
191
+ DoublyLinkedList.prototype.removeFromPosition = function (position) {
192
+ var item = this.getFromPosition(position);
193
+ if (item) {
194
+ this.remove(item.value);
195
+ return item.value;
196
+ }
197
+ return undefined;
198
+ };
199
+ DoublyLinkedList.prototype._findFasterWayToPosition = function (position) {
200
+ var distanceToTheHead = position;
201
+ var distanceToTheTail = this.size - position - 1;
202
+ if (distanceToTheTail > distanceToTheHead) {
203
+ return 'ASC';
204
+ }
205
+ return 'DESC';
206
+ };
207
+ DoublyLinkedList.prototype[Symbol.toPrimitive] = function (type) {
208
+ if (type === 'string') {
209
+ return "[Head] ".concat(this.data.map(function (_a) {
210
+ var value = _a.value;
211
+ return value;
212
+ }).join(' <=> '), " [Tail]");
213
+ }
214
+ if (type === 'number') {
215
+ return this.size;
216
+ }
217
+ return null;
218
+ };
219
+ return DoublyLinkedList;
220
+ }());
221
+ exports.default = DoublyLinkedList;
@@ -0,0 +1,3 @@
1
+ export default class GraphNodeNotFoundError extends Error {
2
+ constructor(node: string);
3
+ }
@@ -0,0 +1,27 @@
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
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ var GraphNodeNotFoundError = /** @class */ (function (_super) {
19
+ __extends(GraphNodeNotFoundError, _super);
20
+ function GraphNodeNotFoundError(node) {
21
+ var _this = _super.call(this, "Node ".concat(node, " not found")) || this;
22
+ _this.name = 'GraphNodeNotFoundError';
23
+ return _this;
24
+ }
25
+ return GraphNodeNotFoundError;
26
+ }(Error));
27
+ exports.default = GraphNodeNotFoundError;
@@ -0,0 +1,6 @@
1
+ declare enum GraphSearchNodeStates {
2
+ UNEXPLORED = 0,
3
+ DISCOVERED = 1,
4
+ EXPLORED = 2
5
+ }
6
+ export default GraphSearchNodeStates;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable no-unused-vars */
4
+ var GraphSearchNodeStates;
5
+ (function (GraphSearchNodeStates) {
6
+ GraphSearchNodeStates[GraphSearchNodeStates["UNEXPLORED"] = 0] = "UNEXPLORED";
7
+ GraphSearchNodeStates[GraphSearchNodeStates["DISCOVERED"] = 1] = "DISCOVERED";
8
+ GraphSearchNodeStates[GraphSearchNodeStates["EXPLORED"] = 2] = "EXPLORED";
9
+ })(GraphSearchNodeStates || (GraphSearchNodeStates = {}));
10
+ exports.default = GraphSearchNodeStates;
@@ -0,0 +1,16 @@
1
+ interface IGraph {
2
+ get isDirected(): boolean;
3
+ get data(): {
4
+ [key: string]: string[];
5
+ };
6
+ get size(): number;
7
+ get nodes(): string[];
8
+ get edges(): [string, string][];
9
+ insert(_node: string): string | null;
10
+ connect(_node1: string, _node2: string): [string, string];
11
+ breadthFirstSearch(_startNode: string, _callback: (_node: string) => void): void;
12
+ getDistancesFrom(_node: string): {
13
+ [key: string]: number;
14
+ };
15
+ }
16
+ export default IGraph;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ interface IGraphOptions {
2
+ inputs?: {
3
+ [key: string]: string[];
4
+ };
5
+ isDirected?: boolean;
6
+ }
7
+ export default IGraphOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ import IGraph from './IGraph';
2
+ import IGraphOptions from './IGraphOptions';
3
+ export default class Graph implements IGraph {
4
+ private _isDirected;
5
+ private _data;
6
+ constructor({ inputs, isDirected }?: IGraphOptions);
7
+ get isDirected(): boolean;
8
+ get data(): {
9
+ [key: string]: string[];
10
+ };
11
+ get size(): number;
12
+ get nodes(): string[];
13
+ get edges(): [string, string][];
14
+ insert(node: string): string | null;
15
+ connect(node1: string, node2: string): [string, string];
16
+ breadthFirstSearch(startNode: string, callback: (_node: string) => void): void;
17
+ getDistancesFrom(node: string): {
18
+ [key: string]: number;
19
+ };
20
+ }