data-structure-typed 1.49.1 → 1.49.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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/README_zh-CN.md +2 -2
  4. package/benchmark/report.html +46 -1
  5. package/benchmark/report.json +457 -22
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
  7. package/dist/cjs/data-structures/base/iterable-base.js +21 -0
  8. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +7 -7
  10. package/dist/cjs/data-structures/graph/abstract-graph.js +43 -12
  11. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  13. package/dist/cjs/data-structures/graph/directed-graph.js +2 -2
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
  17. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/hash/hash-map.d.ts +9 -9
  19. package/dist/cjs/data-structures/hash/hash-map.js +16 -15
  20. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  21. package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
  22. package/dist/cjs/data-structures/heap/heap.js +10 -42
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
  25. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +143 -146
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
  29. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  30. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  31. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
  32. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  33. package/dist/cjs/data-structures/queue/deque.d.ts +70 -75
  34. package/dist/cjs/data-structures/queue/deque.js +100 -110
  35. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  36. package/dist/cjs/data-structures/queue/queue.d.ts +37 -38
  37. package/dist/cjs/data-structures/queue/queue.js +46 -49
  38. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  39. package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
  40. package/dist/cjs/data-structures/stack/stack.js +2 -5
  41. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  42. package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
  43. package/dist/cjs/data-structures/trie/trie.js +2 -5
  44. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  45. package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
  46. package/dist/mjs/data-structures/base/iterable-base.js +21 -0
  47. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +7 -7
  48. package/dist/mjs/data-structures/graph/abstract-graph.js +43 -12
  49. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  50. package/dist/mjs/data-structures/graph/directed-graph.js +2 -2
  51. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
  52. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
  53. package/dist/mjs/data-structures/hash/hash-map.d.ts +9 -9
  54. package/dist/mjs/data-structures/hash/hash-map.js +16 -15
  55. package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
  56. package/dist/mjs/data-structures/heap/heap.js +10 -42
  57. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
  58. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +142 -145
  59. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  60. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
  61. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  62. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
  63. package/dist/mjs/data-structures/queue/deque.d.ts +70 -75
  64. package/dist/mjs/data-structures/queue/deque.js +100 -110
  65. package/dist/mjs/data-structures/queue/queue.d.ts +37 -38
  66. package/dist/mjs/data-structures/queue/queue.js +45 -48
  67. package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
  68. package/dist/mjs/data-structures/stack/stack.js +2 -5
  69. package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
  70. package/dist/mjs/data-structures/trie/trie.js +2 -5
  71. package/dist/umd/data-structure-typed.js +531 -532
  72. package/dist/umd/data-structure-typed.min.js +2 -2
  73. package/dist/umd/data-structure-typed.min.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/data-structures/base/iterable-base.ts +24 -0
  76. package/src/data-structures/graph/abstract-graph.ts +55 -14
  77. package/src/data-structures/graph/directed-graph.ts +3 -2
  78. package/src/data-structures/graph/undirected-graph.ts +1 -1
  79. package/src/data-structures/hash/hash-map.ts +27 -28
  80. package/src/data-structures/heap/heap.ts +19 -57
  81. package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
  82. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  83. package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
  84. package/src/data-structures/queue/deque.ts +122 -135
  85. package/src/data-structures/queue/queue.ts +54 -58
  86. package/src/data-structures/stack/stack.ts +4 -8
  87. package/src/data-structures/trie/trie.ts +5 -9
  88. package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
  89. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  90. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  91. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  92. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
  93. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  94. package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
  95. package/test/unit/data-structures/graph/directed-graph.test.ts +48 -3
  96. package/test/unit/data-structures/graph/undirected-graph.test.ts +48 -4
  97. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  98. package/test/unit/data-structures/heap/heap.test.ts +6 -1
  99. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  100. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  101. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  102. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
  103. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  104. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  105. package/test/unit/data-structures/queue/queue.test.ts +4 -4
  106. package/test/unit/data-structures/trie/trie.test.ts +1 -1
@@ -84,12 +84,12 @@ describe('SinglyLinkedList Operation Test', () => {
84
84
  });
85
85
  });
86
86
 
87
- describe('insertAfter', () => {
87
+ describe('addAfter', () => {
88
88
  it('should insert an element after an existing value', () => {
89
89
  list.push(1);
90
90
  list.push(2);
91
91
  list.push(3);
92
- list.insertAfter(2, 4);
92
+ list.addAfter(2, 4);
93
93
  expect(list.toArray()).toEqual([1, 2, 4, 3]);
94
94
  });
95
95
 
@@ -97,7 +97,7 @@ describe('SinglyLinkedList Operation Test', () => {
97
97
  list.push(1);
98
98
  list.push(2);
99
99
  list.push(3);
100
- const result = list.insertAfter(5, 4);
100
+ const result = list.addAfter(5, 4);
101
101
  expect(result).toBe(false);
102
102
  expect(list.toArray()).toEqual([1, 2, 3]);
103
103
  });
@@ -164,7 +164,7 @@ describe('SinglyLinkedList Operation Test', () => {
164
164
  list.push(3);
165
165
  list.clear();
166
166
  expect(list.toArray()).toEqual([]);
167
- expect(list.length).toBe(0);
167
+ expect(list.size).toBe(0);
168
168
  expect(list.isEmpty()).toBe(true);
169
169
  });
170
170
  });
@@ -223,19 +223,19 @@ describe('SinglyLinkedList Operation Test', () => {
223
223
  });
224
224
  });
225
225
 
226
- describe('insertBefore', () => {
226
+ describe('addBefore', () => {
227
227
  it('should insert an element before an existing value', () => {
228
228
  list.push(1);
229
229
  list.push(2);
230
230
  list.push(3);
231
- list.insertBefore(2, 4);
231
+ list.addBefore(2, 4);
232
232
  expect(list.toArray()).toEqual([1, 4, 2, 3]);
233
233
  });
234
234
 
235
235
  it('should insert an element at the beginning', () => {
236
236
  list.push(1);
237
237
  list.push(2);
238
- list.insertBefore(1, 3);
238
+ list.addBefore(1, 3);
239
239
  expect(list.toArray()).toEqual([3, 1, 2]);
240
240
  });
241
241
 
@@ -243,7 +243,7 @@ describe('SinglyLinkedList Operation Test', () => {
243
243
  list.push(1);
244
244
  list.push(2);
245
245
  list.push(3);
246
- const result = list.insertBefore(5, 4);
246
+ const result = list.addBefore(5, 4);
247
247
  expect(result).toBe(false);
248
248
  expect(list.toArray()).toEqual([1, 2, 3]);
249
249
  });
@@ -251,10 +251,10 @@ describe('SinglyLinkedList Operation Test', () => {
251
251
 
252
252
  describe('getLength', () => {
253
253
  it('should return the correct length of the list', () => {
254
- expect(list.length).toBe(0);
254
+ expect(list.size).toBe(0);
255
255
  list.push(1);
256
256
  list.push(2);
257
- expect(list.length).toBe(2);
257
+ expect(list.size).toBe(2);
258
258
  });
259
259
  });
260
260
 
@@ -264,21 +264,21 @@ describe('SinglyLinkedList Operation Test', () => {
264
264
  list.push(2);
265
265
  list.push(3);
266
266
  const removed = list.deleteAt(1);
267
- expect(removed).toBe(2);
267
+ expect(removed).toBe(true);
268
268
  expect(list.toArray()).toEqual([1, 3]);
269
269
  });
270
270
 
271
271
  it('should return undefined for an out-of-bounds index', () => {
272
272
  list.push(1);
273
273
  const removed = list.deleteAt(1);
274
- expect(removed).toBeUndefined();
274
+ expect(removed).toBe(false);
275
275
  });
276
276
 
277
277
  it('should delete and return the first element', () => {
278
278
  list.push(1);
279
279
  list.push(2);
280
280
  const removed = list.deleteAt(0);
281
- expect(removed).toBe(1);
281
+ expect(removed).toBe(true);
282
282
  expect(list.toArray()).toEqual([2]);
283
283
  });
284
284
 
@@ -286,7 +286,7 @@ describe('SinglyLinkedList Operation Test', () => {
286
286
  list.push(1);
287
287
  list.push(2);
288
288
  const removed = list.deleteAt(1);
289
- expect(removed).toBe(2);
289
+ expect(removed).toBe(true);
290
290
  expect(list.toArray()).toEqual([1]);
291
291
  });
292
292
  });
@@ -313,9 +313,9 @@ describe('SinglyLinkedList Operation Test', () => {
313
313
 
314
314
  describe('insert and toArray', () => {
315
315
  it('should insert elements and return array correctly', () => {
316
- list.insertAt(0, 1);
317
- list.insertAt(1, 3);
318
- list.insertAt(1, 2);
316
+ list.addAt(0, 1);
317
+ list.addAt(1, 3);
318
+ list.addAt(1, 2);
319
319
  expect(list.toArray()).toEqual([1, 2, 3]);
320
320
  });
321
321
  });
@@ -377,7 +377,7 @@ describe('SinglyLinkedList Operation Test', () => {
377
377
  expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
378
378
 
379
379
  const newObj = { keyA: 2.5 }; // Corrected newObj value
380
- const insertSuccess = objectList.insertBefore(obj2, newObj);
380
+ const insertSuccess = objectList.addBefore(obj2, newObj);
381
381
  expect(insertSuccess).toBe(true);
382
382
 
383
383
  const getNode = objectList.getNode(newObj); // Use newObj instead of obj2
@@ -404,7 +404,7 @@ describe('SinglyLinkedList', () => {
404
404
  it('should initialize an empty list', () => {
405
405
  expect(list.head).toBe(undefined);
406
406
  expect(list.tail).toBe(undefined);
407
- expect(list.length).toBe(0);
407
+ expect(list.size).toBe(0);
408
408
  });
409
409
 
410
410
  it('should push elements to the end of the list', () => {
@@ -412,7 +412,7 @@ describe('SinglyLinkedList', () => {
412
412
  list.push(2);
413
413
  expect(list.head!.value).toBe(1);
414
414
  expect(list.tail!.value).toBe(2);
415
- expect(list.length).toBe(2);
415
+ expect(list.size).toBe(2);
416
416
  });
417
417
 
418
418
  it('should pop elements from the end of the list', () => {
@@ -422,7 +422,7 @@ describe('SinglyLinkedList', () => {
422
422
  expect(popped).toBe(2);
423
423
  expect(list.head!.value).toBe(1);
424
424
  expect(list.tail!.value).toBe(1);
425
- expect(list.length).toBe(1);
425
+ expect(list.size).toBe(1);
426
426
  });
427
427
 
428
428
  it('should reverse the list', () => {
@@ -66,11 +66,11 @@ describe('SkipList', () => {
66
66
  });
67
67
 
68
68
  it('getFirst() should return the getFirst element', () => {
69
- expect(skipList.getFirst()).toBe('One');
69
+ expect(skipList.first).toBe('One');
70
70
  });
71
71
 
72
72
  it('getLast() should return the getLast element', () => {
73
- expect(skipList.getLast()).toBe('Four');
73
+ expect(skipList.last).toBe('Four');
74
74
  });
75
75
 
76
76
  it('higher(key) should return the getFirst element greater than the given key', () => {
@@ -1,7 +1,7 @@
1
1
  import { Deque } from '../../../../src';
2
- import { isDebugTest } from '../../../config';
2
+ // import { isDebugTest } from '../../../config';
3
3
 
4
- const isDebug = isDebugTest;
4
+ // const isDebug = isDebugTest;
5
5
 
6
6
  describe('Deque - Basic Operations', () => {
7
7
  let deque: Deque<number>;
@@ -57,10 +57,10 @@ describe('Deque - Complex Operations', () => {
57
57
  deque = new Deque<number>();
58
58
  });
59
59
 
60
- test('insertAt should insert elements at the specified position', () => {
60
+ test('addAt should insert elements at the specified position', () => {
61
61
  deque.push(1);
62
62
  deque.push(3);
63
- deque.insertAt(1, 2);
63
+ deque.addAt(1, 2);
64
64
  expect(deque.toArray()).toEqual([1, 2, 3]);
65
65
  });
66
66
 
@@ -111,7 +111,7 @@ describe('Deque - Complex Operations', () => {
111
111
  deque.push(1);
112
112
  deque.push(2);
113
113
  deque.sort((a, b) => a - b);
114
- expect(deque.toArray()).toEqual([1, 2, 3]);
114
+ expect([...deque]).toEqual([1, 2, 3]);
115
115
  });
116
116
 
117
117
  test('shrinkToFit should reduce the memory footprint', () => {
@@ -1,7 +1,7 @@
1
1
  import { LinkedListQueue, Queue } from '../../../../src';
2
- import { isDebugTest } from '../../../config';
2
+ // import { isDebugTest } from '../../../config';
3
3
 
4
- const isDebug = isDebugTest;
4
+ // const isDebug = isDebugTest;
5
5
 
6
6
  describe('Queue', () => {
7
7
  let queue: Queue<number>;
@@ -224,7 +224,7 @@ describe('LinkedListQueue', () => {
224
224
  queue.enqueue('A');
225
225
  queue.enqueue('B');
226
226
  expect(queue.peek()).toBe('A');
227
- expect(queue.length).toBe(2);
227
+ expect(queue.size).toBe(2);
228
228
  });
229
229
 
230
230
  it('should dequeue elements from the front of the queue', () => {
@@ -233,7 +233,7 @@ describe('LinkedListQueue', () => {
233
233
  const dequeued = queue.dequeue();
234
234
  expect(dequeued).toBe('A');
235
235
  expect(queue.peek()).toBe('B');
236
- expect(queue.length).toBe(1);
236
+ expect(queue.size).toBe(1);
237
237
  });
238
238
 
239
239
  it('should peek at the front of the queue', () => {
@@ -843,7 +843,7 @@ describe('Trie class', () => {
843
843
 
844
844
  test('filter should return words that satisfy the predicate', () => {
845
845
  const filteredWords = trie.filter(word => word.startsWith('ba'));
846
- expect(filteredWords).toEqual(['banana', 'band', 'bandana']);
846
+ expect([...filteredWords]).toEqual(['banana', 'band', 'bandana']);
847
847
  });
848
848
 
849
849
  test('map should apply a function to each word', () => {