data-structure-typed 1.48.1 → 1.48.2
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.
- package/CHANGELOG.md +1 -1
- package/README.md +24 -18
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +182 -182
- package/dist/cjs/data-structures/base/index.d.ts +1 -0
- package/dist/cjs/data-structures/base/index.js +18 -0
- package/dist/cjs/data-structures/base/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/cjs/data-structures/base/iterable-base.js +313 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +36 -69
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +78 -129
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/cjs/data-structures/graph/abstract-graph.js +50 -27
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/cjs/data-structures/hash/hash-map.js +69 -173
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +50 -7
- package/dist/cjs/data-structures/heap/heap.js +60 -30
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/index.d.ts +1 -0
- package/dist/cjs/data-structures/index.js +1 -0
- package/dist/cjs/data-structures/index.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +29 -51
- package/dist/cjs/data-structures/queue/deque.js +36 -71
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +49 -48
- package/dist/cjs/data-structures/queue/queue.js +69 -82
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +43 -10
- package/dist/cjs/data-structures/stack/stack.js +50 -31
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +41 -6
- package/dist/cjs/data-structures/trie/trie.js +53 -32
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -0
- package/dist/cjs/types/data-structures/base/base.js +3 -0
- package/dist/cjs/types/data-structures/base/base.js.map +1 -0
- package/dist/cjs/types/data-structures/base/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/base/index.js +18 -0
- package/dist/cjs/types/data-structures/base/index.js.map +1 -0
- package/dist/cjs/types/data-structures/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/index.js +1 -0
- package/dist/cjs/types/data-structures/index.js.map +1 -1
- package/dist/mjs/data-structures/base/index.d.ts +1 -0
- package/dist/mjs/data-structures/base/index.js +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/mjs/data-structures/base/iterable-base.js +307 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +36 -69
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +78 -129
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/mjs/data-structures/graph/abstract-graph.js +52 -27
- package/dist/mjs/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/mjs/data-structures/hash/hash-map.js +69 -173
- package/dist/mjs/data-structures/heap/heap.d.ts +50 -7
- package/dist/mjs/data-structures/heap/heap.js +60 -30
- package/dist/mjs/data-structures/index.d.ts +1 -0
- package/dist/mjs/data-structures/index.js +1 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/mjs/data-structures/queue/deque.d.ts +29 -51
- package/dist/mjs/data-structures/queue/deque.js +36 -71
- package/dist/mjs/data-structures/queue/queue.d.ts +49 -48
- package/dist/mjs/data-structures/queue/queue.js +66 -79
- package/dist/mjs/data-structures/stack/stack.d.ts +43 -10
- package/dist/mjs/data-structures/stack/stack.js +50 -31
- package/dist/mjs/data-structures/trie/trie.d.ts +41 -6
- package/dist/mjs/data-structures/trie/trie.js +53 -32
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -0
- package/dist/mjs/types/data-structures/base/base.js +1 -0
- package/dist/mjs/types/data-structures/base/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/base/index.js +1 -0
- package/dist/mjs/types/data-structures/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/index.js +1 -0
- package/dist/umd/data-structure-typed.js +846 -715
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/binary-tree.ts +82 -138
- package/src/data-structures/graph/abstract-graph.ts +55 -28
- package/src/data-structures/hash/hash-map.ts +76 -185
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
- package/src/data-structures/queue/deque.ts +40 -82
- package/src/data-structures/queue/queue.ts +72 -87
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/index.ts +1 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/bst.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +10 -10
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +28 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +25 -0
- package/test/unit/data-structures/queue/deque.test.ts +25 -0
|
@@ -524,30 +524,30 @@ describe('RedBlackTree iterative methods test', () => {
|
|
|
524
524
|
|
|
525
525
|
test('forEach should iterate over all elements', () => {
|
|
526
526
|
const mockCallback = jest.fn();
|
|
527
|
-
rbTree.forEach((
|
|
528
|
-
mockCallback(
|
|
527
|
+
rbTree.forEach((value, key) => {
|
|
528
|
+
mockCallback(value, key);
|
|
529
529
|
});
|
|
530
530
|
|
|
531
531
|
expect(mockCallback.mock.calls.length).toBe(3);
|
|
532
|
-
expect(mockCallback.mock.calls[0]
|
|
533
|
-
expect(mockCallback.mock.calls[1]
|
|
534
|
-
expect(mockCallback.mock.calls[2]
|
|
532
|
+
expect(mockCallback.mock.calls[0]).toEqual(['a', 1]);
|
|
533
|
+
expect(mockCallback.mock.calls[1]).toEqual(['b', 2]);
|
|
534
|
+
expect(mockCallback.mock.calls[2]).toEqual(['c', 3]);
|
|
535
535
|
});
|
|
536
536
|
|
|
537
537
|
test('filter should return a new tree with filtered elements', () => {
|
|
538
|
-
const filteredTree = rbTree.filter((
|
|
538
|
+
const filteredTree = rbTree.filter((value, key) => key > 1);
|
|
539
539
|
expect(filteredTree.size).toBe(2);
|
|
540
540
|
expect([...filteredTree]).toEqual([[2, 'b'], [3, 'c']]);
|
|
541
541
|
});
|
|
542
542
|
|
|
543
543
|
test('map should return a new tree with modified elements', () => {
|
|
544
|
-
const mappedTree = rbTree.map((
|
|
544
|
+
const mappedTree = rbTree.map((value, key) => (key * 2).toString());
|
|
545
545
|
expect(mappedTree.size).toBe(3);
|
|
546
546
|
expect([...mappedTree]).toEqual([[1, '2'], [2, '4'], [3, '6']]);
|
|
547
547
|
});
|
|
548
548
|
|
|
549
549
|
test('reduce should accumulate values', () => {
|
|
550
|
-
const sum = rbTree.reduce((acc,
|
|
550
|
+
const sum = rbTree.reduce((acc, value, key) => acc + key, 0);
|
|
551
551
|
expect(sum).toBe(6);
|
|
552
552
|
});
|
|
553
553
|
|
|
@@ -619,30 +619,30 @@ describe('TreeMultimap iterative methods test', () => {
|
|
|
619
619
|
|
|
620
620
|
test('forEach should iterate over all elements', () => {
|
|
621
621
|
const mockCallback = jest.fn();
|
|
622
|
-
treeMM.forEach((
|
|
623
|
-
mockCallback(
|
|
622
|
+
treeMM.forEach((value, key) => {
|
|
623
|
+
mockCallback(value, key);
|
|
624
624
|
});
|
|
625
625
|
|
|
626
626
|
expect(mockCallback.mock.calls.length).toBe(3);
|
|
627
|
-
expect(mockCallback.mock.calls[0]
|
|
628
|
-
expect(mockCallback.mock.calls[1]
|
|
629
|
-
expect(mockCallback.mock.calls[2]
|
|
627
|
+
expect(mockCallback.mock.calls[0]).toEqual(['a', 1]);
|
|
628
|
+
expect(mockCallback.mock.calls[1]).toEqual(['b', 2]);
|
|
629
|
+
expect(mockCallback.mock.calls[2]).toEqual(['c', 3]);
|
|
630
630
|
});
|
|
631
631
|
|
|
632
632
|
test('filter should return a new tree with filtered elements', () => {
|
|
633
|
-
const filteredTree = treeMM.filter((
|
|
633
|
+
const filteredTree = treeMM.filter((value, key) => key > 1);
|
|
634
634
|
expect(filteredTree.size).toBe(2);
|
|
635
635
|
expect([...filteredTree]).toEqual([[2, 'b'], [3, 'c']]);
|
|
636
636
|
});
|
|
637
637
|
|
|
638
638
|
test('map should return a new tree with modified elements', () => {
|
|
639
|
-
const mappedTree = treeMM.map((
|
|
639
|
+
const mappedTree = treeMM.map((value, key) => (key * 2).toString());
|
|
640
640
|
expect(mappedTree.size).toBe(3);
|
|
641
641
|
expect([...mappedTree]).toEqual([[1, '2'], [2, '4'], [3, '6']]);
|
|
642
642
|
});
|
|
643
643
|
|
|
644
644
|
test('reduce should accumulate values', () => {
|
|
645
|
-
const sum = treeMM.reduce((acc,
|
|
645
|
+
const sum = treeMM.reduce((acc, value, key) => acc + key, 0);
|
|
646
646
|
expect(sum).toBe(6);
|
|
647
647
|
});
|
|
648
648
|
|
|
@@ -665,11 +665,11 @@ describe('TreeMultimap iterative methods test', () => {
|
|
|
665
665
|
|
|
666
666
|
test('should keys', () => {
|
|
667
667
|
const keys = treeMM.keys();
|
|
668
|
-
expect(keys).toEqual([1, 2, 3]);
|
|
668
|
+
expect([...keys]).toEqual([1, 2, 3]);
|
|
669
669
|
});
|
|
670
670
|
|
|
671
671
|
test('should values', () => {
|
|
672
672
|
const values = treeMM.values();
|
|
673
|
-
expect(values).toEqual(['a', 'b', 'c']);
|
|
673
|
+
expect([...values]).toEqual(['a', 'b', 'c']);
|
|
674
674
|
});
|
|
675
675
|
});
|
|
@@ -616,22 +616,22 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
616
616
|
|
|
617
617
|
test('forEach should apply a function to each vertex', () => {
|
|
618
618
|
const result: VertexKey[] = [];
|
|
619
|
-
graph.forEach(
|
|
619
|
+
graph.forEach((value, key) => key && result.push(key));
|
|
620
620
|
expect(result).toEqual(vertices);
|
|
621
621
|
});
|
|
622
622
|
|
|
623
623
|
test('filter should return vertices that satisfy the condition', () => {
|
|
624
|
-
const filtered = graph.filter(vertex => vertex
|
|
624
|
+
const filtered = graph.filter((value, vertex) => vertex === 'A' || vertex === 'B');
|
|
625
625
|
expect(filtered).toEqual([["A", undefined], ["B", undefined]]);
|
|
626
626
|
});
|
|
627
627
|
|
|
628
628
|
test('map should apply a function to each vertex and return a new array', () => {
|
|
629
|
-
const mapped = graph.map(vertex => vertex
|
|
629
|
+
const mapped = graph.map((value, vertex) => vertex + '_mapped');
|
|
630
630
|
expect(mapped).toEqual(vertices.map(v => v + '_mapped'));
|
|
631
631
|
});
|
|
632
632
|
|
|
633
633
|
test('reduce should accumulate a value based on each vertex', () => {
|
|
634
|
-
const concatenated = graph.reduce((acc,
|
|
634
|
+
const concatenated = graph.reduce((acc, value, key) => acc + key, '');
|
|
635
635
|
expect(concatenated).toBe(vertices.join(''));
|
|
636
636
|
});
|
|
637
637
|
});
|
|
@@ -548,10 +548,10 @@ describe('LinkedHashMap setMany, keys, values', () => {
|
|
|
548
548
|
})
|
|
549
549
|
|
|
550
550
|
test('keys', () => {
|
|
551
|
-
expect(hm.keys()).toEqual([2, 3, 4, 5, 6])
|
|
551
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
552
552
|
});
|
|
553
553
|
|
|
554
554
|
test('values', () => {
|
|
555
|
-
expect(hm.values()).toEqual([2, 3, 4, 5, 6])
|
|
555
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
556
556
|
});
|
|
557
557
|
});
|
|
@@ -397,3 +397,31 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
397
397
|
expect(shiftedObj).toBe(obj1);
|
|
398
398
|
});
|
|
399
399
|
});
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
describe('iterable methods', () => {
|
|
403
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
404
|
+
const dl = new DoublyLinkedList<number>()
|
|
405
|
+
dl.push(1);
|
|
406
|
+
dl.push(2);
|
|
407
|
+
dl.push(3);
|
|
408
|
+
|
|
409
|
+
const mockCallback = jest.fn();
|
|
410
|
+
dl.forEach((element) => {
|
|
411
|
+
mockCallback(element);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
415
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
416
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
417
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
418
|
+
|
|
419
|
+
expect(dl.every(element => element > 0)).toBe(true);
|
|
420
|
+
expect(dl.every(element => element > 1)).toBe(false);
|
|
421
|
+
expect(dl.some(element => element > 2)).toBe(true);
|
|
422
|
+
|
|
423
|
+
expect([...dl.filter(element => element > 2)]).toEqual([3]);
|
|
424
|
+
expect([...dl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
425
|
+
expect(dl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
@@ -471,3 +471,28 @@ describe('SinglyLinkedList', () => {
|
|
|
471
471
|
expect(list1.reduce((acc, value) => acc + value, 0)).toEqual(6);
|
|
472
472
|
});
|
|
473
473
|
});
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
describe('iterable methods', () => {
|
|
477
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
478
|
+
const sl = new SinglyLinkedList<number>([1, 2, 3])
|
|
479
|
+
|
|
480
|
+
const mockCallback = jest.fn();
|
|
481
|
+
sl.forEach((element) => {
|
|
482
|
+
mockCallback(element);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
486
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
487
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
488
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
489
|
+
|
|
490
|
+
expect(sl.every(element => element > 0)).toBe(true);
|
|
491
|
+
expect(sl.every(element => element > 1)).toBe(false);
|
|
492
|
+
expect(sl.some(element => element > 2)).toBe(true);
|
|
493
|
+
|
|
494
|
+
expect([...sl.filter(element => element > 2)]).toEqual([3]);
|
|
495
|
+
expect([...sl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
496
|
+
expect(sl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
@@ -447,4 +447,29 @@ describe('Deque', () => {
|
|
|
447
447
|
});
|
|
448
448
|
});
|
|
449
449
|
|
|
450
|
+
describe('iterable methods', () => {
|
|
451
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
452
|
+
deque.push(1);
|
|
453
|
+
deque.push(2);
|
|
454
|
+
deque.push(3);
|
|
455
|
+
|
|
456
|
+
const mockCallback = jest.fn();
|
|
457
|
+
deque.forEach((element) => {
|
|
458
|
+
mockCallback(element);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
462
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
463
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
464
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
465
|
+
|
|
466
|
+
expect(deque.every(element => element > 0)).toBe(true);
|
|
467
|
+
expect(deque.every(element => element > 1)).toBe(false);
|
|
468
|
+
expect(deque.some(element => element > 2)).toBe(true);
|
|
469
|
+
|
|
470
|
+
expect([...deque.filter(element => element > 2)]).toEqual([3]);
|
|
471
|
+
expect([...deque.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
472
|
+
expect(deque.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
450
475
|
});
|