data-structure-typed 1.33.7 → 1.33.9

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 (149) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +25 -14
  3. package/package.json +22 -22
  4. package/.prettierrc.js +0 -16
  5. package/coverage/coverage-final.json +0 -68
  6. package/coverage/coverage-summary.json +0 -69
  7. package/docs/.nojekyll +0 -1
  8. package/docs/index.html +0 -875
  9. package/docs/modules.html +0 -336
  10. package/jest.config.js +0 -8
  11. package/src/data-structures/binary-tree/aa-tree.ts +0 -1
  12. package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1608
  13. package/src/data-structures/binary-tree/avl-tree.ts +0 -307
  14. package/src/data-structures/binary-tree/b-tree.ts +0 -1
  15. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -76
  16. package/src/data-structures/binary-tree/binary-tree.ts +0 -47
  17. package/src/data-structures/binary-tree/bst.ts +0 -537
  18. package/src/data-structures/binary-tree/index.ts +0 -12
  19. package/src/data-structures/binary-tree/rb-tree.ts +0 -366
  20. package/src/data-structures/binary-tree/segment-tree.ts +0 -260
  21. package/src/data-structures/binary-tree/splay-tree.ts +0 -1
  22. package/src/data-structures/binary-tree/tree-multiset.ts +0 -700
  23. package/src/data-structures/binary-tree/two-three-tree.ts +0 -1
  24. package/src/data-structures/graph/abstract-graph.ts +0 -1040
  25. package/src/data-structures/graph/directed-graph.ts +0 -470
  26. package/src/data-structures/graph/index.ts +0 -4
  27. package/src/data-structures/graph/map-graph.ts +0 -129
  28. package/src/data-structures/graph/undirected-graph.ts +0 -274
  29. package/src/data-structures/hash/coordinate-map.ts +0 -67
  30. package/src/data-structures/hash/coordinate-set.ts +0 -56
  31. package/src/data-structures/hash/hash-map.ts +0 -203
  32. package/src/data-structures/hash/hash-table.ts +0 -277
  33. package/src/data-structures/hash/index.ts +0 -7
  34. package/src/data-structures/hash/pair.ts +0 -1
  35. package/src/data-structures/hash/tree-map.ts +0 -1
  36. package/src/data-structures/hash/tree-set.ts +0 -1
  37. package/src/data-structures/heap/heap.ts +0 -212
  38. package/src/data-structures/heap/index.ts +0 -3
  39. package/src/data-structures/heap/max-heap.ts +0 -31
  40. package/src/data-structures/heap/min-heap.ts +0 -32
  41. package/src/data-structures/index.ts +0 -11
  42. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -636
  43. package/src/data-structures/linked-list/index.ts +0 -3
  44. package/src/data-structures/linked-list/singly-linked-list.ts +0 -501
  45. package/src/data-structures/linked-list/skip-linked-list.ts +0 -166
  46. package/src/data-structures/matrix/index.ts +0 -4
  47. package/src/data-structures/matrix/matrix.ts +0 -27
  48. package/src/data-structures/matrix/matrix2d.ts +0 -213
  49. package/src/data-structures/matrix/navigator.ts +0 -121
  50. package/src/data-structures/matrix/vector2d.ts +0 -316
  51. package/src/data-structures/priority-queue/index.ts +0 -3
  52. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -56
  53. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -57
  54. package/src/data-structures/priority-queue/priority-queue.ts +0 -359
  55. package/src/data-structures/queue/deque.ts +0 -297
  56. package/src/data-structures/queue/index.ts +0 -2
  57. package/src/data-structures/queue/queue.ts +0 -191
  58. package/src/data-structures/stack/index.ts +0 -1
  59. package/src/data-structures/stack/stack.ts +0 -98
  60. package/src/data-structures/tree/index.ts +0 -1
  61. package/src/data-structures/tree/tree.ts +0 -69
  62. package/src/data-structures/trie/index.ts +0 -1
  63. package/src/data-structures/trie/trie.ts +0 -225
  64. package/src/index.ts +0 -4
  65. package/src/interfaces/abstract-binary-tree.ts +0 -189
  66. package/src/interfaces/abstract-graph.ts +0 -31
  67. package/src/interfaces/avl-tree.ts +0 -25
  68. package/src/interfaces/binary-tree.ts +0 -6
  69. package/src/interfaces/bst.ts +0 -31
  70. package/src/interfaces/directed-graph.ts +0 -20
  71. package/src/interfaces/doubly-linked-list.ts +0 -1
  72. package/src/interfaces/heap.ts +0 -1
  73. package/src/interfaces/index.ts +0 -15
  74. package/src/interfaces/navigator.ts +0 -1
  75. package/src/interfaces/priority-queue.ts +0 -1
  76. package/src/interfaces/rb-tree.ts +0 -9
  77. package/src/interfaces/segment-tree.ts +0 -1
  78. package/src/interfaces/singly-linked-list.ts +0 -1
  79. package/src/interfaces/tree-multiset.ts +0 -7
  80. package/src/interfaces/undirected-graph.ts +0 -6
  81. package/src/types/data-structures/abstract-binary-tree.ts +0 -50
  82. package/src/types/data-structures/abstract-graph.ts +0 -11
  83. package/src/types/data-structures/avl-tree.ts +0 -5
  84. package/src/types/data-structures/binary-tree.ts +0 -5
  85. package/src/types/data-structures/bst.ts +0 -13
  86. package/src/types/data-structures/directed-graph.ts +0 -8
  87. package/src/types/data-structures/doubly-linked-list.ts +0 -1
  88. package/src/types/data-structures/hash.ts +0 -1
  89. package/src/types/data-structures/heap.ts +0 -5
  90. package/src/types/data-structures/index.ts +0 -16
  91. package/src/types/data-structures/map-graph.ts +0 -1
  92. package/src/types/data-structures/navigator.ts +0 -13
  93. package/src/types/data-structures/priority-queue.ts +0 -9
  94. package/src/types/data-structures/rb-tree.ts +0 -8
  95. package/src/types/data-structures/segment-tree.ts +0 -1
  96. package/src/types/data-structures/singly-linked-list.ts +0 -1
  97. package/src/types/data-structures/tree-multiset.ts +0 -6
  98. package/src/types/helpers.ts +0 -1
  99. package/src/types/index.ts +0 -3
  100. package/src/types/utils/index.ts +0 -2
  101. package/src/types/utils/utils.ts +0 -6
  102. package/src/types/utils/validate-type.ts +0 -35
  103. package/src/utils/index.ts +0 -1
  104. package/src/utils/utils.ts +0 -79
  105. package/test/integration/avl-tree.test.ts +0 -108
  106. package/test/integration/bst.test.ts +0 -380
  107. package/test/integration/heap.test.js +0 -16
  108. package/test/integration/index.html +0 -44
  109. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +0 -108
  110. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +0 -142
  111. package/test/unit/data-structures/binary-tree/bst.test.ts +0 -380
  112. package/test/unit/data-structures/binary-tree/overall.test.ts +0 -65
  113. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +0 -43
  114. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +0 -50
  115. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +0 -461
  116. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -5
  117. package/test/unit/data-structures/graph/directed-graph.test.ts +0 -519
  118. package/test/unit/data-structures/graph/index.ts +0 -2
  119. package/test/unit/data-structures/graph/map-graph.test.ts +0 -45
  120. package/test/unit/data-structures/graph/overall.test.ts +0 -49
  121. package/test/unit/data-structures/graph/undirected-graph.test.ts +0 -59
  122. package/test/unit/data-structures/hash/coordinate-map.test.ts +0 -54
  123. package/test/unit/data-structures/hash/coordinate-set.test.ts +0 -41
  124. package/test/unit/data-structures/hash/hash-map.test.ts +0 -104
  125. package/test/unit/data-structures/hash/hash-table.test.ts +0 -184
  126. package/test/unit/data-structures/heap/heap.test.ts +0 -55
  127. package/test/unit/data-structures/heap/max-heap.test.ts +0 -44
  128. package/test/unit/data-structures/heap/min-heap.test.ts +0 -82
  129. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +0 -364
  130. package/test/unit/data-structures/linked-list/index.ts +0 -4
  131. package/test/unit/data-structures/linked-list/linked-list.test.ts +0 -35
  132. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -451
  133. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +0 -13
  134. package/test/unit/data-structures/linked-list/skip-list.test.ts +0 -55
  135. package/test/unit/data-structures/matrix/matrix.test.ts +0 -54
  136. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -138
  137. package/test/unit/data-structures/matrix/navigator.test.ts +0 -79
  138. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +0 -106
  139. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +0 -105
  140. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -27
  141. package/test/unit/data-structures/queue/deque.test.ts +0 -130
  142. package/test/unit/data-structures/queue/queue.test.ts +0 -199
  143. package/test/unit/data-structures/stack/stack.test.ts +0 -67
  144. package/test/unit/data-structures/tree/tree.test.ts +0 -39
  145. package/test/unit/data-structures/trie/trie.test.ts +0 -95
  146. package/test/utils/index.ts +0 -2
  147. package/test/utils/magnitude.ts +0 -21
  148. package/test/utils/number.ts +0 -3
  149. package/tsconfig.json +0 -29
@@ -1,364 +0,0 @@
1
- import {DoublyLinkedList} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
3
-
4
- describe('DoublyLinkedList Operation Test', () => {
5
- let list: DoublyLinkedList<number>;
6
- let objectList: DoublyLinkedList<{keyA: number}>;
7
-
8
- beforeEach(() => {
9
- list = new DoublyLinkedList();
10
- objectList = new DoublyLinkedList();
11
- });
12
-
13
- it('should initialize an empty list', () => {
14
- expect(list.length).toBe(0);
15
- expect(list.head).toBeNull();
16
- expect(list.tail).toBeNull();
17
- });
18
-
19
- it('should push elements to the list', () => {
20
- list.push(1);
21
- list.push(2);
22
- list.push(3);
23
- expect(list.length).toBe(3);
24
- expect(list.head!.val).toBe(1);
25
- expect(list.tail!.val).toBe(3);
26
- });
27
-
28
- it('should pop elements from the end of the list', () => {
29
- list.push(1);
30
- list.push(2);
31
- const poppedValue = list.pop();
32
- expect(poppedValue).toBe(2);
33
- expect(list.length).toBe(1);
34
- expect(list.head!.val).toBe(1);
35
- expect(list.tail!.val).toBe(1);
36
- });
37
- it('should insert elements at specific positions', () => {
38
- list.push(1);
39
- list.push(2);
40
- list.push(3);
41
-
42
- // Inserting at the beginning
43
- list.insertAt(0, 0);
44
- expect(list.length).toBe(4);
45
- expect(list.getAt(0)).toBe(0);
46
- expect(list.getAt(1)).toBe(1);
47
-
48
- // Inserting in the middle
49
- list.insertAt(2, 1.5);
50
- expect(list.length).toBe(5);
51
- expect(list.getAt(2)).toBe(1.5);
52
- expect(list.getAt(3)).toBe(2);
53
-
54
- // Inserting at the end
55
- list.insertAt(5, 4);
56
- expect(list.length).toBe(6);
57
- expect(list.getAt(5)).toBe(4);
58
- expect(list.tail!.val).toBe(4);
59
- });
60
-
61
- it('should delete elements at specific positions', () => {
62
- list.push(1);
63
- list.push(2);
64
- list.push(3);
65
-
66
- // Deleting from the beginning
67
- const deletedValue = list.deleteAt(0);
68
- expect(deletedValue).toBe(1);
69
- expect(list.length).toBe(2);
70
- expect(list.head!.val).toBe(2);
71
-
72
- // Deleting from the middle
73
- list.deleteAt(0); // Deleting the second element
74
- expect(list.length).toBe(1);
75
- expect(list.head!.val).toBe(3);
76
-
77
- // Deleting from the end
78
- list.deleteAt(0);
79
- expect(list.length).toBe(0);
80
- expect(list.head).toBeNull();
81
- expect(list.tail).toBeNull();
82
- });
83
-
84
- it('should delete elements by value', () => {
85
- list.push(1);
86
- list.push(2);
87
- list.push(3);
88
-
89
- list.delete(2);
90
- expect(list.length).toBe(2);
91
- expect(list.head!.val).toBe(1);
92
- expect(list.tail!.val).toBe(3);
93
-
94
- list.delete(1);
95
- expect(list.length).toBe(1);
96
- expect(list.head!.val).toBe(3);
97
-
98
- list.delete(3);
99
- expect(list.length).toBe(0);
100
- expect(list.head).toBeNull();
101
- expect(list.tail).toBeNull();
102
- });
103
-
104
- it('should reverse the linked list', () => {
105
- list.push(1);
106
- list.push(2);
107
- list.push(3);
108
-
109
- list.reverse();
110
-
111
- expect(list.toArray()).toEqual([3, 2, 1]);
112
- expect(list.toArrayReverse()).toEqual([1, 2, 3]);
113
- });
114
-
115
- it('should map elements using a callback function', () => {
116
- list.push(1);
117
- list.push(2);
118
- list.push(3);
119
-
120
- const mappedList = list.map(val => val * 2);
121
-
122
- expect(mappedList.toArray()).toEqual([2, 4, 6]);
123
- });
124
-
125
- it('should filter elements using a callback function', () => {
126
- list.push(1);
127
- list.push(2);
128
- list.push(3);
129
- list.push(4);
130
-
131
- const filteredList = list.filter(val => val % 2 === 0);
132
-
133
- expect(filteredList.toArray()).toEqual([2, 4]);
134
- });
135
-
136
- it('should reduce elements using a callback function and an initial value', () => {
137
- list.push(1);
138
- list.push(2);
139
- list.push(3);
140
- list.push(4);
141
-
142
- const sum = list.reduce((acc, val) => acc + val, 0);
143
-
144
- expect(sum).toBe(10);
145
- });
146
-
147
- it('should insert an element after a specific value', () => {
148
- list.push(1);
149
- list.push(2);
150
- list.push(3);
151
-
152
- list.insertAfter(2, 2.5);
153
-
154
- expect(list.toArray()).toEqual([1, 2, 2.5, 3]);
155
- });
156
-
157
- it('should insert an element before a specific value', () => {
158
- list.push(1);
159
- list.push(2);
160
- list.push(3);
161
-
162
- list.insertBefore(2, 1.5);
163
-
164
- expect(list.toArray()).toEqual([1, 1.5, 2, 3]);
165
- });
166
- it('should find the first element that satisfies a condition', () => {
167
- list.push(1);
168
- list.push(2);
169
- list.push(3);
170
-
171
- const found = list.find(val => val % 2 === 0);
172
-
173
- expect(found).toBe(2);
174
- });
175
-
176
- it('should find the index of an element', () => {
177
- list.push(1);
178
- list.push(2);
179
- list.push(3);
180
-
181
- const index = list.indexOf(2);
182
-
183
- expect(index).toBe(1);
184
- });
185
-
186
- it('should find the last element that satisfies a condition', () => {
187
- list.push(1);
188
- list.push(2);
189
- list.push(3);
190
- list.push(4);
191
-
192
- const lastEven = list.findLast(val => val % 2 === 0);
193
-
194
- expect(lastEven).toBe(4);
195
- });
196
-
197
- it('should clear the linked list', () => {
198
- list.push(1);
199
- list.push(2);
200
- list.push(3);
201
-
202
- list.clear();
203
-
204
- expect(list.length).toBe(0);
205
- expect(list.head).toBe(null);
206
- expect(list.tail).toBe(null);
207
- });
208
-
209
- it('should create a reversed array of values', () => {
210
- list.push(1);
211
- list.push(2);
212
- list.push(3);
213
-
214
- const reversedArray = list.toArrayReverse();
215
-
216
- expect(reversedArray).toEqual([3, 2, 1]);
217
- });
218
-
219
- it('should reverse the linked list', () => {
220
- list.push(1);
221
- list.push(2);
222
- list.push(3);
223
-
224
- list.reverse();
225
-
226
- expect(list.toArray()).toEqual([3, 2, 1]);
227
- expect(list.head?.val).toBe(3);
228
- expect(list.tail?.val).toBe(1);
229
- });
230
-
231
- it('should iterate over each element and apply a callback', () => {
232
- list.push(1);
233
- list.push(2);
234
- list.push(3);
235
-
236
- const result: number[] = [];
237
- list.forEach(val => {
238
- result.push(val * 2);
239
- });
240
-
241
- expect(result).toEqual([2, 4, 6]);
242
- });
243
-
244
- it('should create a new linked list by applying a mapping function', () => {
245
- list.push(1);
246
- list.push(2);
247
- list.push(3);
248
-
249
- const mappedList = list.map(val => val * 2);
250
-
251
- expect(mappedList.toArray()).toEqual([2, 4, 6]);
252
- });
253
-
254
- it('should create a new linked list by filtering elements', () => {
255
- list.push(1);
256
- list.push(2);
257
- list.push(3);
258
- list.push(4);
259
-
260
- const filteredList = list.filter(val => val % 2 === 0);
261
-
262
- expect(filteredList.toArray()).toEqual([2, 4]);
263
- });
264
-
265
- it('should reduce the linked list to a single value', () => {
266
- list.push(1);
267
- list.push(2);
268
- list.push(3);
269
-
270
- const sum = list.reduce((acc, val) => acc + val, 0);
271
-
272
- expect(sum).toBe(6);
273
- });
274
-
275
- it('should insert a new value after an existing value', () => {
276
- list.push(1);
277
- list.push(2);
278
- list.push(3);
279
-
280
- const success = list.insertAfter(2, 4);
281
- expect(success).toBe(true);
282
- expect(list.toArray()).toEqual([1, 2, 4, 3]);
283
- });
284
-
285
- it('should insert a new value before an existing value', () => {
286
- list.push(1);
287
- list.push(2);
288
- list.push(3);
289
-
290
- const success = list.insertBefore(2, 0);
291
- expect(success).toBe(true);
292
- expect(list.toArray()).toEqual([1, 0, 2, 3]);
293
- });
294
-
295
- it('should not insert a new value after a non-existing value', () => {
296
- list.push(1);
297
- list.push(2);
298
- list.push(3);
299
-
300
- const success = list.insertAfter(4, 5);
301
- expect(success).toBe(false);
302
- expect(list.toArray()).toEqual([1, 2, 3]);
303
- });
304
-
305
- it('should not insert a new value before a non-existing value', () => {
306
- list.push(1);
307
- list.push(2);
308
- list.push(3);
309
-
310
- const success = list.insertBefore(4, 0);
311
- expect(success).toBe(false);
312
- expect(list.toArray()).toEqual([1, 2, 3]);
313
- });
314
-
315
- it('should insert and manipulate objects with numeric properties', () => {
316
- const obj1 = {keyA: 10};
317
- const obj2 = {keyA: 20};
318
- const obj3 = {keyA: 30};
319
-
320
- objectList.push(obj1);
321
- objectList.push(obj2);
322
- objectList.push(obj3);
323
-
324
- expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
325
-
326
- const newObj = {keyA: 25}; // Corrected newObj value
327
- const insertSuccess = objectList.insertBefore(obj2, newObj);
328
- expect(insertSuccess).toBe(true);
329
-
330
- const findNode = objectList.findNode(newObj); // Use newObj instead of obj2
331
- expect(findNode?.val).toEqual(newObj);
332
-
333
- const deleted = objectList.delete(newObj); // Use newObj instead of obj2
334
- expect(deleted).toBe(true);
335
-
336
- const poppedObj = objectList.pop();
337
- expect(poppedObj).toBe(obj3);
338
-
339
- const shiftedObj = objectList.shift();
340
- expect(shiftedObj).toBe(obj1);
341
- });
342
- });
343
-
344
- describe('DoublyLinkedList Performance Test', () => {
345
- it('should the push and pop methods adhere to a time complexity of O(n) and executed correctly under large scale data', () => {
346
- const list = new DoublyLinkedList<number>();
347
-
348
- const startPushTime = performance.now();
349
- for (let i = 0; i < magnitude.LINEAR; i++) {
350
- list.unshift(i);
351
- }
352
- expect(performance.now() - startPushTime).toBeLessThan(bigO.LINEAR * 10);
353
-
354
- expect(list.length).toBeGreaterThan(0);
355
- const startPopTime = performance.now();
356
- for (let i = 0; i < magnitude.LINEAR; i++) {
357
- list.shift();
358
- }
359
- expect(performance.now() - startPopTime).toBeLessThan(bigO.LINEAR * 100);
360
-
361
- expect(list.pop()).toBeUndefined();
362
- expect(list.length).toBe(0);
363
- });
364
- });
@@ -1,4 +0,0 @@
1
- export * from './singly-linked-list.test';
2
- export * from './doubly-linked-list.test';
3
- export * from './linked-list.test';
4
- export * from './skip-linked-list.test';
@@ -1,35 +0,0 @@
1
- import {DoublyLinkedList, DoublyLinkedListNode, SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
2
- import {bigO, magnitude} from '../../../utils';
3
-
4
- describe('LinkedList Performance Test', () => {
5
- it('should DoublyLinkedList insertBefore faster than SinglyLinkedList', () => {
6
- const doublyList = new DoublyLinkedList<number>();
7
-
8
- const startPushTime = performance.now();
9
- let midNode: DoublyLinkedListNode | null = null;
10
- const midIndex = Math.floor(magnitude.SQUARED / 2);
11
- for (let i = 0; i < magnitude.SQUARED; i++) {
12
- doublyList.push(i);
13
- if (i === midIndex) {
14
- midNode = doublyList.findNode(i);
15
- } else if (i > midIndex && midNode) {
16
- doublyList.insertBefore(midNode, i);
17
- }
18
- }
19
- const doublyListPushCost = performance.now() - startPushTime;
20
-
21
- const singlyList = new SinglyLinkedList<number>();
22
- let midSinglyNode: SinglyLinkedListNode | null = null;
23
-
24
- for (let i = 0; i < magnitude.SQUARED; i++) {
25
- singlyList.push(i);
26
- if (i === midIndex) {
27
- midSinglyNode = singlyList.findNode(i);
28
- } else if (i > midIndex && midSinglyNode) {
29
- singlyList.insertBefore(midSinglyNode.val, i);
30
- }
31
- }
32
-
33
- expect(doublyListPushCost).toBeLessThan(bigO.SQUARED * 5);
34
- });
35
- });