@gabrielrufino/cube 1.0.1 → 1.0.3

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 (123) hide show
  1. package/package.json +1 -1
  2. package/.github/workflows/cd.yml +0 -26
  3. package/.github/workflows/ci.yml +0 -23
  4. package/coverage/clover.xml +0 -706
  5. package/coverage/coverage-final.json +0 -19
  6. package/coverage/lcov-report/base.css +0 -224
  7. package/coverage/lcov-report/block-navigation.js +0 -87
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +0 -327
  10. package/coverage/lcov-report/prettify.css +0 -1
  11. package/coverage/lcov-report/prettify.js +0 -2
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +0 -196
  14. package/coverage/lcov-report/src/Algorithms/index.html +0 -117
  15. package/coverage/lcov-report/src/Algorithms/index.ts.html +0 -149
  16. package/coverage/lcov-report/src/Array/index.html +0 -117
  17. package/coverage/lcov-report/src/Array/index.ts.html +0 -290
  18. package/coverage/lcov-report/src/DataStructure/index.html +0 -117
  19. package/coverage/lcov-report/src/DataStructure/index.ts.html +0 -131
  20. package/coverage/lcov-report/src/Deck/index.html +0 -117
  21. package/coverage/lcov-report/src/Deck/index.ts.html +0 -239
  22. package/coverage/lcov-report/src/Dictionary/index.html +0 -117
  23. package/coverage/lcov-report/src/Dictionary/index.ts.html +0 -350
  24. package/coverage/lcov-report/src/DoublyLinkedList/Node.ts.html +0 -113
  25. package/coverage/lcov-report/src/DoublyLinkedList/index.html +0 -132
  26. package/coverage/lcov-report/src/DoublyLinkedList/index.ts.html +0 -836
  27. package/coverage/lcov-report/src/HashTable/index.html +0 -117
  28. package/coverage/lcov-report/src/HashTable/index.ts.html +0 -320
  29. package/coverage/lcov-report/src/HashTableLinearProbing/index.html +0 -117
  30. package/coverage/lcov-report/src/HashTableLinearProbing/index.ts.html +0 -95
  31. package/coverage/lcov-report/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts.html +0 -149
  32. package/coverage/lcov-report/src/HashTableSeparateChaining/index.html +0 -132
  33. package/coverage/lcov-report/src/HashTableSeparateChaining/index.ts.html +0 -398
  34. package/coverage/lcov-report/src/LinkedList/Node.ts.html +0 -110
  35. package/coverage/lcov-report/src/LinkedList/index.html +0 -132
  36. package/coverage/lcov-report/src/LinkedList/index.ts.html +0 -641
  37. package/coverage/lcov-report/src/List/index.html +0 -117
  38. package/coverage/lcov-report/src/List/index.ts.html +0 -89
  39. package/coverage/lcov-report/src/Queue/index.html +0 -117
  40. package/coverage/lcov-report/src/Queue/index.ts.html +0 -218
  41. package/coverage/lcov-report/src/Set/index.html +0 -117
  42. package/coverage/lcov-report/src/Set/index.ts.html +0 -488
  43. package/coverage/lcov-report/src/Stack/index.html +0 -117
  44. package/coverage/lcov-report/src/Stack/index.ts.html +0 -215
  45. package/coverage/lcov-report/src/index.html +0 -117
  46. package/coverage/lcov-report/src/index.ts.html +0 -125
  47. package/coverage/lcov.info +0 -1346
  48. package/src/Algorithms/index.spec.ts +0 -15
  49. package/src/Algorithms/index.ts +0 -21
  50. package/src/Array/IArray.ts +0 -10
  51. package/src/Array/index.spec.ts +0 -151
  52. package/src/Array/index.ts +0 -68
  53. package/src/BinarySearchTree/BinarySearchTreeNode.spec.ts +0 -29
  54. package/src/BinarySearchTree/BinarySearchTreeNode.ts +0 -23
  55. package/src/BinarySearchTree/IBinarySearchNodeOptions.ts +0 -6
  56. package/src/BinarySearchTree/IBinarySearchTree.ts +0 -16
  57. package/src/BinarySearchTree/IBinarySearchTreeData.ts +0 -9
  58. package/src/BinarySearchTree/index.spec.ts +0 -486
  59. package/src/BinarySearchTree/index.ts +0 -198
  60. package/src/DataStructure/index.spec.ts +0 -25
  61. package/src/DataStructure/index.ts +0 -15
  62. package/src/Deck/IDeck.ts +0 -10
  63. package/src/Deck/index.spec.ts +0 -131
  64. package/src/Deck/index.ts +0 -51
  65. package/src/Dictionary/IDictionary.ts +0 -18
  66. package/src/Dictionary/IDictionaryData.ts +0 -5
  67. package/src/Dictionary/index.spec.ts +0 -310
  68. package/src/Dictionary/index.ts +0 -88
  69. package/src/DoublyLinkedList/IDoublyLinkedList.ts +0 -18
  70. package/src/DoublyLinkedList/Node.ts +0 -9
  71. package/src/DoublyLinkedList/index.spec.ts +0 -478
  72. package/src/DoublyLinkedList/index.ts +0 -250
  73. package/src/Graph/GraphNodeNotFoundError.ts +0 -7
  74. package/src/Graph/GraphSearchNodeStates.ts +0 -8
  75. package/src/Graph/IGraph.ts +0 -15
  76. package/src/Graph/IGraphOptions.ts +0 -6
  77. package/src/Graph/index.spec.ts +0 -318
  78. package/src/Graph/index.ts +0 -170
  79. package/src/HashTable/IHashTable.ts +0 -11
  80. package/src/HashTable/IHashTableData.ts +0 -5
  81. package/src/HashTable/IHashTableInputs.ts +0 -5
  82. package/src/HashTable/IHashTableOptions.ts +0 -5
  83. package/src/HashTable/index.spec.ts +0 -136
  84. package/src/HashTable/index.ts +0 -78
  85. package/src/HashTableLinearProbing/HashTableLinearProbingElement.spec.ts +0 -28
  86. package/src/HashTableLinearProbing/HashTableLinearProbingElement.ts +0 -18
  87. package/src/HashTableLinearProbing/IHashTableLinearProbing.ts +0 -11
  88. package/src/HashTableLinearProbing/IHashTableLinearProbingData.ts +0 -7
  89. package/src/HashTableLinearProbing/IHashTableLinearProbingInputs.ts +0 -5
  90. package/src/HashTableLinearProbing/IHashTableLinearProbingOptions.ts +0 -5
  91. package/src/HashTableLinearProbing/index.spec.ts +0 -266
  92. package/src/HashTableLinearProbing/index.ts +0 -128
  93. package/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts +0 -21
  94. package/src/HashTableSeparateChaining/IHashTableSeparateChaining.ts +0 -12
  95. package/src/HashTableSeparateChaining/IHashTableSeparateChainingData.ts +0 -7
  96. package/src/HashTableSeparateChaining/IHashTableSeparateChainingInputs.ts +0 -5
  97. package/src/HashTableSeparateChaining/IHashTableSeparateChainingOptions.ts +0 -5
  98. package/src/HashTableSeparateChaining/index.spec.ts +0 -173
  99. package/src/HashTableSeparateChaining/index.ts +0 -104
  100. package/src/LinkedList/ILinkedList.ts +0 -15
  101. package/src/LinkedList/ILinkedListItem.ts +0 -6
  102. package/src/LinkedList/Node.ts +0 -8
  103. package/src/LinkedList/index.spec.ts +0 -355
  104. package/src/LinkedList/index.ts +0 -185
  105. package/src/List/index.ts +0 -1
  106. package/src/MaxHeap/IMaxHeap.ts +0 -10
  107. package/src/MaxHeap/IMaxHeapOptions.ts +0 -6
  108. package/src/MaxHeap/index.spec.ts +0 -161
  109. package/src/MaxHeap/index.ts +0 -91
  110. package/src/MinHeap/IMinHeap.ts +0 -10
  111. package/src/MinHeap/IMinHeapOptions.ts +0 -6
  112. package/src/MinHeap/index.spec.ts +0 -161
  113. package/src/MinHeap/index.ts +0 -91
  114. package/src/Queue/IQueue.ts +0 -9
  115. package/src/Queue/index.spec.ts +0 -92
  116. package/src/Queue/index.ts +0 -44
  117. package/src/Set/ISet.ts +0 -17
  118. package/src/Set/index.spec.ts +0 -246
  119. package/src/Set/index.ts +0 -134
  120. package/src/Stack/IStack.ts +0 -9
  121. package/src/Stack/index.spec.ts +0 -108
  122. package/src/Stack/index.ts +0 -43
  123. package/src/index.ts +0 -17
package/src/Deck/IDeck.ts DELETED
@@ -1,10 +0,0 @@
1
- interface IDeck<T> {
2
- addFront(_element: T): T;
3
- addBack(_element: T): T;
4
- removeFront(): T | undefined;
5
- removeBack(): T | undefined;
6
- peekFront(): T | undefined;
7
- peekBack(): T | undefined;
8
- }
9
-
10
- export default IDeck;
@@ -1,131 +0,0 @@
1
- import {describe, it, expect} from '@jest/globals';
2
-
3
- import Deck from './';
4
-
5
- describe('Deck', () => {
6
- it('Should create an empty deck without problems', () => {
7
- const deck = new Deck();
8
-
9
- expect(deck.data).toEqual([]);
10
- expect(deck.size).toBe(0);
11
- });
12
-
13
- it('Should create a filled deck without problems', () => {
14
- const deck = new Deck(1, 2, 3, 4);
15
-
16
- expect(deck.data).toEqual([1, 2, 3, 4]);
17
- expect(deck.size).toBe(4);
18
- });
19
-
20
- describe('.addFront()', () => {
21
- it('Should add an element in the front of the deck', () => {
22
- const deck = new Deck(2, 3, 4);
23
- deck.addFront(1);
24
-
25
- expect(deck.data).toEqual([1, 2, 3, 4]);
26
- });
27
-
28
- it('Should return the inserted element', () => {
29
- const deck = new Deck(2, 3, 4);
30
- const returned = deck.addFront(1);
31
-
32
- expect(returned).toBe(1);
33
- });
34
- });
35
-
36
- describe('.addBack()', () => {
37
- it('Should add an element in the back of the deck', () => {
38
- const deck = new Deck(1, 2, 3);
39
- deck.addBack(4);
40
-
41
- expect(deck.data).toEqual([1, 2, 3, 4]);
42
- });
43
-
44
- it('Should return the inserted element', () => {
45
- const deck = new Deck(1, 2, 3);
46
- const returned = deck.addBack(4);
47
-
48
- expect(returned).toBe(4);
49
- });
50
- });
51
-
52
- describe('.removeFront()', () => {
53
- it('Should remove the element in the front of the deck', () => {
54
- const deck = new Deck(1, 2, 3, 4);
55
- deck.removeFront();
56
-
57
- expect(deck.data).toEqual([2, 3, 4]);
58
- });
59
-
60
- it('Should return the removed element', () => {
61
- const deck = new Deck(1, 2, 3, 4);
62
- const returned = deck.removeFront();
63
-
64
- expect(returned).toBe(1);
65
- });
66
- });
67
-
68
- describe('.removeBack()', () => {
69
- it('Should remove the element in the back of the deck', () => {
70
- const deck = new Deck(1, 2, 3, 4);
71
- deck.removeBack();
72
-
73
- expect(deck.data).toEqual([1, 2, 3]);
74
- });
75
-
76
- it('Should return the removed element', () => {
77
- const deck = new Deck(1, 2, 3, 4);
78
- const returned = deck.removeBack();
79
-
80
- expect(returned).toBe(4);
81
- });
82
- });
83
-
84
- describe('.peekFront()', () => {
85
- it('Should peek the element in the front of the deck', () => {
86
- const deck = new Deck(1, 2, 3, 4);
87
- const returned = deck.peekFront();
88
-
89
- expect(returned).toBe(1);
90
- });
91
-
92
- it('Should not remove the element in the front os the deck', () => {
93
- const deck = new Deck(1, 2, 3, 4);
94
- deck.peekFront();
95
-
96
- expect(deck.data).toEqual([1, 2, 3, 4]);
97
- });
98
- });
99
-
100
- describe('.peekBack()', () => {
101
- it('Should peek the element in the back of the deck', () => {
102
- const deck = new Deck(1, 2, 3, 4);
103
- const returned = deck.peekBack();
104
-
105
- expect(returned).toBe(4);
106
- });
107
-
108
- it('Should not remove the element in the back os the deck', () => {
109
- const deck = new Deck(1, 2, 3, 4);
110
- deck.peekBack();
111
-
112
- expect(deck.data).toEqual([1, 2, 3, 4]);
113
- });
114
- });
115
-
116
- describe('Conversion to primitive', () => {
117
- it('Should return comma-separated elements in string conversion', () => {
118
- const deck = new Deck(1, 2, 3, 4);
119
- const string = String(deck);
120
-
121
- expect(string).toBe('[Front] 1, 2, 3, 4 [Back]');
122
- });
123
-
124
- it('Should return the deck size in number conversion', () => {
125
- const deck = new Deck(1, 2, 3, 4);
126
- const number = Number(deck);
127
-
128
- expect(number).toBe(4);
129
- });
130
- });
131
- });
package/src/Deck/index.ts DELETED
@@ -1,51 +0,0 @@
1
- import DataStructure from '../DataStructure';
2
- import IDeck from './IDeck';
3
-
4
- export default class Deck<T = number> extends DataStructure<T> implements IDeck<T> {
5
- constructor(...inputs: T[]) {
6
- super(inputs);
7
- }
8
-
9
- public addFront(element: T): T {
10
- this._data = [element, ...this.data];
11
- return element;
12
- }
13
-
14
- public addBack(element: T): T {
15
- this._data = [...this.data, element];
16
- return element;
17
- }
18
-
19
- public removeFront(): T | undefined {
20
- const [element, ...rest] = this.data;
21
- this._data = rest;
22
- return element;
23
- }
24
-
25
- public removeBack(): T | undefined {
26
- const element = this._data.pop();
27
- return element;
28
- }
29
-
30
- public peekFront(): T | undefined {
31
- const [element] = this.data;
32
- return element;
33
- }
34
-
35
- public peekBack(): T | undefined {
36
- const element = this.data[this.size - 1];
37
- return element;
38
- }
39
-
40
- private [Symbol.toPrimitive](type: string): string | number | null {
41
- if (type === 'string') {
42
- return `[Front] ${this.data.join(', ')} [Back]`;
43
- }
44
-
45
- if (type === 'number') {
46
- return this.size;
47
- }
48
-
49
- return null;
50
- }
51
- }
@@ -1,18 +0,0 @@
1
- import IDictionaryData from './IDictionaryData';
2
-
3
- interface IDictionary<T> {
4
- get data(): IDictionaryData<T>;
5
- get size(): number;
6
- get isEmpty(): boolean;
7
- get keys(): string[];
8
- get values(): T[];
9
- get pairs(): [string, T][]
10
- set(_key: string, _value: T): [string, T];
11
- remove(_key: string): [string, T] | null;
12
- hasKey(_key: string): boolean;
13
- get(_key: string): T | null;
14
- clear(): IDictionaryData<T>
15
- forEach(_func: (_key: string, _value: T) => any): void;
16
- }
17
-
18
- export default IDictionary;
@@ -1,5 +0,0 @@
1
- interface IDictionaryData<T> {
2
- [key: string]: T
3
- }
4
-
5
- export default IDictionaryData;
@@ -1,310 +0,0 @@
1
- import {describe, it, expect, jest} from '@jest/globals';
2
-
3
- import Dictionary from './';
4
-
5
- describe('Dictionary', () => {
6
- it('Should create an empty dictionary without problems', () => {
7
- const dictionary = new Dictionary<number>();
8
-
9
- expect(dictionary.data).toEqual({});
10
- expect(dictionary.size).toBe(0);
11
- });
12
-
13
- it('Should create a filled dictionary without problems', () => {
14
- const dictionary = new Dictionary<number>({
15
- first: 1,
16
- second: 2,
17
- third: 3,
18
- fourth: 4,
19
- });
20
-
21
- expect(dictionary.data).toEqual({
22
- first: 1,
23
- second: 2,
24
- third: 3,
25
- fourth: 4,
26
- });
27
- expect(dictionary.size).toBe(4);
28
- });
29
-
30
- describe('.isEmpty', () => {
31
- it('Should return true when the dictionary has no key value pairs', () => {
32
- const dictionary = new Dictionary({});
33
-
34
- expect(dictionary.isEmpty).toBe(true);
35
- });
36
-
37
- it('Should return false when the dictionary has some key value pair', () => {
38
- const dictionary = new Dictionary({
39
- first: 1,
40
- });
41
-
42
- expect(dictionary.isEmpty).toBe(false);
43
- });
44
- });
45
-
46
- describe('.keys', () => {
47
- it('Should return an array with all the dictionary keys', () => {
48
- const dictionary = new Dictionary<number>({
49
- first: 1,
50
- second: 2,
51
- third: 3,
52
- fourth: 4,
53
- });
54
-
55
- expect(dictionary.keys.sort()).toEqual(['first', 'second', 'third', 'fourth'].sort());
56
- });
57
- });
58
-
59
- describe('.values', () => {
60
- it('Should return an array with all the dictionary values', () => {
61
- const dictionary = new Dictionary<number>({
62
- first: 1,
63
- second: 2,
64
- third: 3,
65
- fourth: 4,
66
- });
67
-
68
- expect(dictionary.values.sort()).toEqual([1, 2, 3, 4].sort());
69
- });
70
- });
71
-
72
- describe('.pairs', () => {
73
- it('Should return an array of key value pairs', () => {
74
- const dictionary = new Dictionary<number>({
75
- first: 1,
76
- second: 2,
77
- third: 3,
78
- fourth: 4,
79
- });
80
-
81
- expect(dictionary.pairs.sort())
82
- .toEqual([['first', 1], ['second', 2], ['third', 3], ['fourth', 4]].sort());
83
- });
84
- });
85
-
86
- describe('.set()', () => {
87
- it('Should set a new key with a value in the dictionary', () => {
88
- const dictionary = new Dictionary({
89
- first: 1,
90
- });
91
- dictionary.set('second', 2);
92
-
93
- expect(dictionary.data).toEqual({
94
- first: 1,
95
- second: 2,
96
- });
97
- expect(dictionary.size).toBe(2);
98
- });
99
-
100
- it('Should replace a key value pair when receive an already existent key', () => {
101
- const dictionary = new Dictionary({
102
- first: 1,
103
- });
104
- dictionary.set('first', 2);
105
-
106
- expect(dictionary.data).toEqual({
107
- first: 2,
108
- });
109
- expect(dictionary.size).toBe(1);
110
- });
111
-
112
- it('Should return the inserted key valur pair', () => {
113
- const dictionary = new Dictionary();
114
- const returned = dictionary.set('first', 1);
115
-
116
- expect(returned).toEqual(['first', 1]);
117
- });
118
- });
119
-
120
- describe('.remove()', () => {
121
- it('Should remove an existent key value pair', () => {
122
- const dictionary = new Dictionary({
123
- first: 1,
124
- second: 2,
125
- third: 3,
126
- fourth: 4,
127
- });
128
- dictionary.remove('third');
129
-
130
- expect(dictionary.data).toEqual({
131
- first: 1,
132
- second: 2,
133
- fourth: 4,
134
- });
135
- expect(dictionary.size).toBe(3);
136
- });
137
-
138
- it('Should change nothing when receive a non existent key', () => {
139
- const dictionary = new Dictionary({
140
- first: 1,
141
- second: 2,
142
- third: 3,
143
- fourth: 4,
144
- });
145
- dictionary.remove('fifth');
146
-
147
- expect(dictionary.data).toEqual({
148
- first: 1,
149
- second: 2,
150
- third: 3,
151
- fourth: 4,
152
- });
153
- expect(dictionary.size).toBe(4);
154
- });
155
-
156
- it('Should return the removed key value pair', () => {
157
- const dictionary = new Dictionary({
158
- first: 1,
159
- second: 2,
160
- third: 3,
161
- fourth: 4,
162
- });
163
- const returned = dictionary.remove('second');
164
-
165
- expect(returned).toEqual(['second', 2]);
166
- });
167
-
168
- it('Should return null when the dictionary has not the received key', () => {
169
- const dictionary = new Dictionary({
170
- first: 1,
171
- second: 2,
172
- third: 3,
173
- fourth: 4,
174
- });
175
- const returned = dictionary.remove('fifth');
176
-
177
- expect(returned).toBeNull();
178
- });
179
- });
180
-
181
- describe('.hasKey()', () => {
182
- it('Should return truw when the dictionary has the received key', () => {
183
- const dictionary = new Dictionary({
184
- first: 1,
185
- second: 2,
186
- third: 3,
187
- fourth: 4,
188
- });
189
- const returned = dictionary.hasKey('first');
190
-
191
- expect(returned).toBe(true);
192
- });
193
-
194
- it('Should return false when the dictionary has not the received key', () => {
195
- const dictionary = new Dictionary({
196
- first: 1,
197
- second: 2,
198
- third: 3,
199
- fourth: 4,
200
- });
201
- const returned = dictionary.hasKey('fifth');
202
-
203
- expect(returned).toBe(false);
204
- });
205
- });
206
-
207
- describe('.get()', () => {
208
- it('Should return the value of the received key', () => {
209
- const dictionary = new Dictionary<number>({
210
- first: 1,
211
- second: 2,
212
- third: 3,
213
- fourth: 4,
214
- });
215
- const returned = dictionary.get('third');
216
-
217
- expect(returned).toBe(3);
218
- });
219
-
220
- it('Should return null when the dictionary has not the received key', () => {
221
- const dictionary = new Dictionary<number>({
222
- first: 1,
223
- second: 2,
224
- third: 3,
225
- fourth: 4,
226
- });
227
- const returned = dictionary.get('fifth');
228
-
229
- expect(returned).toBeNull();
230
- });
231
- });
232
-
233
- describe('.clear()', () => {
234
- it('Should clear the dictionary', () => {
235
- const dictionary = new Dictionary({
236
- first: 1,
237
- second: 2,
238
- third: 3,
239
- fourth: 3,
240
- });
241
- dictionary.clear();
242
-
243
- expect(dictionary.data).toEqual({});
244
- expect(dictionary.size).toBe(0);
245
- });
246
-
247
- it('Should return the dictionary key values pairs befores the clear', () => {
248
- const dictionary = new Dictionary({
249
- first: 1,
250
- second: 2,
251
- third: 3,
252
- fourth: 3,
253
- });
254
- const returned = dictionary.clear();
255
-
256
- expect(returned).toEqual({
257
- first: 1,
258
- second: 2,
259
- third: 3,
260
- fourth: 3,
261
- });
262
- });
263
- });
264
-
265
- describe('.forEach()', () => {
266
- it('Should call the received function for each elements', () => {
267
- const dictionary = new Dictionary<number>({
268
- first: 1,
269
- second: 2,
270
- third: 3,
271
- fourth: 4,
272
- });
273
- const func = jest.fn();
274
-
275
- dictionary.forEach(func);
276
-
277
- expect(func).toBeCalledTimes(4);
278
- expect(func).toBeCalledWith('first', 1);
279
- expect(func).toBeCalledWith('second', 2);
280
- expect(func).toBeCalledWith('third', 3);
281
- expect(func).toBeCalledWith('fourth', 4);
282
- });
283
- });
284
-
285
- describe('Conversion to primitive', () => {
286
- it('Should return a comma separated key value pairs in string conversion', () => {
287
- const dictionary = new Dictionary<number>({
288
- first: 1,
289
- second: 2,
290
- third: 3,
291
- fourth: 4,
292
- });
293
- const string = String(dictionary);
294
-
295
- expect(string).toBe('{ first => 1, second => 2, third => 3, fourth => 4 }');
296
- });
297
-
298
- it('Should return the dictionary size in number conversion', () => {
299
- const dictionary = new Dictionary<number>({
300
- first: 1,
301
- second: 2,
302
- third: 3,
303
- fourth: 4,
304
- });
305
- const number = Number(dictionary);
306
-
307
- expect(number).toBe(4);
308
- });
309
- });
310
- });
@@ -1,88 +0,0 @@
1
- import IDictionary from './IDictionary';
2
- import IDictionaryData from './IDictionaryData';
3
-
4
- export default class Dictionary<T = number> implements IDictionary<T> {
5
- private _data: IDictionaryData<T> = {};
6
-
7
- constructor(inputs: { [key: string]: T } = {}) {
8
- this._data = inputs;
9
- }
10
-
11
- get data(): IDictionaryData<T> {
12
- return {...this._data};
13
- }
14
-
15
- get size(): number {
16
- return Reflect.ownKeys(this.data).length;
17
- }
18
-
19
- get isEmpty(): boolean {
20
- return this.size === 0;
21
- }
22
-
23
- get keys(): string[] {
24
- return Reflect
25
- .ownKeys(this.data)
26
- .map(key => String(key));
27
- }
28
-
29
- get values(): T[] {
30
- return Object.values(this.data);
31
- }
32
-
33
- get pairs(): [string, T][] {
34
- return Object.entries(this.data);
35
- }
36
-
37
- public set(key: string, value: T): [string, T] {
38
- Reflect.set(this._data, key, value);
39
- return [key, value];
40
- }
41
-
42
- public remove(key: string): [string, T] | null {
43
- if (this.hasKey(key)) {
44
- const value = Reflect.get(this.data, key);
45
- Reflect.deleteProperty(this._data, key);
46
-
47
- return [key, value];
48
- }
49
-
50
- return null;
51
- }
52
-
53
- public hasKey(key: string): boolean {
54
- return Reflect.has(this.data, key);
55
- }
56
-
57
- public get(key: string): T | null {
58
- if (this.hasKey(key)) {
59
- return Reflect.get(this.data, key);
60
- }
61
-
62
- return null;
63
- }
64
-
65
- public clear(): IDictionaryData<T> {
66
- const dictionary = {...this.data};
67
- this._data = {};
68
- return dictionary;
69
- }
70
-
71
- public forEach(func: (_key: string, _value: T) => any): void {
72
- for (const [key, value] of this.pairs) {
73
- func(key, value);
74
- }
75
- }
76
-
77
- private[Symbol.toPrimitive](type: string): string | number | null {
78
- if (type === 'string') {
79
- return `{ ${this.pairs.map(([key, value]) => `${key} => ${value}`).join(', ')} }`;
80
- }
81
-
82
- if (type === 'number') {
83
- return this.size;
84
- }
85
-
86
- return null;
87
- }
88
- }
@@ -1,18 +0,0 @@
1
- export interface IDoublyLinkedListItem<T> {
2
- previous: T | null;
3
- value: T;
4
- next: T | null;
5
- }
6
-
7
- interface IDoublyLinkedList<T> {
8
- get data(): IDoublyLinkedListItem<T>[];
9
- get size(): number;
10
- push(_element: T): T;
11
- getFromPosition(_position: number): IDoublyLinkedListItem<T> | undefined;
12
- positionOf(_element: T): number | undefined;
13
- insertInPosition(_element: T, _position: number): T | undefined;
14
- remove(_element: T): T | undefined;
15
- removeFromPosition(_position: number): T | undefined;
16
- }
17
-
18
- export default IDoublyLinkedList;
@@ -1,9 +0,0 @@
1
- export default class Node<T> {
2
- public value: T;
3
- public previous: Node<T> | null = null;
4
- public next: Node<T> | null = null;
5
-
6
- constructor(value: T) {
7
- this.value = value;
8
- }
9
- }