data-structure-typed 1.51.1 → 1.51.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 (30) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +208 -185
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +158 -146
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +16 -10
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +31 -25
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +27 -1
  9. package/dist/cjs/data-structures/binary-tree/bst.js +29 -0
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -47
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -61
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +16 -10
  15. package/dist/mjs/data-structures/binary-tree/binary-tree.js +31 -25
  16. package/dist/mjs/data-structures/binary-tree/bst.d.ts +27 -1
  17. package/dist/mjs/data-structures/binary-tree/bst.js +28 -0
  18. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -47
  19. package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -60
  20. package/dist/umd/data-structure-typed.js +66 -86
  21. package/dist/umd/data-structure-typed.min.js +2 -2
  22. package/dist/umd/data-structure-typed.min.js.map +1 -1
  23. package/package.json +92 -69
  24. package/src/data-structures/binary-tree/binary-tree.ts +33 -28
  25. package/src/data-structures/binary-tree/bst.ts +36 -1
  26. package/src/data-structures/binary-tree/rb-tree.ts +6 -72
  27. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -0
  28. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +4 -0
  29. package/test/unit/data-structures/binary-tree/overall.test.ts +2 -2
  30. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +40 -40
@@ -74,7 +74,7 @@ describe('RedBlackTree 1', () => {
74
74
 
75
75
  it('should handle an empty rbTree', () => {
76
76
  const minNode = rbTree.getLeftMost(rbTree.root);
77
- expect(minNode).toBe(rbTree.SENTINEL);
77
+ expect(minNode).toBe(rbTree.NIL);
78
78
  });
79
79
  });
80
80
 
@@ -92,7 +92,7 @@ describe('RedBlackTree 1', () => {
92
92
 
93
93
  it('should handle an empty rbTree', () => {
94
94
  const maxNode = rbTree.getRightMost(rbTree.root);
95
- expect(maxNode).toBe(rbTree.SENTINEL);
95
+ expect(maxNode).toBe(rbTree.NIL);
96
96
  });
97
97
  });
98
98
 
@@ -116,7 +116,7 @@ describe('RedBlackTree 1', () => {
116
116
 
117
117
  const node = rbTree.getNode(10);
118
118
  const successorNode = rbTree.getSuccessor(node!);
119
- // TODO not sure if it should be undefined or rbTree.SENTINEL
119
+ // TODO not sure if it should be undefined or rbTree.NIL
120
120
  expect(successorNode).toBe(undefined);
121
121
  });
122
122
  });
@@ -141,7 +141,7 @@ describe('RedBlackTree 1', () => {
141
141
 
142
142
  const node = rbTree.getNode(20);
143
143
  const predecessorNode = rbTree.getPredecessor(node!);
144
- // TODO not sure if it should be rbTree.SENTINEL or something else.
144
+ // TODO not sure if it should be rbTree.NIL or something else.
145
145
  expect(predecessorNode).toBe(rbTree.getNode(20));
146
146
  });
147
147
  });
@@ -279,28 +279,28 @@ describe('RedBlackTree 2', () => {
279
279
  expect(node5F?.parent).toBe(node10F);
280
280
  expect(node15F?.key).toBe(15);
281
281
  expect(node15F?.color).toBe('RED');
282
- expect(node15F?.left).toBe(rbTree.SENTINEL);
283
- expect(node15F?.right).toBe(rbTree.SENTINEL);
282
+ expect(node15F?.left).toBe(rbTree.NIL);
283
+ expect(node15F?.right).toBe(rbTree.NIL);
284
284
  expect(node15F?.parent).toBe(node20F);
285
285
  expect(node21F?.key).toBe(21);
286
286
  expect(node21F?.color).toBe('RED');
287
- expect(node21F?.left).toBe(rbTree.SENTINEL);
288
- expect(node21F?.right).toBe(rbTree.SENTINEL);
287
+ expect(node21F?.left).toBe(rbTree.NIL);
288
+ expect(node21F?.right).toBe(rbTree.NIL);
289
289
  expect(node21F?.parent).toBe(node20F);
290
290
  expect(node6F?.key).toBe(6);
291
291
  expect(node6F?.color).toBe('RED');
292
- expect(node6F?.left).toBe(rbTree.SENTINEL);
293
- expect(node6F?.right).toBe(rbTree.SENTINEL);
292
+ expect(node6F?.left).toBe(rbTree.NIL);
293
+ expect(node6F?.right).toBe(rbTree.NIL);
294
294
  expect(node6F?.parent).toBe(node5F);
295
295
  expect(node2F?.key).toBe(2);
296
296
  expect(node2F?.color).toBe('RED');
297
- expect(node2F?.left).toBe(rbTree.SENTINEL);
298
- expect(node2F?.right).toBe(rbTree.SENTINEL);
297
+ expect(node2F?.left).toBe(rbTree.NIL);
298
+ expect(node2F?.right).toBe(rbTree.NIL);
299
299
  expect(node2F?.parent).toBe(node5F);
300
300
  expect(node15F?.key).toBe(15);
301
301
  expect(node15F?.color).toBe('RED');
302
- expect(node15F?.left).toBe(rbTree.SENTINEL);
303
- expect(node15F?.right).toBe(rbTree.SENTINEL);
302
+ expect(node15F?.left).toBe(rbTree.NIL);
303
+ expect(node15F?.right).toBe(rbTree.NIL);
304
304
  expect(node15F?.parent).toBe(node20F);
305
305
  rbTree.delete(5);
306
306
  node10F = rbTree.getNode(10);
@@ -323,28 +323,28 @@ describe('RedBlackTree 2', () => {
323
323
  expect(node5F).toBe(undefined);
324
324
  expect(node15F?.key).toBe(15);
325
325
  expect(node15F?.color).toBe('RED');
326
- expect(node15F?.left).toBe(rbTree.SENTINEL);
327
- expect(node15F?.right).toBe(rbTree.SENTINEL);
326
+ expect(node15F?.left).toBe(rbTree.NIL);
327
+ expect(node15F?.right).toBe(rbTree.NIL);
328
328
  expect(node15F?.parent).toBe(node20F);
329
329
  expect(node21F?.key).toBe(21);
330
330
  expect(node21F?.color).toBe('RED');
331
- expect(node21F?.left).toBe(rbTree.SENTINEL);
332
- expect(node21F?.right).toBe(rbTree.SENTINEL);
331
+ expect(node21F?.left).toBe(rbTree.NIL);
332
+ expect(node21F?.right).toBe(rbTree.NIL);
333
333
  expect(node21F?.parent).toBe(node20F);
334
334
  expect(node6F?.key).toBe(6);
335
335
  expect(node6F?.color).toBe('BLACK');
336
336
  expect(node6F?.left).toBe(node2F);
337
- expect(node6F?.right).toBe(rbTree.SENTINEL);
337
+ expect(node6F?.right).toBe(rbTree.NIL);
338
338
  expect(node6F?.parent).toBe(node10F);
339
339
  expect(node2F?.key).toBe(2);
340
340
  expect(node2F?.color).toBe('RED');
341
- expect(node2F?.left).toBe(rbTree.SENTINEL);
342
- expect(node2F?.right).toBe(rbTree.SENTINEL);
341
+ expect(node2F?.left).toBe(rbTree.NIL);
342
+ expect(node2F?.right).toBe(rbTree.NIL);
343
343
  expect(node2F?.parent).toBe(node6F);
344
344
  expect(node15F?.key).toBe(15);
345
345
  expect(node15F?.color).toBe('RED');
346
- expect(node15F?.left).toBe(rbTree.SENTINEL);
347
- expect(node15F?.right).toBe(rbTree.SENTINEL);
346
+ expect(node15F?.left).toBe(rbTree.NIL);
347
+ expect(node15F?.right).toBe(rbTree.NIL);
348
348
  expect(node15F?.parent).toBe(node20F);
349
349
  rbTree.delete(20);
350
350
  node10F = rbTree.getNode(10);
@@ -363,28 +363,28 @@ describe('RedBlackTree 2', () => {
363
363
  expect(node5F).toBe(undefined);
364
364
  expect(node15F?.key).toBe(15);
365
365
  expect(node15F?.color).toBe('RED');
366
- expect(node15F?.left).toBe(rbTree.SENTINEL);
367
- expect(node15F?.right).toBe(rbTree.SENTINEL);
366
+ expect(node15F?.left).toBe(rbTree.NIL);
367
+ expect(node15F?.right).toBe(rbTree.NIL);
368
368
  expect(node15F?.parent).toBe(node21F);
369
369
  expect(node21F?.key).toBe(21);
370
370
  expect(node21F?.color).toBe('BLACK');
371
371
  expect(node21F?.left).toBe(node15F);
372
- expect(node21F?.right).toBe(rbTree.SENTINEL);
372
+ expect(node21F?.right).toBe(rbTree.NIL);
373
373
  expect(node21F?.parent).toBe(node10F);
374
374
  expect(node6F?.key).toBe(6);
375
375
  expect(node6F?.color).toBe('BLACK');
376
376
  expect(node6F?.left).toBe(node2F);
377
- expect(node6F?.right).toBe(rbTree.SENTINEL);
377
+ expect(node6F?.right).toBe(rbTree.NIL);
378
378
  expect(node6F?.parent).toBe(node10F);
379
379
  expect(node2F?.key).toBe(2);
380
380
  expect(node2F?.color).toBe('RED');
381
- expect(node2F?.left).toBe(rbTree.SENTINEL);
382
- expect(node2F?.right).toBe(rbTree.SENTINEL);
381
+ expect(node2F?.left).toBe(rbTree.NIL);
382
+ expect(node2F?.right).toBe(rbTree.NIL);
383
383
  expect(node2F?.parent).toBe(node6F);
384
384
  expect(node15F?.key).toBe(15);
385
385
  expect(node15F?.color).toBe('RED');
386
- expect(node15F?.left).toBe(rbTree.SENTINEL);
387
- expect(node15F?.right).toBe(rbTree.SENTINEL);
386
+ expect(node15F?.left).toBe(rbTree.NIL);
387
+ expect(node15F?.right).toBe(rbTree.NIL);
388
388
  expect(node15F?.parent).toBe(node21F);
389
389
  });
390
390
 
@@ -394,8 +394,8 @@ describe('RedBlackTree 2', () => {
394
394
  rbTree.add(5);
395
395
  rbTree.add(15);
396
396
  const node15F = rbTree.getNode(15);
397
- expect(node15F?.left).toBe(rbTree.SENTINEL);
398
- expect(node15F?.right).toBe(rbTree.SENTINEL);
397
+ expect(node15F?.left).toBe(rbTree.NIL);
398
+ expect(node15F?.right).toBe(rbTree.NIL);
399
399
  expect(node15F?.parent).toBe(rbTree.getNode(5));
400
400
 
401
401
  rbTree.add(25);
@@ -410,8 +410,8 @@ describe('RedBlackTree 2', () => {
410
410
  rbTree.add(155);
411
411
  rbTree.add(225);
412
412
  const node225F = rbTree.getNode(225);
413
- expect(node225F?.left).toBe(rbTree.SENTINEL);
414
- expect(node225F?.right).toBe(rbTree.SENTINEL);
413
+ expect(node225F?.left).toBe(rbTree.NIL);
414
+ expect(node225F?.right).toBe(rbTree.NIL);
415
415
  expect(node225F?.parent?.key).toBe(155);
416
416
  rbTree.add(7);
417
417
  isDebug && rbTree.print();
@@ -438,14 +438,14 @@ describe('RedBlackTree 2', () => {
438
438
  const node50 = rbTree.getNode(50);
439
439
  expect(node50?.key).toBe(50);
440
440
  expect(node50?.left?.key).toBe(33);
441
- expect(node50?.right).toBe(rbTree.SENTINEL);
441
+ expect(node50?.right).toBe(rbTree.NIL);
442
442
  const node15Fo = rbTree.getNode(15);
443
443
 
444
444
  expect(node15Fo?.key).toBe(15);
445
- expect(node15Fo?.left).toBe(rbTree.SENTINEL);
445
+ expect(node15Fo?.left).toBe(rbTree.NIL);
446
446
  const node225S = rbTree.getNode(225);
447
- expect(node225S?.left).toBe(rbTree.SENTINEL);
448
- expect(node225S?.right).toBe(rbTree.SENTINEL);
447
+ expect(node225S?.left).toBe(rbTree.NIL);
448
+ expect(node225S?.right).toBe(rbTree.NIL);
449
449
  expect(node225S?.parent?.key).toBe(155);
450
450
  // TODO
451
451
  // expect(rbTree.getNode(0)).toBe(undefined);
@@ -512,7 +512,7 @@ describe('RedBlackTree 2', () => {
512
512
  rbTree.delete(getRandomInt(-100, 1000));
513
513
  }
514
514
 
515
- // TODO there is a bug when dfs the rbTree with SENTINEL node
515
+ // TODO there is a bug when dfs the rbTree with NIL node
516
516
  // expect(rbTree.isBST()).toBe(true);
517
517
  });
518
518
  const { HUNDRED_THOUSAND } = magnitude;