deque-typed 1.53.3 → 1.53.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.
|
@@ -326,8 +326,8 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
326
326
|
* cache.set('c', 3);
|
|
327
327
|
* cache.set('d', 4); // This will eliminate 'a'
|
|
328
328
|
*
|
|
329
|
-
* console.log(cache.get('a'))
|
|
330
|
-
*
|
|
329
|
+
* console.log(cache.get('a')); // undefined
|
|
330
|
+
* console.log(cache.get('b')); // 2
|
|
331
331
|
* console.log(cache.get('c')); // 3
|
|
332
332
|
* console.log(cache.get('d')); // 4
|
|
333
333
|
*
|
|
@@ -341,8 +341,8 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
341
341
|
* cache.set('d', 4); // This will eliminate 'b'
|
|
342
342
|
*
|
|
343
343
|
* console.log(cache.get('a')); // 1
|
|
344
|
-
* console.log(cache.get('b'))
|
|
345
|
-
*
|
|
344
|
+
* console.log(cache.get('b')); // undefined
|
|
345
|
+
* console.log(cache.get('c')); // 3
|
|
346
346
|
* console.log(cache.get('d')); // 4
|
|
347
347
|
*
|
|
348
348
|
* // Should support updating existing keys
|
|
@@ -358,8 +358,8 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
358
358
|
* cache.set('b', 2);
|
|
359
359
|
*
|
|
360
360
|
* console.log(cache.delete('a')); // true
|
|
361
|
-
* console.log(cache.get('a'))
|
|
362
|
-
*
|
|
361
|
+
* console.log(cache.get('a')); // undefined
|
|
362
|
+
* console.log(cache.size); // 1
|
|
363
363
|
*
|
|
364
364
|
* // Should support clearing cache
|
|
365
365
|
* cache.clear();
|
|
@@ -395,20 +395,20 @@ 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.
|
|
407
|
-
* console.log(earlyTimeLyric)
|
|
406
|
+
* const earlyTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= -1000);
|
|
407
|
+
* console.log(earlyTimeLyric); // undefined
|
|
408
408
|
*
|
|
409
409
|
* // 4. Find last lyric when timestamp is after last entry
|
|
410
|
-
* const lateTimeLyric = lyricsList.
|
|
411
|
-
*
|
|
410
|
+
* const lateTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 50000);
|
|
411
|
+
* console.log(lateTimeLyric?.text); // 'And I will try to fix you'
|
|
412
412
|
* @example
|
|
413
413
|
* // cpu process schedules
|
|
414
414
|
* class Process {
|
|
@@ -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,45 @@ 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
|
-
* The function returns the index of
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
712
|
+
* The indexOf function in TypeScript returns the index of a specified element or node in a Doubly
|
|
713
|
+
* Linked List.
|
|
714
|
+
* @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the
|
|
715
|
+
* `indexOf` method can be either an element of type `E` or a `DoublyLinkedListNode` containing an
|
|
716
|
+
* element of type `E`.
|
|
717
|
+
* @returns The `indexOf` method is returning the index of the element or node in the doubly linked
|
|
718
|
+
* list. If the element or node is found in the list, the method returns the index of that element or
|
|
719
|
+
* node. If the element or node is not found in the list, the method returns -1.
|
|
720
|
+
*/
|
|
721
|
+
indexOf(elementOrNode: E | DoublyLinkedListNode<E>): number;
|
|
722
|
+
/**
|
|
723
|
+
* Time Complexity: O(n)
|
|
724
|
+
* Space Complexity: O(1)
|
|
725
|
+
*
|
|
692
726
|
*/
|
|
693
|
-
|
|
727
|
+
/**
|
|
728
|
+
* This function retrieves an element from a doubly linked list based on a given element
|
|
729
|
+
* node or predicate.
|
|
730
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
731
|
+
* elementNodeOrPredicate - The `get` method takes in a parameter called `elementNodeOrPredicate`,
|
|
732
|
+
* which can be one of the following types:
|
|
733
|
+
* @returns The `get` method returns the value of the first node in the doubly linked list that
|
|
734
|
+
* satisfies the provided predicate function. If no such node is found, it returns `undefined`.
|
|
735
|
+
*/
|
|
736
|
+
get(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
694
737
|
/**
|
|
695
738
|
* Time Complexity: O(n)
|
|
696
739
|
* Space Complexity: O(1)
|
|
697
740
|
*
|
|
698
|
-
* The `
|
|
699
|
-
*
|
|
700
|
-
* @param
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
741
|
+
* The `getBackward` function searches for a specific element in a doubly linked list starting from
|
|
742
|
+
* the tail and moving backwards.
|
|
743
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
744
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `getBackward`
|
|
745
|
+
* function can be one of the following types:
|
|
746
|
+
* @returns The `getBackward` method returns the value of the element node that matches the provided
|
|
747
|
+
* predicate when traversing the doubly linked list backwards. If no matching element is found, it
|
|
748
|
+
* returns `undefined`.
|
|
704
749
|
*/
|
|
705
|
-
|
|
750
|
+
getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
|
|
706
751
|
/**
|
|
707
752
|
* Time Complexity: O(n)
|
|
708
753
|
* Space Complexity: O(1)
|
|
@@ -775,8 +820,48 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
775
820
|
* @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
|
|
776
821
|
*/
|
|
777
822
|
map<EM, RM>(callback: ElementCallback<E, R, EM, DoublyLinkedList<E, R>>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): DoublyLinkedList<EM, RM>;
|
|
823
|
+
/**
|
|
824
|
+
* Time Complexity: O(n)
|
|
825
|
+
* Space Complexity: O(n)
|
|
826
|
+
*
|
|
827
|
+
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
|
|
828
|
+
* given array.
|
|
829
|
+
* @param {E[]} data - The `data` parameter is an array of elements of type `E`.
|
|
830
|
+
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
831
|
+
*/
|
|
832
|
+
static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
|
|
778
833
|
/**
|
|
779
834
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
780
835
|
*/
|
|
781
836
|
protected _getIterator(): IterableIterator<E>;
|
|
837
|
+
/**
|
|
838
|
+
* The function `_isPredicate` checks if the input is a function that takes a `DoublyLinkedListNode`
|
|
839
|
+
* as an argument and returns a boolean.
|
|
840
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
841
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
|
|
842
|
+
* types:
|
|
843
|
+
* @returns The _isPredicate method is returning a boolean value indicating whether the
|
|
844
|
+
* elementNodeOrPredicate parameter is a function or not. If the elementNodeOrPredicate is a
|
|
845
|
+
* function, the method will return true, indicating that it is a predicate function.
|
|
846
|
+
*/
|
|
847
|
+
protected _isPredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is (node: DoublyLinkedListNode<E>) => boolean;
|
|
848
|
+
/**
|
|
849
|
+
* The function `_ensureNode` ensures that the input is a valid node in a doubly linked list.
|
|
850
|
+
* @param {E | DoublyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter can be either
|
|
851
|
+
* an element of type `E` or a `DoublyLinkedListNode` containing an element of type `E`.
|
|
852
|
+
* @returns If the `elementOrNode` parameter is already a `DoublyLinkedListNode`, it will be returned
|
|
853
|
+
* as is. Otherwise, a new `DoublyLinkedListNode` instance will be created with the `elementOrNode`
|
|
854
|
+
* value and returned.
|
|
855
|
+
*/
|
|
856
|
+
protected _ensureNode(elementOrNode: E | DoublyLinkedListNode<E>): DoublyLinkedListNode<E>;
|
|
857
|
+
/**
|
|
858
|
+
* The function `_ensurePredicate` in TypeScript ensures that the input is either a node, a predicate
|
|
859
|
+
* function, or a value to compare with the node's value.
|
|
860
|
+
* @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
861
|
+
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following
|
|
862
|
+
* types:
|
|
863
|
+
* @returns A function is being returned that takes a `DoublyLinkedListNode` as a parameter and
|
|
864
|
+
* returns a boolean value based on the conditions specified in the code.
|
|
865
|
+
*/
|
|
866
|
+
protected _ensurePredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): (node: DoublyLinkedListNode<E>) => boolean;
|
|
782
867
|
}
|