@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,187 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ var GraphNodeNotFoundError_1 = __importDefault(require("./GraphNodeNotFoundError"));
27
+ var GraphSearchNodeStates_1 = __importDefault(require("./GraphSearchNodeStates"));
28
+ var Dictionary_1 = __importDefault(require("../Dictionary"));
29
+ var Queue_1 = __importDefault(require("../Queue"));
30
+ var Set_1 = __importDefault(require("../Set"));
31
+ var Graph = /** @class */ (function () {
32
+ function Graph(_a) {
33
+ var _b = _a === void 0 ? { inputs: {}, isDirected: false } : _a, _c = _b.inputs, inputs = _c === void 0 ? {} : _c, _d = _b.isDirected, isDirected = _d === void 0 ? false : _d;
34
+ this._isDirected = isDirected;
35
+ this._data = new Dictionary_1.default();
36
+ var nodes = Object.keys(inputs);
37
+ for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
38
+ var node = nodes_1[_i];
39
+ this.insert(node);
40
+ }
41
+ for (var _e = 0, nodes_2 = nodes; _e < nodes_2.length; _e++) {
42
+ var node = nodes_2[_e];
43
+ for (var _f = 0, _g = inputs[node]; _f < _g.length; _f++) {
44
+ var value = _g[_f];
45
+ this.connect(node, value);
46
+ }
47
+ }
48
+ }
49
+ Object.defineProperty(Graph.prototype, "isDirected", {
50
+ get: function () {
51
+ return this._isDirected;
52
+ },
53
+ enumerable: false,
54
+ configurable: true
55
+ });
56
+ Object.defineProperty(Graph.prototype, "data", {
57
+ get: function () {
58
+ return Object.entries(this._data.data)
59
+ .reduce(function (accumulator, _a) {
60
+ var _b;
61
+ var key = _a[0], value = _a[1];
62
+ return (__assign(__assign({}, accumulator), (_b = {}, _b[key] = value.data, _b)));
63
+ }, {});
64
+ },
65
+ enumerable: false,
66
+ configurable: true
67
+ });
68
+ Object.defineProperty(Graph.prototype, "size", {
69
+ get: function () {
70
+ return this._data.size;
71
+ },
72
+ enumerable: false,
73
+ configurable: true
74
+ });
75
+ Object.defineProperty(Graph.prototype, "nodes", {
76
+ get: function () {
77
+ return __spreadArray([], this._data.keys, true);
78
+ },
79
+ enumerable: false,
80
+ configurable: true
81
+ });
82
+ Object.defineProperty(Graph.prototype, "edges", {
83
+ get: function () {
84
+ if (this.isDirected) {
85
+ return Object.entries(this.data)
86
+ .flatMap(function (_a) {
87
+ var node = _a[0], links = _a[1];
88
+ return links.map(function (link) { return [node, link]; });
89
+ });
90
+ }
91
+ return Object.entries(this.data)
92
+ .reduce(function (accumulator, _a) {
93
+ var node = _a[0], links = _a[1];
94
+ var edges = links
95
+ .map(function (link) { return [node, link]; })
96
+ .filter(function (edge) { return !accumulator.find(function (item) { return item.includes(edge[0]) && item.includes(edge[1]); }); });
97
+ return __spreadArray(__spreadArray([], accumulator, true), edges, true);
98
+ }, []);
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ Graph.prototype.insert = function (node) {
104
+ if (this._data.hasKey(node)) {
105
+ return null;
106
+ }
107
+ this._data.set(node, new Set_1.default());
108
+ return node;
109
+ };
110
+ Graph.prototype.connect = function (node1, node2) {
111
+ var _a, _b;
112
+ if (!this._data.hasKey(node1)) {
113
+ throw new GraphNodeNotFoundError_1.default(node1);
114
+ }
115
+ if (!this._data.hasKey(node2)) {
116
+ throw new GraphNodeNotFoundError_1.default(node2);
117
+ }
118
+ (_a = this._data.get(node1)) === null || _a === void 0 ? void 0 : _a.add(node2);
119
+ if (!this._isDirected) {
120
+ (_b = this._data.get(node2)) === null || _b === void 0 ? void 0 : _b.add(node1);
121
+ }
122
+ return [node1, node2];
123
+ };
124
+ Graph.prototype.breadthFirstSearch = function (startNode, callback) {
125
+ var _a;
126
+ if (!this._data.hasKey(startNode)) {
127
+ throw new GraphNodeNotFoundError_1.default(startNode);
128
+ }
129
+ var nodes = this.nodes;
130
+ var states = nodes.reduce(function (accumulator, node) {
131
+ var _a;
132
+ return (__assign(__assign({}, accumulator), (_a = {}, _a[node] = GraphSearchNodeStates_1.default.UNEXPLORED, _a)));
133
+ }, {});
134
+ var queue = new Queue_1.default();
135
+ queue.enqueue(startNode);
136
+ while (!queue.isEmpty) {
137
+ var current = queue.dequeue() || '';
138
+ if (current) {
139
+ states[current] = GraphSearchNodeStates_1.default.DISCOVERED;
140
+ var neighbors = ((_a = this._data.get(current)) === null || _a === void 0 ? void 0 : _a.data) || [];
141
+ var unexploredNeighbors = neighbors.filter(function (neighbor) { return states[neighbor] === GraphSearchNodeStates_1.default.UNEXPLORED; });
142
+ for (var _i = 0, unexploredNeighbors_1 = unexploredNeighbors; _i < unexploredNeighbors_1.length; _i++) {
143
+ var neighbor = unexploredNeighbors_1[_i];
144
+ states[neighbor] = GraphSearchNodeStates_1.default.DISCOVERED;
145
+ queue.enqueue(neighbor);
146
+ }
147
+ }
148
+ states[current] = GraphSearchNodeStates_1.default.EXPLORED;
149
+ callback(current);
150
+ }
151
+ };
152
+ Graph.prototype.getDistancesFrom = function (node) {
153
+ var _a;
154
+ if (!this._data.hasKey(node)) {
155
+ throw new GraphNodeNotFoundError_1.default(node);
156
+ }
157
+ var nodes = this.nodes;
158
+ var states = nodes.reduce(function (accumulator, node) {
159
+ var _a;
160
+ return (__assign(__assign({}, accumulator), (_a = {}, _a[node] = GraphSearchNodeStates_1.default.UNEXPLORED, _a)));
161
+ }, {});
162
+ var distances = nodes.reduce(function (accumulator, node) {
163
+ var _a;
164
+ return (__assign(__assign({}, accumulator), (_a = {}, _a[node] = 0, _a)));
165
+ }, {});
166
+ var queue = new Queue_1.default();
167
+ queue.enqueue(node);
168
+ while (!queue.isEmpty) {
169
+ var current = queue.dequeue() || '';
170
+ if (current) {
171
+ states[current] = GraphSearchNodeStates_1.default.DISCOVERED;
172
+ var neighbors = ((_a = this._data.get(current)) === null || _a === void 0 ? void 0 : _a.data) || [];
173
+ var unexploredNeighbors = neighbors.filter(function (neighbor) { return states[neighbor] === GraphSearchNodeStates_1.default.UNEXPLORED; });
174
+ for (var _i = 0, unexploredNeighbors_2 = unexploredNeighbors; _i < unexploredNeighbors_2.length; _i++) {
175
+ var neighbor = unexploredNeighbors_2[_i];
176
+ states[neighbor] = GraphSearchNodeStates_1.default.DISCOVERED;
177
+ distances[neighbor] = distances[current] + 1;
178
+ queue.enqueue(neighbor);
179
+ }
180
+ }
181
+ states[current] = GraphSearchNodeStates_1.default.EXPLORED;
182
+ }
183
+ return distances;
184
+ };
185
+ return Graph;
186
+ }());
187
+ exports.default = Graph;
@@ -0,0 +1,9 @@
1
+ import IHashTableData from './IHashTableData';
2
+ interface IHashTable<T> {
3
+ get data(): IHashTableData<T>;
4
+ get size(): number;
5
+ put(_key: string, _value: T): T;
6
+ get(_key: string): T | null;
7
+ remove(_key: string): T | null;
8
+ }
9
+ export default IHashTable;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableData<T> {
2
+ [key: number]: T;
3
+ }
4
+ export default IHashTableData;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableInputs<T> {
2
+ [key: string]: T;
3
+ }
4
+ export default IHashTableInputs;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableOptions {
2
+ maxSize?: number;
3
+ }
4
+ export default IHashTableOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import IHashTable from './IHashTable';
2
+ import IHashTableData from './IHashTableData';
3
+ import IHashTableInputs from './IHashTableInputs';
4
+ import IHashTableOptions from './IHashTableOptions';
5
+ export default class HashTable<T = number> implements IHashTable<T> {
6
+ private _maxSize;
7
+ private _data;
8
+ constructor(inputs?: IHashTableInputs<T>, { maxSize }?: IHashTableOptions);
9
+ get data(): IHashTableData<T>;
10
+ get size(): number;
11
+ put(key: string, value: T): T;
12
+ get(key: string): T | null;
13
+ remove(key: string): T | null;
14
+ private _hashCode;
15
+ private [Symbol.toPrimitive];
16
+ }
@@ -0,0 +1,83 @@
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 HashTable = /** @class */ (function () {
15
+ function HashTable(inputs, _a) {
16
+ if (inputs === void 0) { inputs = {}; }
17
+ var _b = _a === void 0 ? { maxSize: 100 } : _a, _c = _b.maxSize, maxSize = _c === void 0 ? 100 : _c;
18
+ this._maxSize = maxSize;
19
+ this._data = new Array(this._maxSize);
20
+ for (var _i = 0, _d = Object.entries(inputs); _i < _d.length; _i++) {
21
+ var _e = _d[_i], key = _e[0], value = _e[1];
22
+ this.put(key, value);
23
+ }
24
+ }
25
+ Object.defineProperty(HashTable.prototype, "data", {
26
+ get: function () {
27
+ return this._data
28
+ .map(function (value, index) { return ({ index: index, value: value }); })
29
+ .reduce(function (accumulator, current) {
30
+ var _a;
31
+ return (__assign(__assign({}, accumulator), (_a = {}, _a[current.index] = current.value, _a)));
32
+ }, {});
33
+ },
34
+ enumerable: false,
35
+ configurable: true
36
+ });
37
+ Object.defineProperty(HashTable.prototype, "size", {
38
+ get: function () {
39
+ return Reflect.ownKeys(this.data).length;
40
+ },
41
+ enumerable: false,
42
+ configurable: true
43
+ });
44
+ HashTable.prototype.put = function (key, value) {
45
+ var position = this._hashCode(key);
46
+ this._data[position] = value;
47
+ return value;
48
+ };
49
+ HashTable.prototype.get = function (key) {
50
+ var position = this._hashCode(key);
51
+ return this.data[position] || null;
52
+ };
53
+ HashTable.prototype.remove = function (key) {
54
+ var value = this.get(key);
55
+ if (value) {
56
+ var position = this._hashCode(key);
57
+ Reflect.deleteProperty(this._data, position);
58
+ return value;
59
+ }
60
+ return null;
61
+ };
62
+ HashTable.prototype._hashCode = function (key) {
63
+ var code = key
64
+ .split('')
65
+ .map(function (character) { return character.charCodeAt(0); })
66
+ .reduce(function (previous, current) { return previous + current; }, 0);
67
+ return code % this._maxSize;
68
+ };
69
+ HashTable.prototype[Symbol.toPrimitive] = function (type) {
70
+ if (type === 'string') {
71
+ return "[ ".concat(Object.entries(this.data).map(function (_a) {
72
+ var key = _a[0], value = _a[1];
73
+ return "".concat(key, " => ").concat(value);
74
+ }).join(', '), " ]");
75
+ }
76
+ if (type === 'number') {
77
+ return this.size;
78
+ }
79
+ return null;
80
+ };
81
+ return HashTable;
82
+ }());
83
+ exports.default = HashTable;
@@ -0,0 +1,6 @@
1
+ export default class HashTableLinearProbingElement<T> {
2
+ key: string;
3
+ value: T;
4
+ constructor(key: string, value: T);
5
+ [Symbol.toPrimitive](type: 'string' | 'number'): string | number | null;
6
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /* eslint-disable no-unused-vars */
3
+ /* eslint-disable no-useless-constructor */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ var HashTableLinearProbingElement = /** @class */ (function () {
6
+ function HashTableLinearProbingElement(key, value) {
7
+ this.key = key;
8
+ this.value = value;
9
+ }
10
+ HashTableLinearProbingElement.prototype[Symbol.toPrimitive] = function (type) {
11
+ var options = {
12
+ string: "{ ".concat(this.key, " => ").concat(this.value, " }"),
13
+ number: 2,
14
+ };
15
+ return options[type] || null;
16
+ };
17
+ return HashTableLinearProbingElement;
18
+ }());
19
+ exports.default = HashTableLinearProbingElement;
@@ -0,0 +1,9 @@
1
+ import IHashTableLinearProbingData from './IHashTableLinearProbingData';
2
+ interface IHashTableLinearProbing<T> {
3
+ get data(): IHashTableLinearProbingData<T>;
4
+ get size(): number;
5
+ put(_key: string, _value: T): T | null;
6
+ get(_key: string): T | null;
7
+ remove(_key: string): T | null;
8
+ }
9
+ export default IHashTableLinearProbing;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import HashTableLinearProbingElement from './HashTableLinearProbingElement';
2
+ interface IHashTableLinearProbingData<T> {
3
+ [index: number]: HashTableLinearProbingElement<T>;
4
+ }
5
+ export default IHashTableLinearProbingData;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableLinearProbingInputs<T> {
2
+ [key: string]: T;
3
+ }
4
+ export default IHashTableLinearProbingInputs;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableLinearProbingOptions {
2
+ maxSize: number;
3
+ }
4
+ export default IHashTableLinearProbingOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ import HashTableLinearProbingElement from './HashTableLinearProbingElement';
2
+ import IHashTableLinearProbing from './IHashTableLinearProbing';
3
+ import IHashTableLinearProbingInputs from './IHashTableLinearProbingInputs';
4
+ import IHashTableLinearProbingOptions from './IHashTableLinearProbingOptions';
5
+ export default class HashTableLinearProbing<T = number> implements IHashTableLinearProbing<T> {
6
+ private _maxSize;
7
+ private _data;
8
+ constructor(inputs?: IHashTableLinearProbingInputs<T>, { maxSize }?: IHashTableLinearProbingOptions);
9
+ get data(): {
10
+ [index: number]: HashTableLinearProbingElement<T>;
11
+ };
12
+ get size(): number;
13
+ put(key: string, value: T): T | null;
14
+ get(key: string): T | null;
15
+ remove(key: string): T | null;
16
+ private _hashCode;
17
+ private _nextPositionOf;
18
+ private _previousPositionOf;
19
+ private [Symbol.toPrimitive];
20
+ }
@@ -0,0 +1,120 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var HashTableLinearProbingElement_1 = __importDefault(require("./HashTableLinearProbingElement"));
18
+ var HashTableLinearProbing = /** @class */ (function () {
19
+ function HashTableLinearProbing(inputs, _a) {
20
+ if (inputs === void 0) { inputs = {}; }
21
+ var _b = _a === void 0 ? { maxSize: 100 } : _a, _c = _b.maxSize, maxSize = _c === void 0 ? 100 : _c;
22
+ this._maxSize = 0;
23
+ this._data = [];
24
+ this._maxSize = maxSize;
25
+ for (var _i = 0, _d = Object.entries(inputs); _i < _d.length; _i++) {
26
+ var _e = _d[_i], key = _e[0], value = _e[1];
27
+ this.put(key, value);
28
+ }
29
+ }
30
+ Object.defineProperty(HashTableLinearProbing.prototype, "data", {
31
+ get: function () {
32
+ return this._data
33
+ .map(function (value, index) { return ({ index: index, value: value }); })
34
+ .reduce(function (accumulator, current) {
35
+ var _a;
36
+ return (__assign(__assign({}, accumulator), (_a = {}, _a[current.index] = current.value, _a)));
37
+ }, {});
38
+ },
39
+ enumerable: false,
40
+ configurable: true
41
+ });
42
+ Object.defineProperty(HashTableLinearProbing.prototype, "size", {
43
+ get: function () {
44
+ return Reflect.ownKeys(this.data).length;
45
+ },
46
+ enumerable: false,
47
+ configurable: true
48
+ });
49
+ HashTableLinearProbing.prototype.put = function (key, value) {
50
+ if (this.size === this._maxSize) {
51
+ return null;
52
+ }
53
+ var element = new HashTableLinearProbingElement_1.default(key, value);
54
+ var position = this._hashCode(key);
55
+ if (this._data[position]) {
56
+ do {
57
+ position = this._nextPositionOf(position);
58
+ } while (this._data[position]);
59
+ }
60
+ this._data[position] = element;
61
+ return value;
62
+ };
63
+ HashTableLinearProbing.prototype.get = function (key) {
64
+ var _a;
65
+ var position = this._hashCode(key);
66
+ var i = position;
67
+ do {
68
+ if (((_a = this._data[i]) === null || _a === void 0 ? void 0 : _a.key) === key) {
69
+ return this._data[i].value;
70
+ }
71
+ i = this._nextPositionOf(i);
72
+ } while (this._data[i] && i !== position);
73
+ return null;
74
+ };
75
+ HashTableLinearProbing.prototype.remove = function (key) {
76
+ if (this.get(key)) {
77
+ var position = this._hashCode(key);
78
+ while (this._data[position].key !== key) {
79
+ position = this._nextPositionOf(position);
80
+ }
81
+ var value = this._data[position].value;
82
+ Reflect.deleteProperty(this._data, position);
83
+ var i = void 0;
84
+ for (i = position; this._data[this._nextPositionOf(i)]
85
+ && this._hashCode(this._data[this._nextPositionOf(i)].key) === this._hashCode(key)
86
+ && this._nextPositionOf(i) !== position; i = this._nextPositionOf(i)) {
87
+ this._data[i] = this._data[this._nextPositionOf(i)];
88
+ }
89
+ if (i !== position) {
90
+ Reflect.deleteProperty(this._data, i);
91
+ }
92
+ return value;
93
+ }
94
+ return null;
95
+ };
96
+ HashTableLinearProbing.prototype._hashCode = function (key) {
97
+ var code = key
98
+ .split('')
99
+ .map(function (character) { return character.charCodeAt(0); })
100
+ .reduce(function (previous, current) { return previous + current; }, 0);
101
+ return code % this._maxSize;
102
+ };
103
+ HashTableLinearProbing.prototype._nextPositionOf = function (position) {
104
+ return (position + 1) % this._maxSize;
105
+ };
106
+ HashTableLinearProbing.prototype._previousPositionOf = function (position) {
107
+ return (position + this.size - 1) % this._maxSize;
108
+ };
109
+ HashTableLinearProbing.prototype[Symbol.toPrimitive] = function (type) {
110
+ if (type === 'string') {
111
+ return "[ ".concat(Object.values(this.data).join(', '), " ]");
112
+ }
113
+ if (type === 'number') {
114
+ return this.size;
115
+ }
116
+ return null;
117
+ };
118
+ return HashTableLinearProbing;
119
+ }());
120
+ exports.default = HashTableLinearProbing;
@@ -0,0 +1,6 @@
1
+ export default class HashTableSeparateChainingElement<T> {
2
+ key: string;
3
+ value: T;
4
+ constructor(key: string, value: T);
5
+ private [Symbol.toPrimitive];
6
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /* eslint-disable no-useless-constructor */
3
+ /* eslint-disable no-unused-vars */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ var HashTableSeparateChainingElement = /** @class */ (function () {
6
+ function HashTableSeparateChainingElement(key, value) {
7
+ this.key = key;
8
+ this.value = value;
9
+ }
10
+ HashTableSeparateChainingElement.prototype[Symbol.toPrimitive] = function (type) {
11
+ if (type === 'string') {
12
+ return "{ ".concat(this.key, " => ").concat(this.value, "}");
13
+ }
14
+ if (type === 'number') {
15
+ return 2;
16
+ }
17
+ return null;
18
+ };
19
+ return HashTableSeparateChainingElement;
20
+ }());
21
+ exports.default = HashTableSeparateChainingElement;
@@ -0,0 +1,10 @@
1
+ import HashTableSeparateChainingElement from './HashTableSeparateChainingElement';
2
+ import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
3
+ interface IHashTableSeparateChaining<T> {
4
+ get data(): IHashTableSeparateChainingData<T>;
5
+ get size(): number;
6
+ put(_key: string, _value: T): T;
7
+ get(_key: string): HashTableSeparateChainingElement<T> | null;
8
+ remove(_key: string): HashTableSeparateChainingElement<T> | null;
9
+ }
10
+ export default IHashTableSeparateChaining;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import LinkedList from '../LinkedList';
2
+ interface IHashTableSeparateChainingData<T> {
3
+ [key: number]: LinkedList<T>;
4
+ }
5
+ export default IHashTableSeparateChainingData;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableSeparateChainingInputs<T> {
2
+ [key: string]: T;
3
+ }
4
+ export default IHashTableSeparateChainingInputs;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ interface IHashTableSeparateChainingOptions {
2
+ maxSize: number;
3
+ }
4
+ export default IHashTableSeparateChainingOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import HashTableSeparateChainingElement from './HashTableSeparateChainingElement';
2
+ import IHashTableSeparateChaining from './IHashTableSeparateChaining';
3
+ import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
4
+ import IHashTableSeparateChainingInputs from './IHashTableSeparateChainingInputs';
5
+ export default class HashTableSeparateChaining<T = number> implements IHashTableSeparateChaining<T> {
6
+ private _maxSize;
7
+ private _data;
8
+ constructor(inputs?: IHashTableSeparateChainingInputs<T>, { maxSize }?: {
9
+ maxSize: number;
10
+ });
11
+ get data(): IHashTableSeparateChainingData<T>;
12
+ get size(): number;
13
+ put(key: string, value: T): T;
14
+ get(key: string): HashTableSeparateChainingElement<T> | null;
15
+ remove(key: string): HashTableSeparateChainingElement<T> | null;
16
+ private _getLinkedListByKey;
17
+ private _hashCode;
18
+ private [Symbol.toPrimitive];
19
+ }