data-structure-typed 1.49.4 → 1.49.5

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 (154) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -3
  3. package/README_zh-CN.md +1 -1
  4. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  5. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  13. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  17. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  22. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  23. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/heap.js +2 -3
  25. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  26. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  29. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  31. package/dist/cjs/data-structures/matrix/index.js +0 -2
  32. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  33. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  34. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  35. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  36. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  37. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  38. package/dist/cjs/data-structures/queue/deque.js +5 -7
  39. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  40. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  42. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  43. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  44. package/dist/cjs/utils/utils.d.ts +1 -0
  45. package/dist/cjs/utils/utils.js +6 -1
  46. package/dist/cjs/utils/utils.js.map +1 -1
  47. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  48. package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
  49. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
  50. package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
  51. package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
  52. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
  53. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  54. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
  55. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  56. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  57. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  58. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  59. package/dist/mjs/data-structures/heap/heap.js +2 -3
  60. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  61. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  62. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  63. package/dist/mjs/data-structures/matrix/index.js +0 -2
  64. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  65. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  66. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  67. package/dist/mjs/data-structures/queue/deque.js +7 -9
  68. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  69. package/dist/mjs/data-structures/queue/queue.js +1 -1
  70. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  71. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  72. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  73. package/dist/mjs/utils/utils.d.ts +1 -0
  74. package/dist/mjs/utils/utils.js +4 -0
  75. package/dist/umd/data-structure-typed.js +356 -524
  76. package/dist/umd/data-structure-typed.min.js +2 -2
  77. package/dist/umd/data-structure-typed.min.js.map +1 -1
  78. package/package.json +4 -3
  79. package/src/data-structures/base/index.ts +1 -1
  80. package/src/data-structures/base/iterable-base.ts +7 -10
  81. package/src/data-structures/binary-tree/avl-tree.ts +15 -8
  82. package/src/data-structures/binary-tree/binary-tree.ts +57 -74
  83. package/src/data-structures/binary-tree/bst.ts +16 -13
  84. package/src/data-structures/binary-tree/rb-tree.ts +16 -10
  85. package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
  86. package/src/data-structures/graph/abstract-graph.ts +13 -11
  87. package/src/data-structures/graph/directed-graph.ts +1 -3
  88. package/src/data-structures/graph/map-graph.ts +6 -1
  89. package/src/data-structures/graph/undirected-graph.ts +3 -6
  90. package/src/data-structures/hash/hash-map.ts +18 -16
  91. package/src/data-structures/heap/heap.ts +7 -10
  92. package/src/data-structures/heap/max-heap.ts +2 -1
  93. package/src/data-structures/heap/min-heap.ts +2 -1
  94. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  95. package/src/data-structures/matrix/index.ts +0 -2
  96. package/src/data-structures/matrix/matrix.ts +442 -13
  97. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  98. package/src/data-structures/queue/deque.ts +18 -39
  99. package/src/data-structures/queue/queue.ts +1 -1
  100. package/src/interfaces/binary-tree.ts +7 -2
  101. package/src/types/common.ts +4 -4
  102. package/src/types/data-structures/base/base.ts +14 -3
  103. package/src/types/data-structures/base/index.ts +1 -1
  104. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  105. package/src/types/data-structures/hash/hash-map.ts +3 -3
  106. package/src/types/data-structures/heap/heap.ts +2 -2
  107. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  108. package/src/utils/utils.ts +7 -1
  109. package/test/integration/avl-tree.test.ts +18 -1
  110. package/test/integration/bst.test.ts +2 -2
  111. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
  112. package/test/performance/data-structures/comparison/comparison.test.ts +6 -11
  113. package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
  114. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
  115. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  116. package/test/performance/data-structures/queue/queue.test.ts +10 -9
  117. package/test/performance/reportor.ts +14 -15
  118. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  119. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +59 -24
  120. package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
  121. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  122. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  123. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  124. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  125. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  126. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  127. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  128. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  129. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  130. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  131. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  132. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  133. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  134. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  135. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  136. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  137. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  138. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  139. package/test/utils/performanc.ts +1 -1
  140. package/typedoc.json +30 -0
  141. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  142. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  143. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  144. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  145. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  146. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  147. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  148. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  149. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  150. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  151. package/src/data-structures/matrix/matrix2d.ts +0 -211
  152. package/src/data-structures/matrix/vector2d.ts +0 -315
  153. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  154. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -54,7 +54,6 @@ describe('HashMap Test1', () => {
54
54
  hashMap.set('one', 1);
55
55
  hashMap.set('two', 2);
56
56
  hashMap.set('three', 3);
57
-
58
57
  });
59
58
 
60
59
  it('should resize the table when load factor is exceeded', () => {
@@ -181,7 +180,6 @@ describe('HashMap Test2', () => {
181
180
  }
182
181
  compareHashMaps(hashMap, stdMap);
183
182
  });
184
-
185
183
  });
186
184
 
187
185
  describe('HashMap for coordinate object keys', () => {
@@ -207,30 +205,39 @@ describe('HashMap for coordinate object keys', () => {
207
205
 
208
206
  test('delete elements in hash map', () => {
209
207
  for (let i = 0; i < 1000; i++) {
210
- if (i === 500) expect(hashMap.size).toBe(500)
208
+ if (i === 500) expect(hashMap.size).toBe(500);
211
209
  const codObj = codObjs[i];
212
210
  if (codObj) hashMap.delete(codObj);
213
211
  }
214
212
  expect(hashMap.size).toBe(0);
215
213
  });
216
-
217
214
  });
218
215
 
219
216
  describe('HashMap setMany, keys, values', () => {
220
217
  const hm: HashMap<number, number> = new HashMap<number, number>();
221
218
 
222
219
  beforeEach(() => {
223
- hm.clear()
224
- hm.setMany([[2, 2], [3, 3], [4, 4], [5, 5]])
225
- hm.setMany([[2, 2], [3, 3], [4, 4], [6, 6]])
226
- })
220
+ hm.clear();
221
+ hm.setMany([
222
+ [2, 2],
223
+ [3, 3],
224
+ [4, 4],
225
+ [5, 5]
226
+ ]);
227
+ hm.setMany([
228
+ [2, 2],
229
+ [3, 3],
230
+ [4, 4],
231
+ [6, 6]
232
+ ]);
233
+ });
227
234
 
228
235
  test('keys', () => {
229
- expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
236
+ expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
230
237
  });
231
238
 
232
239
  test('values', () => {
233
- expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
240
+ expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
234
241
  });
235
242
  });
236
243
 
@@ -245,7 +252,7 @@ describe('HashMap HOF', () => {
245
252
  });
246
253
 
247
254
  test('every() returns true if all elements match the condition', () => {
248
- expect(hashMap.every((value) => typeof value === 'string')).toBe(true);
255
+ expect(hashMap.every(value => typeof value === 'string')).toBe(true);
249
256
  });
250
257
 
251
258
  test('some() returns true if any element matches the condition', () => {
@@ -259,7 +266,7 @@ describe('HashMap HOF', () => {
259
266
  });
260
267
 
261
268
  test('map() should transform each element', () => {
262
- const newHashMap = hashMap.map((value) => value.toUpperCase());
269
+ const newHashMap = hashMap.map(value => value.toUpperCase());
263
270
  expect(newHashMap.get('key1')).toBe('VALUE1');
264
271
  });
265
272
 
@@ -274,7 +281,6 @@ describe('HashMap HOF', () => {
274
281
  });
275
282
  });
276
283
 
277
-
278
284
  describe('LinkedHashMap Test1', () => {
279
285
  let hashMap: LinkedHashMap<string, number>;
280
286
 
@@ -368,7 +374,6 @@ describe('LinkedHashMap Test1', () => {
368
374
  // expect(hashMap.table[0].length).toBe(2);
369
375
  });
370
376
 
371
-
372
377
  // it('should handle number keys correctly', () => {
373
378
  // const hm = new LinkedHashMap();
374
379
  // hm.set(999, { a: '999Value' });
@@ -529,50 +534,65 @@ describe('LinkedHashMap for coordinate object keys', () => {
529
534
 
530
535
  test('delete elements in hash map', () => {
531
536
  for (let i = 0; i < 1000; i++) {
532
- if (i === 500) expect(hashMap.size).toBe(500)
537
+ if (i === 500) expect(hashMap.size).toBe(500);
533
538
  const codObj = codObjs[i];
534
539
  if (codObj) hashMap.delete(codObj);
535
540
  }
536
541
  expect(hashMap.size).toBe(0);
537
542
  });
538
-
539
543
  });
540
544
 
541
545
  describe('LinkedHashMap setMany, keys, values', () => {
542
546
  const hm: LinkedHashMap<number, number> = new LinkedHashMap<number, number>();
543
547
 
544
548
  beforeEach(() => {
545
- hm.clear()
546
- hm.setMany([[2, 2], [3, 3], [4, 4], [5, 5]])
547
- hm.setMany([[2, 2], [3, 3], [4, 4], [6, 6]])
548
- })
549
+ hm.clear();
550
+ hm.setMany([
551
+ [2, 2],
552
+ [3, 3],
553
+ [4, 4],
554
+ [5, 5]
555
+ ]);
556
+ hm.setMany([
557
+ [2, 2],
558
+ [3, 3],
559
+ [4, 4],
560
+ [6, 6]
561
+ ]);
562
+ });
549
563
 
550
564
  test('keys', () => {
551
- expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
565
+ expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
552
566
  });
553
567
 
554
568
  test('values', () => {
555
- expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
569
+ expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
556
570
  });
557
571
 
558
572
  test('entries', () => {
559
- expect([...hm.entries()]).toEqual([[2, 2], [3, 3], [4, 4], [5, 5], [6, 6]])
573
+ expect([...hm.entries()]).toEqual([
574
+ [2, 2],
575
+ [3, 3],
576
+ [4, 4],
577
+ [5, 5],
578
+ [6, 6]
579
+ ]);
560
580
  });
561
581
 
562
582
  test('every', () => {
563
- expect(hm.every(value => value > 4)).toBe(false)
583
+ expect(hm.every(value => value > 4)).toBe(false);
564
584
  });
565
585
 
566
586
  test('some', () => {
567
- expect(hm.some(value => value > 6)).toBe(false)
587
+ expect(hm.some(value => value > 6)).toBe(false);
568
588
  });
569
589
 
570
590
  test('hasValue', () => {
571
- expect(hm.hasValue(3)).toBe(true)
572
- expect(hm.hasValue(7)).toBe(false)
591
+ expect(hm.hasValue(3)).toBe(true);
592
+ expect(hm.hasValue(7)).toBe(false);
573
593
  });
574
594
 
575
595
  test('print', () => {
576
596
  hm.print();
577
597
  });
578
- });
598
+ });
@@ -185,7 +185,6 @@ describe('HashTable performance', function () {
185
185
  });
186
186
  });
187
187
 
188
-
189
188
  describe('HashTable methods', () => {
190
189
  let hashTable: HashTable<string, string>;
191
190
 
@@ -215,7 +214,6 @@ describe('HashTable methods', () => {
215
214
  // }
216
215
  // });
217
216
 
218
-
219
217
  test('filter should return a new HashTable with elements that satisfy the condition', () => {
220
218
  const filtered = hashTable.filter(([key]) => key.endsWith('1') || key.endsWith('3'));
221
219
 
@@ -237,6 +235,4 @@ describe('HashTable methods', () => {
237
235
 
238
236
  expect(result).toBe('-value5-value7-value3-value4-value6-value0-value2-value8-value1-value9');
239
237
  });
240
-
241
238
  });
242
-
@@ -1,7 +1,6 @@
1
1
  import { FibonacciHeap, MaxHeap, MinHeap } from '../../../../src';
2
2
  import { logBigOMetricsWrap } from '../../../utils';
3
3
 
4
-
5
4
  describe('Heap Operation Test', () => {
6
5
  it('should numeric heap work well', function () {
7
6
  const minNumHeap = new MinHeap<number>();
@@ -50,17 +50,15 @@ describe('MinHeap', () => {
50
50
  expect(minHeap.isEmpty()).toBe(true);
51
51
  });
52
52
 
53
-
54
53
  const n = 100000;
55
54
 
56
55
  it('should push & dfs', () => {
57
56
  for (let i = 0; i < n; i++) {
58
57
  minHeap.add(i);
59
58
  }
60
- expect(minHeap.dfs()[0]).toBe(0)
61
- expect(minHeap.dfs()[999]).toBe(4126)
59
+ expect(minHeap.dfs()[0]).toBe(0);
60
+ expect(minHeap.dfs()[999]).toBe(4126);
62
61
  });
63
-
64
62
  });
65
63
 
66
64
  describe('Heap iterative methods', () => {
@@ -89,7 +87,10 @@ describe('Heap iterative methods', () => {
89
87
  });
90
88
 
91
89
  test('map method correctly maps elements', () => {
92
- const result = heap.map(x => x / 10, (a: number, b: number) => a - b);
90
+ const result = heap.map(
91
+ x => x / 10,
92
+ (a: number, b: number) => a - b
93
+ );
93
94
  expect([...result]).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
94
95
  });
95
96
 
@@ -398,16 +398,15 @@ describe('DoublyLinkedList Operation Test', () => {
398
398
  });
399
399
  });
400
400
 
401
-
402
401
  describe('iterable methods', () => {
403
402
  it('should forEach, some, every, filter, map, reduce of the deque', () => {
404
- const dl = new DoublyLinkedList<number>()
403
+ const dl = new DoublyLinkedList<number>();
405
404
  dl.push(1);
406
405
  dl.push(2);
407
406
  dl.push(3);
408
407
 
409
408
  const mockCallback = jest.fn();
410
- dl.forEach((element) => {
409
+ dl.forEach(element => {
411
410
  mockCallback(element);
412
411
  });
413
412
 
@@ -426,7 +425,7 @@ describe('iterable methods', () => {
426
425
  });
427
426
 
428
427
  test('values', () => {
429
- const dl = new DoublyLinkedList<number>()
428
+ const dl = new DoublyLinkedList<number>();
430
429
  dl.push(1);
431
430
  dl.push(2);
432
431
  dl.push(3);
@@ -435,11 +434,11 @@ describe('iterable methods', () => {
435
434
  dl.shift();
436
435
  dl.pop();
437
436
  dl.unshift(3);
438
- expect([...dl.values()]).toEqual([3, 1])
439
- })
437
+ expect([...dl.values()]).toEqual([3, 1]);
438
+ });
440
439
 
441
440
  test('some', () => {
442
- const dl = new DoublyLinkedList<number>()
441
+ const dl = new DoublyLinkedList<number>();
443
442
  dl.push(1);
444
443
  dl.push(2);
445
444
  dl.push(3);
@@ -448,7 +447,7 @@ describe('iterable methods', () => {
448
447
  dl.shift();
449
448
  dl.pop();
450
449
  dl.unshift(3);
451
- expect(dl.some(value => value > 1)).toBe(true)
452
- expect(dl.some(value => value > 100)).toBe(false)
453
- })
454
- });
450
+ expect(dl.some(value => value > 1)).toBe(true);
451
+ expect(dl.some(value => value > 100)).toBe(false);
452
+ });
453
+ });
@@ -472,13 +472,12 @@ describe('SinglyLinkedList', () => {
472
472
  });
473
473
  });
474
474
 
475
-
476
475
  describe('iterable methods', () => {
477
476
  it('should forEach, some, every, filter, map, reduce of the deque', () => {
478
- const sl = new SinglyLinkedList<number>([1, 2, 3])
477
+ const sl = new SinglyLinkedList<number>([1, 2, 3]);
479
478
 
480
479
  const mockCallback = jest.fn();
481
- sl.forEach((element) => {
480
+ sl.forEach(element => {
482
481
  mockCallback(element);
483
482
  });
484
483
 
@@ -495,4 +494,4 @@ describe('iterable methods', () => {
495
494
  expect([...sl.map(element => element * 2)]).toEqual([2, 4, 6]);
496
495
  expect(sl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
497
496
  });
498
- });
497
+ });