data-structure-typed 1.41.6 → 1.41.7

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 (107) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +11 -11
  3. package/benchmark/report.html +11 -11
  4. package/benchmark/report.json +111 -111
  5. package/dist/cjs/src/data-structures/graph/abstract-graph.js +5 -5
  6. package/dist/cjs/src/data-structures/graph/abstract-graph.js.map +1 -1
  7. package/dist/mjs/src/data-structures/graph/abstract-graph.js +5 -5
  8. package/dist/umd/data-structure-typed.min.js +1 -1
  9. package/dist/umd/data-structure-typed.min.js.map +1 -1
  10. package/package.json +5 -5
  11. package/src/data-structures/graph/abstract-graph.ts +6 -6
  12. package/test/config.ts +1 -0
  13. package/test/integration/avl-tree.test.ts +110 -0
  14. package/test/integration/bst.test.ts +385 -0
  15. package/test/integration/heap.test.js +16 -0
  16. package/test/integration/index.html +51 -0
  17. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +36 -0
  18. package/test/performance/data-structures/binary-tree/binary-index-tree.test.ts +0 -0
  19. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +45 -0
  20. package/test/performance/data-structures/binary-tree/bst.test.ts +36 -0
  21. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  22. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +0 -0
  23. package/test/performance/data-structures/binary-tree/segment-tree.test.ts +0 -0
  24. package/test/performance/data-structures/binary-tree/tree-multiset.test.ts +0 -0
  25. package/test/performance/data-structures/graph/abstract-graph.test.ts +0 -0
  26. package/test/performance/data-structures/graph/directed-graph.test.ts +49 -0
  27. package/test/performance/data-structures/graph/map-graph.test.ts +0 -0
  28. package/test/performance/data-structures/graph/overall.test.ts +0 -0
  29. package/test/performance/data-structures/graph/undirected-graph.test.ts +0 -0
  30. package/test/performance/data-structures/hash/coordinate-map.test.ts +0 -0
  31. package/test/performance/data-structures/hash/coordinate-set.test.ts +0 -0
  32. package/test/performance/data-structures/hash/hash-map.test.ts +0 -0
  33. package/test/performance/data-structures/hash/hash-table.test.ts +0 -0
  34. package/test/performance/data-structures/heap/heap.test.ts +30 -0
  35. package/test/performance/data-structures/heap/max-heap.test.ts +0 -0
  36. package/test/performance/data-structures/heap/min-heap.test.ts +0 -0
  37. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +40 -0
  38. package/test/performance/data-structures/linked-list/linked-list.test.ts +0 -0
  39. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +34 -0
  40. package/test/performance/data-structures/linked-list/skip-linked-list.test.ts +0 -0
  41. package/test/performance/data-structures/linked-list/skip-list.test.ts +0 -0
  42. package/test/performance/data-structures/matrix/matrix.test.ts +0 -0
  43. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  44. package/test/performance/data-structures/matrix/navigator.test.ts +0 -0
  45. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  46. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +19 -0
  47. package/test/performance/data-structures/priority-queue/min-priority-queue.test.ts +0 -0
  48. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +0 -0
  49. package/test/performance/data-structures/queue/deque.test.ts +21 -0
  50. package/test/performance/data-structures/queue/queue.test.ts +25 -0
  51. package/test/performance/data-structures/stack/stack.test.ts +0 -0
  52. package/test/performance/data-structures/tree/tree.test.ts +0 -0
  53. package/test/performance/data-structures/trie/trie.test.ts +22 -0
  54. package/test/performance/reportor.ts +186 -0
  55. package/test/performance/types/index.ts +1 -0
  56. package/test/performance/types/reportor.ts +3 -0
  57. package/test/types/index.ts +1 -0
  58. package/test/types/utils/big-o.ts +1 -0
  59. package/test/types/utils/index.ts +2 -0
  60. package/test/types/utils/json2html.ts +1 -0
  61. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +269 -0
  62. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +320 -0
  63. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +486 -0
  64. package/test/unit/data-structures/binary-tree/bst.test.ts +840 -0
  65. package/test/unit/data-structures/binary-tree/overall.test.ts +66 -0
  66. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +435 -0
  67. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +50 -0
  68. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +542 -0
  69. package/test/unit/data-structures/graph/abstract-graph.test.ts +100 -0
  70. package/test/unit/data-structures/graph/directed-graph.test.ts +564 -0
  71. package/test/unit/data-structures/graph/map-graph.test.ts +126 -0
  72. package/test/unit/data-structures/graph/overall.test.ts +49 -0
  73. package/test/unit/data-structures/graph/salty-edges.json +1 -0
  74. package/test/unit/data-structures/graph/salty-vertexes.json +1 -0
  75. package/test/unit/data-structures/graph/undirected-graph.test.ts +168 -0
  76. package/test/unit/data-structures/hash/coordinate-map.test.ts +74 -0
  77. package/test/unit/data-structures/hash/coordinate-set.test.ts +66 -0
  78. package/test/unit/data-structures/hash/hash-map.test.ts +103 -0
  79. package/test/unit/data-structures/hash/hash-table.test.ts +186 -0
  80. package/test/unit/data-structures/heap/heap.test.ts +254 -0
  81. package/test/unit/data-structures/heap/max-heap.test.ts +52 -0
  82. package/test/unit/data-structures/heap/min-heap.test.ts +52 -0
  83. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +400 -0
  84. package/test/unit/data-structures/linked-list/linked-list.test.ts +8 -0
  85. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +474 -0
  86. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  87. package/test/unit/data-structures/linked-list/skip-list.test.ts +86 -0
  88. package/test/unit/data-structures/matrix/matrix.test.ts +54 -0
  89. package/test/unit/data-structures/matrix/matrix2d.test.ts +345 -0
  90. package/test/unit/data-structures/matrix/navigator.test.ts +244 -0
  91. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  92. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +73 -0
  93. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +63 -0
  94. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +53 -0
  95. package/test/unit/data-structures/queue/deque.test.ts +410 -0
  96. package/test/unit/data-structures/queue/queue.test.ts +207 -0
  97. package/test/unit/data-structures/stack/stack.test.ts +67 -0
  98. package/test/unit/data-structures/tree/tree.test.ts +39 -0
  99. package/test/unit/data-structures/trie/trie.test.ts +825 -0
  100. package/test/utils/array.ts +5514 -0
  101. package/test/utils/big-o.ts +207 -0
  102. package/test/utils/console.ts +31 -0
  103. package/test/utils/index.ts +7 -0
  104. package/test/utils/is.ts +56 -0
  105. package/test/utils/json2html.ts +322 -0
  106. package/test/utils/number.ts +13 -0
  107. package/test/utils/string.ts +1 -0
@@ -0,0 +1,400 @@
1
+ import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
2
+
3
+ describe('DoublyLinkedListNode', () => {
4
+ it('should DoublyLinkedListNode', () => {
5
+ const node1 = new DoublyLinkedListNode<number>(2);
6
+ expect(node1.value).toBe(2);
7
+ node1.value = 1;
8
+ expect(node1.value).toBe(1);
9
+ });
10
+ });
11
+
12
+ describe('DoublyLinkedList Operation Test', () => {
13
+ let list: DoublyLinkedList<number>;
14
+
15
+ beforeEach(() => {
16
+ list = DoublyLinkedList.fromArray([1, 2, 3, 4, 5]);
17
+ });
18
+
19
+ it('should out of bound index', () => {
20
+ expect(list.getNodeAt(-1)).toBe(null);
21
+ expect(list.getNodeAt(5)).toBe(null);
22
+ expect(list.insertAt(5, 6)).toBe(true);
23
+ });
24
+
25
+ it('should insertBefore', () => {
26
+ expect(list.insertBefore(1, 0)).toBe(true);
27
+ });
28
+
29
+ it('should deleteAt', () => {
30
+ expect(list.deleteAt(1)).toBeTruthy();
31
+ });
32
+
33
+ it('should delete tail', () => {
34
+ expect(list.delete(list.tail)).toBe(true);
35
+ expect(list.tail?.value).toBe(4);
36
+ expect(list.delete(6)).toBe(false);
37
+ expect(list.tail?.value).toBe(4);
38
+ });
39
+
40
+ it('should find null', () => {
41
+ expect(list.find(value => value === 6)).toBe(null);
42
+ });
43
+
44
+ it('should indexOf -1', () => {
45
+ expect(list.indexOf(6)).toBe(-1);
46
+ });
47
+
48
+ it('should findBackward null', () => {
49
+ expect(list.findBackward(value => value === 0)).toBe(null);
50
+ });
51
+
52
+ it('should insertAfter tail', () => {
53
+ expect(list.insertAfter(list.tail!, 6)).toBe(true);
54
+ });
55
+
56
+ it('should insertAfter tail', () => {
57
+ // @ts-ignore
58
+ expect([...list]).toEqual([1, 2, 3, 4, 5]);
59
+ });
60
+ });
61
+
62
+ describe('DoublyLinkedList Operation Test', () => {
63
+ let list: DoublyLinkedList<number>;
64
+ let objectList: DoublyLinkedList<{keyA: number}>;
65
+
66
+ beforeEach(() => {
67
+ list = new DoublyLinkedList();
68
+ objectList = new DoublyLinkedList();
69
+ });
70
+
71
+ it('should initialize an empty list', () => {
72
+ expect(list.length).toBe(0);
73
+ expect(list.head).toBeNull();
74
+ expect(list.tail).toBeNull();
75
+ });
76
+
77
+ it('should push elements to the list', () => {
78
+ list.push(1);
79
+ list.push(2);
80
+ list.push(3);
81
+ expect(list.length).toBe(3);
82
+ expect(list.head!.value).toBe(1);
83
+ expect(list.tail!.value).toBe(3);
84
+ });
85
+
86
+ it('should pop elements from the end of the list', () => {
87
+ list.push(1);
88
+ list.push(2);
89
+ const poppedValue = list.pop();
90
+ expect(poppedValue).toBe(2);
91
+ expect(list.length).toBe(1);
92
+ expect(list.head!.value).toBe(1);
93
+ expect(list.tail!.value).toBe(1);
94
+ });
95
+ it('should insert elements at specific positions', () => {
96
+ list.push(1);
97
+ list.push(2);
98
+ list.push(3);
99
+
100
+ // Inserting at the beginning
101
+ list.insertAt(0, 0);
102
+ expect(list.length).toBe(4);
103
+ expect(list.getAt(0)).toBe(0);
104
+ expect(list.getAt(1)).toBe(1);
105
+
106
+ // Inserting in the middle
107
+ list.insertAt(2, 1.5);
108
+ expect(list.length).toBe(5);
109
+ expect(list.getAt(2)).toBe(1.5);
110
+ expect(list.getAt(3)).toBe(2);
111
+
112
+ // Inserting at the end
113
+ list.insertAt(5, 4);
114
+ expect(list.length).toBe(6);
115
+ expect(list.getAt(5)).toBe(4);
116
+ expect(list.tail!.value).toBe(4);
117
+ });
118
+
119
+ it('should delete elements at specific positions', () => {
120
+ list.push(1);
121
+ list.push(2);
122
+ list.push(3);
123
+
124
+ // Deleting from the beginning
125
+ const deletedValue = list.deleteAt(0);
126
+ expect(deletedValue).toBe(1);
127
+ expect(list.length).toBe(2);
128
+ expect(list.head!.value).toBe(2);
129
+
130
+ // Deleting from the middle
131
+ list.deleteAt(0); // Deleting the second element
132
+ expect(list.length).toBe(1);
133
+ expect(list.head!.value).toBe(3);
134
+
135
+ // Deleting from the end
136
+ list.deleteAt(0);
137
+ expect(list.length).toBe(0);
138
+ expect(list.head).toBeNull();
139
+ expect(list.tail).toBeNull();
140
+ });
141
+
142
+ it('should delete elements by value', () => {
143
+ list.push(1);
144
+ list.push(2);
145
+ list.push(3);
146
+
147
+ list.delete(2);
148
+ expect(list.length).toBe(2);
149
+ expect(list.head!.value).toBe(1);
150
+ expect(list.tail!.value).toBe(3);
151
+
152
+ list.delete(1);
153
+ expect(list.length).toBe(1);
154
+ expect(list.head!.value).toBe(3);
155
+
156
+ list.delete(3);
157
+ expect(list.length).toBe(0);
158
+ expect(list.head).toBeNull();
159
+ expect(list.tail).toBeNull();
160
+ });
161
+
162
+ it('should reverse the linked list', () => {
163
+ list.push(1);
164
+ list.push(2);
165
+ list.push(3);
166
+
167
+ list.reverse();
168
+
169
+ expect(list.toArray()).toEqual([3, 2, 1]);
170
+ expect(list.toArrayBackward()).toEqual([1, 2, 3]);
171
+ });
172
+
173
+ it('should map elements using a callback function', () => {
174
+ list.push(1);
175
+ list.push(2);
176
+ list.push(3);
177
+
178
+ const mappedList = list.map(value => value * 2);
179
+
180
+ expect(mappedList.toArray()).toEqual([2, 4, 6]);
181
+ });
182
+
183
+ it('should filter elements using a callback function', () => {
184
+ list.push(1);
185
+ list.push(2);
186
+ list.push(3);
187
+ list.push(4);
188
+
189
+ const filteredList = list.filter(value => value % 2 === 0);
190
+
191
+ expect(filteredList.toArray()).toEqual([2, 4]);
192
+ });
193
+
194
+ it('should reduce elements using a callback function and an initial value', () => {
195
+ list.push(1);
196
+ list.push(2);
197
+ list.push(3);
198
+ list.push(4);
199
+
200
+ const sum = list.reduce((acc, value) => acc + value, 0);
201
+
202
+ expect(sum).toBe(10);
203
+ });
204
+
205
+ it('should insert an element after a specific value', () => {
206
+ list.push(1);
207
+ list.push(2);
208
+ list.push(3);
209
+
210
+ list.insertAfter(2, 2.5);
211
+
212
+ expect(list.toArray()).toEqual([1, 2, 2.5, 3]);
213
+ });
214
+
215
+ it('should insert an element before a specific value', () => {
216
+ list.push(1);
217
+ list.push(2);
218
+ list.push(3);
219
+
220
+ list.insertBefore(2, 1.5);
221
+
222
+ expect(list.toArray()).toEqual([1, 1.5, 2, 3]);
223
+ });
224
+ it('should find the first element that satisfies a condition', () => {
225
+ list.push(1);
226
+ list.push(2);
227
+ list.push(3);
228
+
229
+ const found = list.find(value => value % 2 === 0);
230
+
231
+ expect(found).toBe(2);
232
+ });
233
+
234
+ it('should find the index of an element', () => {
235
+ list.push(1);
236
+ list.push(2);
237
+ list.push(3);
238
+
239
+ const index = list.indexOf(2);
240
+
241
+ expect(index).toBe(1);
242
+ });
243
+
244
+ it('should find the last element that satisfies a condition', () => {
245
+ list.push(1);
246
+ list.push(2);
247
+ list.push(3);
248
+ list.push(4);
249
+
250
+ const lastEven = list.findBackward(value => value % 2 === 0);
251
+
252
+ expect(lastEven).toBe(4);
253
+ });
254
+
255
+ it('should clear the linked list', () => {
256
+ list.push(1);
257
+ list.push(2);
258
+ list.push(3);
259
+
260
+ list.clear();
261
+
262
+ expect(list.length).toBe(0);
263
+ expect(list.head).toBe(null);
264
+ expect(list.tail).toBe(null);
265
+ });
266
+
267
+ it('should create a reversed array of values', () => {
268
+ list.push(1);
269
+ list.push(2);
270
+ list.push(3);
271
+
272
+ const reversedArray = list.toArrayBackward();
273
+
274
+ expect(reversedArray).toEqual([3, 2, 1]);
275
+ });
276
+
277
+ it('should reverse the linked list', () => {
278
+ list.push(1);
279
+ list.push(2);
280
+ list.push(3);
281
+
282
+ list.reverse();
283
+
284
+ expect(list.toArray()).toEqual([3, 2, 1]);
285
+ expect(list.head?.value).toBe(3);
286
+ expect(list.tail?.value).toBe(1);
287
+ });
288
+
289
+ it('should iterate over each element and apply a callback', () => {
290
+ list.push(1);
291
+ list.push(2);
292
+ list.push(3);
293
+
294
+ const result: number[] = [];
295
+ list.forEach(value => {
296
+ result.push(value * 2);
297
+ });
298
+
299
+ expect(result).toEqual([2, 4, 6]);
300
+ });
301
+
302
+ it('should create a new linked list by applying a mapping function', () => {
303
+ list.push(1);
304
+ list.push(2);
305
+ list.push(3);
306
+
307
+ const mappedList = list.map(value => value * 2);
308
+
309
+ expect(mappedList.toArray()).toEqual([2, 4, 6]);
310
+ });
311
+
312
+ it('should create a new linked list by filtering elements', () => {
313
+ list.push(1);
314
+ list.push(2);
315
+ list.push(3);
316
+ list.push(4);
317
+
318
+ const filteredList = list.filter(value => value % 2 === 0);
319
+
320
+ expect(filteredList.toArray()).toEqual([2, 4]);
321
+ });
322
+
323
+ it('should reduce the linked list to a single value', () => {
324
+ list.push(1);
325
+ list.push(2);
326
+ list.push(3);
327
+
328
+ const sum = list.reduce((acc, value) => acc + value, 0);
329
+
330
+ expect(sum).toBe(6);
331
+ });
332
+
333
+ it('should insert a new value after an existing value', () => {
334
+ list.push(1);
335
+ list.push(2);
336
+ list.push(3);
337
+
338
+ const success = list.insertAfter(2, 4);
339
+ expect(success).toBe(true);
340
+ expect(list.toArray()).toEqual([1, 2, 4, 3]);
341
+ });
342
+
343
+ it('should insert a new value before an existing value', () => {
344
+ list.push(1);
345
+ list.push(2);
346
+ list.push(3);
347
+
348
+ const success = list.insertBefore(2, 0);
349
+ expect(success).toBe(true);
350
+ expect(list.toArray()).toEqual([1, 0, 2, 3]);
351
+ });
352
+
353
+ it('should not insert a new value after a non-existing value', () => {
354
+ list.push(1);
355
+ list.push(2);
356
+ list.push(3);
357
+
358
+ const success = list.insertAfter(4, 5);
359
+ expect(success).toBe(false);
360
+ expect(list.toArray()).toEqual([1, 2, 3]);
361
+ });
362
+
363
+ it('should not insert a new value before a non-existing value', () => {
364
+ list.push(1);
365
+ list.push(2);
366
+ list.push(3);
367
+
368
+ const success = list.insertBefore(4, 0);
369
+ expect(success).toBe(false);
370
+ expect(list.toArray()).toEqual([1, 2, 3]);
371
+ });
372
+
373
+ it('should insert and manipulate objects with numeric properties', () => {
374
+ const obj1 = {keyA: 10};
375
+ const obj2 = {keyA: 20};
376
+ const obj3 = {keyA: 30};
377
+
378
+ objectList.push(obj1);
379
+ objectList.push(obj2);
380
+ objectList.push(obj3);
381
+
382
+ expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
383
+
384
+ const newObj = {keyA: 25}; // Corrected newObj value
385
+ const insertSuccess = objectList.insertBefore(obj2, newObj);
386
+ expect(insertSuccess).toBe(true);
387
+
388
+ const getNode = objectList.getNode(newObj); // Use newObj instead of obj2
389
+ expect(getNode?.value).toEqual(newObj);
390
+
391
+ const deleted = objectList.delete(newObj); // Use newObj instead of obj2
392
+ expect(deleted).toBe(true);
393
+
394
+ const poppedObj = objectList.pop();
395
+ expect(poppedObj).toBe(obj3);
396
+
397
+ const shiftedObj = objectList.shift();
398
+ expect(shiftedObj).toBe(obj1);
399
+ });
400
+ });
@@ -0,0 +1,8 @@
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
+ expect(1).toBe(1);
7
+ });
8
+ });