min-heap-typed 1.53.4 → 1.53.6
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/README.md +5 -5
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +163 -76
- package/dist/data-structures/linked-list/doubly-linked-list.js +211 -104
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +144 -62
- package/dist/data-structures/linked-list/singly-linked-list.js +201 -97
- package/package.json +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +232 -105
- package/src/data-structures/linked-list/singly-linked-list.ts +219 -98
package/README.md
CHANGED
|
@@ -30,10 +30,6 @@ npm i min-heap-typed --save
|
|
|
30
30
|
yarn add min-heap-typed
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
### methods
|
|
34
|
-
|
|
35
|
-

|
|
36
|
-
|
|
37
33
|
### snippet
|
|
38
34
|
|
|
39
35
|
#### TS
|
|
@@ -84,7 +80,11 @@ yarn add min-heap-typed
|
|
|
84
80
|
minNumHeap.sort() // [2, 5, 6, 9]
|
|
85
81
|
```
|
|
86
82
|
|
|
87
|
-
|
|
83
|
+
[//]: # (No deletion!!! Start of Example Replace Section)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
[//]: # (No deletion!!! End of Example Replace Section)
|
|
87
|
+
|
|
88
88
|
|
|
89
89
|
## API docs & Examples
|
|
90
90
|
|
|
@@ -395,19 +395,19 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
395
395
|
* // Test different scenarios of lyric synchronization
|
|
396
396
|
*
|
|
397
397
|
* // 1. Find lyric at exact timestamp
|
|
398
|
-
* const exactTimeLyric = lyricsList.
|
|
398
|
+
* const exactTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 36000);
|
|
399
399
|
* console.log(exactTimeLyric?.text); // 'And ignite your bones'
|
|
400
400
|
*
|
|
401
401
|
* // 2. Find lyric between timestamps
|
|
402
|
-
* const betweenTimeLyric = lyricsList.
|
|
402
|
+
* const betweenTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 22000);
|
|
403
403
|
* console.log(betweenTimeLyric?.text); // "When you lose something you can't replace"
|
|
404
404
|
*
|
|
405
405
|
* // 3. Find first lyric when timestamp is less than first entry
|
|
406
|
-
* const earlyTimeLyric = lyricsList.
|
|
406
|
+
* const earlyTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= -1000);
|
|
407
407
|
* console.log(earlyTimeLyric); // undefined
|
|
408
408
|
*
|
|
409
409
|
* // 4. Find last lyric when timestamp is after last entry
|
|
410
|
-
* const lateTimeLyric = lyricsList.
|
|
410
|
+
* const lateTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 50000);
|
|
411
411
|
* console.log(lateTimeLyric?.text); // 'And I will try to fix you'
|
|
412
412
|
* @example
|
|
413
413
|
* // cpu process schedules
|
|
@@ -524,25 +524,30 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
524
524
|
*/
|
|
525
525
|
get last(): E | undefined;
|
|
526
526
|
/**
|
|
527
|
-
* Time Complexity: O(
|
|
528
|
-
* Space Complexity: O(
|
|
527
|
+
* Time Complexity: O(1)
|
|
528
|
+
* Space Complexity: O(1)
|
|
529
529
|
*
|
|
530
|
-
* The `
|
|
531
|
-
*
|
|
532
|
-
* @param {E
|
|
533
|
-
*
|
|
534
|
-
|
|
535
|
-
|
|
530
|
+
* The function `isNode` in TypeScript checks if a given input is an instance of
|
|
531
|
+
* `DoublyLinkedListNode`.
|
|
532
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
533
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `isNode` function can
|
|
534
|
+
* be one of the following types:
|
|
535
|
+
* @returns The `isNode` function is checking if the `elementNodeOrPredicate` parameter is an
|
|
536
|
+
* instance of `DoublyLinkedListNode<E>`. If it is, the function returns `true`, indicating that the
|
|
537
|
+
* parameter is a `DoublyLinkedListNode<E>`. If it is not an instance of `DoublyLinkedListNode<E>`,
|
|
538
|
+
* the function returns `false`.
|
|
539
|
+
*/
|
|
540
|
+
isNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is DoublyLinkedListNode<E>;
|
|
536
541
|
/**
|
|
537
542
|
* Time Complexity: O(1)
|
|
538
543
|
* Space Complexity: O(1)
|
|
539
544
|
*
|
|
540
|
-
* The push function adds a new element to the end of a doubly linked list.
|
|
541
|
-
* @param {E}
|
|
542
|
-
*
|
|
543
|
-
* @returns The `push` method is returning a boolean value, `true`.
|
|
545
|
+
* The `push` function adds a new element or node to the end of a doubly linked list.
|
|
546
|
+
* @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the `push`
|
|
547
|
+
* method can accept either an element of type `E` or a `DoublyLinkedListNode<E>` object.
|
|
548
|
+
* @returns The `push` method is returning a boolean value, specifically `true`.
|
|
544
549
|
*/
|
|
545
|
-
push(
|
|
550
|
+
push(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
546
551
|
/**
|
|
547
552
|
* Time Complexity: O(1)
|
|
548
553
|
* Space Complexity: O(1)
|
|
@@ -563,12 +568,13 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
563
568
|
* Time Complexity: O(1)
|
|
564
569
|
* Space Complexity: O(1)
|
|
565
570
|
*
|
|
566
|
-
* The unshift function adds a new element to the beginning of a doubly linked list.
|
|
567
|
-
* @param {E}
|
|
568
|
-
*
|
|
569
|
-
*
|
|
571
|
+
* The unshift function adds a new element or node to the beginning of a doubly linked list.
|
|
572
|
+
* @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the
|
|
573
|
+
* `unshift` method can be either an element of type `E` or a `DoublyLinkedListNode` containing an
|
|
574
|
+
* element of type `E`.
|
|
575
|
+
* @returns The `unshift` method is returning a boolean value, specifically `true`.
|
|
570
576
|
*/
|
|
571
|
-
unshift(
|
|
577
|
+
unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
572
578
|
/**
|
|
573
579
|
* Time Complexity: O(n)
|
|
574
580
|
* Space Complexity: O(1)
|
|
@@ -596,53 +602,69 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
596
602
|
* Time Complexity: O(n)
|
|
597
603
|
* Space Complexity: O(1)
|
|
598
604
|
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* @param {E
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
|
|
605
|
-
|
|
605
|
+
* This TypeScript function searches for a node in a doubly linked list based on a given element node
|
|
606
|
+
* or predicate.
|
|
607
|
+
* @param {| E
|
|
608
|
+
* | DoublyLinkedListNode<E>
|
|
609
|
+
* | ((node: DoublyLinkedListNode<E>) => boolean)
|
|
610
|
+
* | undefined} elementNodeOrPredicate - The `getNode` method you provided is used to find a
|
|
611
|
+
* node in a doubly linked list based on a given element, node, or predicate function. The
|
|
612
|
+
* `elementNodeOrPredicate` parameter can be one of the following:
|
|
613
|
+
* @returns The `getNode` method returns a `DoublyLinkedListNode<E>` or `undefined` based on the
|
|
614
|
+
* input `elementNodeOrPredicate`. If the input is `undefined`, the method returns `undefined`.
|
|
615
|
+
* Otherwise, it iterates through the linked list starting from the head node and applies the
|
|
616
|
+
* provided predicate function to each node. If a node satisfies the predicate, that node is
|
|
617
|
+
* returned. If
|
|
618
|
+
*/
|
|
619
|
+
getNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean) | undefined): DoublyLinkedListNode<E> | undefined;
|
|
606
620
|
/**
|
|
607
621
|
* Time Complexity: O(n)
|
|
608
622
|
* Space Complexity: O(1)
|
|
609
623
|
*
|
|
610
|
-
* The `
|
|
611
|
-
* @param {number} index - The index parameter
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
* if the
|
|
617
|
-
|
|
618
|
-
|
|
624
|
+
* The `addAt` function inserts a new element or node at a specified index in a doubly linked list.
|
|
625
|
+
* @param {number} index - The `index` parameter in the `addAt` method represents the position at
|
|
626
|
+
* which you want to add a new element or node in the doubly linked list. It indicates the location
|
|
627
|
+
* where the new element or node should be inserted.
|
|
628
|
+
* @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
|
|
629
|
+
* `addAt` method can be either a value of type `E` or a `DoublyLinkedListNode<E>` object.
|
|
630
|
+
* @returns The `addAt` method returns a boolean value. It returns `true` if the element or node was
|
|
631
|
+
* successfully added at the specified index, and `false` if the index is out of bounds (less than 0
|
|
632
|
+
* or greater than the size of the list).
|
|
633
|
+
*/
|
|
634
|
+
addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
619
635
|
/**
|
|
620
636
|
* Time Complexity: O(1) or O(n)
|
|
621
637
|
* Space Complexity: O(1)
|
|
622
638
|
*
|
|
623
|
-
* The `addBefore` function
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* @param {E}
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
|
|
632
|
-
|
|
639
|
+
* The `addBefore` function in TypeScript adds a new element or node before an existing element or
|
|
640
|
+
* node in a doubly linked list.
|
|
641
|
+
* @param {E | DoublyLinkedListNode<E>} existingElementOrNode - The `existingElementOrNode` parameter
|
|
642
|
+
* in the `addBefore` method can be either an element of type `E` or a `DoublyLinkedListNode<E>`.
|
|
643
|
+
* @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter
|
|
644
|
+
* represents the element or node that you want to add before the `existingElementOrNode` in a doubly
|
|
645
|
+
* linked list.
|
|
646
|
+
* @returns The `addBefore` method returns a boolean value - `true` if the new element or node was
|
|
647
|
+
* successfully added before the existing element or node, and `false` if the existing element or
|
|
648
|
+
* node was not found.
|
|
649
|
+
*/
|
|
650
|
+
addBefore(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
633
651
|
/**
|
|
634
652
|
* Time Complexity: O(1) or O(n)
|
|
635
653
|
* Space Complexity: O(1)
|
|
636
654
|
*
|
|
637
|
-
* The `addAfter` function
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
* @param {E}
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
|
|
645
|
-
|
|
655
|
+
* The `addAfter` function in TypeScript adds a new element or node after an existing element or node
|
|
656
|
+
* in a doubly linked list.
|
|
657
|
+
* @param {E | DoublyLinkedListNode<E>} existingElementOrNode - existingElementOrNode represents the
|
|
658
|
+
* element or node in the doubly linked list after which you want to add a new element or node.
|
|
659
|
+
* @param {E | DoublyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
|
|
660
|
+
* `addAfter` method represents the element or node that you want to add after the existing element
|
|
661
|
+
* or node in a doubly linked list. This parameter can be either an element value or a
|
|
662
|
+
* `DoublyLinkedListNode` object that you want to insert
|
|
663
|
+
* @returns The `addAfter` method returns a boolean value - `true` if the new element or node was
|
|
664
|
+
* successfully added after the existing element or node, and `false` if the existing element or node
|
|
665
|
+
* was not found in the linked list.
|
|
666
|
+
*/
|
|
667
|
+
addAfter(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
|
|
646
668
|
/**
|
|
647
669
|
* Time Complexity: O(n)
|
|
648
670
|
* Space Complexity: O(1)
|
|
@@ -658,13 +680,16 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
658
680
|
* Time Complexity: O(1) or O(n)
|
|
659
681
|
* Space Complexity: O(1)
|
|
660
682
|
*
|
|
661
|
-
* The `delete` function removes a node from a doubly linked list
|
|
662
|
-
* @param {E | DoublyLinkedListNode<E>}
|
|
663
|
-
* a `DoublyLinkedListNode
|
|
664
|
-
*
|
|
665
|
-
*
|
|
683
|
+
* The `delete` function removes a specified element or node from a doubly linked list if it exists.
|
|
684
|
+
* @param {E | DoublyLinkedListNode<E> | undefined} elementOrNode - The `elementOrNode` parameter in
|
|
685
|
+
* the `delete` method can accept an element of type `E`, a `DoublyLinkedListNode` of type `E`, or it
|
|
686
|
+
* can be `undefined`. This parameter is used to identify the node that needs to be deleted from the
|
|
687
|
+
* doubly linked list
|
|
688
|
+
* @returns The `delete` method returns a boolean value - `true` if the element or node was
|
|
689
|
+
* successfully deleted from the doubly linked list, and `false` if the element or node was not found
|
|
690
|
+
* in the list.
|
|
666
691
|
*/
|
|
667
|
-
delete(
|
|
692
|
+
delete(elementOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
668
693
|
/**
|
|
669
694
|
* Time Complexity: O(1)
|
|
670
695
|
* Space Complexity: O(1)
|
|
@@ -684,25 +709,41 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
684
709
|
* Time Complexity: O(n)
|
|
685
710
|
* Space Complexity: O(1)
|
|
686
711
|
*
|
|
687
|
-
*
|
|
688
|
-
* @param {E
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
712
|
+
* This function finds the index of a specified element, node, or predicate in a doubly linked list.
|
|
713
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
714
|
+
* elementNodeOrPredicate - The `indexOf` method takes in a parameter `elementNodeOrPredicate`, which
|
|
715
|
+
* can be one of the following:
|
|
716
|
+
* @returns The `indexOf` method returns the index of the element in the doubly linked list that
|
|
717
|
+
* matches the provided element, node, or predicate. If no match is found, it returns -1.
|
|
692
718
|
*/
|
|
693
|
-
indexOf(
|
|
719
|
+
indexOf(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): number;
|
|
694
720
|
/**
|
|
695
721
|
* Time Complexity: O(n)
|
|
696
722
|
* Space Complexity: O(1)
|
|
697
723
|
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* @param
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
724
|
+
* This function retrieves an element from a doubly linked list based on a given element
|
|
725
|
+
* node or predicate.
|
|
726
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
727
|
+
* elementNodeOrPredicate - The `get` method takes in a parameter called `elementNodeOrPredicate`,
|
|
728
|
+
* which can be one of the following types:
|
|
729
|
+
* @returns The `get` method returns the value of the first node in the doubly linked list that
|
|
730
|
+
* satisfies the provided predicate function. If no such node is found, it returns `undefined`.
|
|
704
731
|
*/
|
|
705
|
-
|
|
732
|
+
get(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
733
|
+
/**
|
|
734
|
+
* Time Complexity: O(n)
|
|
735
|
+
* Space Complexity: O(1)
|
|
736
|
+
*
|
|
737
|
+
* The `getBackward` function searches for a specific element in a doubly linked list starting from
|
|
738
|
+
* the tail and moving backwards.
|
|
739
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
740
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `getBackward`
|
|
741
|
+
* function can be one of the following types:
|
|
742
|
+
* @returns The `getBackward` method returns the value of the element node that matches the provided
|
|
743
|
+
* predicate when traversing the doubly linked list backwards. If no matching element is found, it
|
|
744
|
+
* returns `undefined`.
|
|
745
|
+
*/
|
|
746
|
+
getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
706
747
|
/**
|
|
707
748
|
* Time Complexity: O(n)
|
|
708
749
|
* Space Complexity: O(1)
|
|
@@ -775,8 +816,54 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
775
816
|
* @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
|
|
776
817
|
*/
|
|
777
818
|
map<EM, RM>(callback: ElementCallback<E, R, EM, DoublyLinkedList<E, R>>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): DoublyLinkedList<EM, RM>;
|
|
819
|
+
/**
|
|
820
|
+
* Time Complexity: O(n)
|
|
821
|
+
* Space Complexity: O(1)
|
|
822
|
+
*
|
|
823
|
+
*/
|
|
824
|
+
countOccurrences(elementOrNode: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): number;
|
|
825
|
+
/**
|
|
826
|
+
* Time Complexity: O(n)
|
|
827
|
+
* Space Complexity: O(n)
|
|
828
|
+
*
|
|
829
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
830
|
+
* given array.
|
|
831
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
832
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
833
|
+
*/
|
|
834
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
|
|
778
835
|
/**
|
|
779
836
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
780
837
|
*/
|
|
781
838
|
protected _getIterator(): IterableIterator<E>;
|
|
839
|
+
/**
|
|
840
|
+
* The function `_isPredicate` checks if the input is a function that takes a `DoublyLinkedListNode`
|
|
841
|
+
* as an argument and returns a boolean.
|
|
842
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
843
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
|
|
844
|
+
* types:
|
|
845
|
+
* @returns The _isPredicate method is returning a boolean value indicating whether the
|
|
846
|
+
* elementNodeOrPredicate parameter is a function or not. If the elementNodeOrPredicate is a
|
|
847
|
+
* function, the method will return true, indicating that it is a predicate function.
|
|
848
|
+
*/
|
|
849
|
+
protected _isPredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is (node: DoublyLinkedListNode<E>) => boolean;
|
|
850
|
+
/**
|
|
851
|
+
* The function `_ensureNode` ensures that the input is a valid node in a doubly linked list.
|
|
852
|
+
* @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter can be either
|
|
853
|
+
* an element of type `E` or a `DoublyLinkedListNode` containing an element of type `E`.
|
|
854
|
+
* @returns If the `elementOrNode` parameter is already a `DoublyLinkedListNode`, it will be returned
|
|
855
|
+
* as is. Otherwise, a new `DoublyLinkedListNode` instance will be created with the `elementOrNode`
|
|
856
|
+
* value and returned.
|
|
857
|
+
*/
|
|
858
|
+
protected _ensureNode(elementOrNode: E | DoublyLinkedListNode<E>): DoublyLinkedListNode<E>;
|
|
859
|
+
/**
|
|
860
|
+
* The function `_ensurePredicate` in TypeScript ensures that the input is either a node, a predicate
|
|
861
|
+
* function, or a value to compare with the node's value.
|
|
862
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
863
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
|
|
864
|
+
* types:
|
|
865
|
+
* @returns A function is being returned that takes a `DoublyLinkedListNode` as a parameter and
|
|
866
|
+
* returns a boolean value based on the conditions specified in the code.
|
|
867
|
+
*/
|
|
868
|
+
protected _ensurePredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): (node: DoublyLinkedListNode<E>) => boolean;
|
|
782
869
|
}
|