directed-graph-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')).toBeUndefined();
330
- * expect(cache.get('b')); // 2
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')).toBeUndefined();
345
- * expect(cache.get('c')); // 3
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')).toBeUndefined();
362
- * expect(cache.size); // 1
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.findBackward(lyric => lyric.time <= 36000);
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.findBackward(lyric => lyric.time <= 22000);
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.findBackward(lyric => lyric.time <= -1000);
407
- * console.log(earlyTimeLyric).toBeUndefined();
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.findBackward(lyric => lyric.time <= 50000);
411
- * expect(lateTimeLyric?.text); // 'And I will try to fix you'
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(n)
528
- * Space Complexity: O(n)
527
+ * Time Complexity: O(1)
528
+ * Space Complexity: O(1)
529
529
  *
530
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
531
- * given array.
532
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
533
- * @returns The `fromArray` function returns a DoublyLinkedList object.
534
- */
535
- static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
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} element - The "element" parameter represents the value that you want to add to the
542
- * doubly linked list.
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(element: E): boolean;
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} element - The "element" parameter represents the value of the element that you want to
568
- * add to the beginning of the doubly linked list.
569
- * @returns The `unshift` method is returning a boolean value, `true`.
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(element: E): boolean;
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
- * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
600
- * node if found, otherwise it returns undefined.
601
- * @param {E} value - The `value` parameter is the value that we want to search for in the doubly linked list.
602
- * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `value`
603
- * is found in the linked list. If no such node is found, it returns `undefined`.
604
- */
605
- getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined;
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 `insert` function inserts a value at a specified index in a doubly linked list.
611
- * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
612
- * DoublyLinkedList. It is of type number.
613
- * @param {E} value - The `value` parameter represents the value that you want to insert into the Doubly Linked List at the
614
- * specified index.
615
- * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
616
- * if the index is out of bounds.
617
- */
618
- addAt(index: number, value: E): boolean;
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 inserts a new value before an existing value or node in a doubly linked list.
624
- * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
625
- * before which the new value will be inserted. It can be either the value of the existing node or the existing node
626
- * itself.
627
- * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
628
- * list.
629
- * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
630
- * insertion fails.
631
- */
632
- addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
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 inserts a new node with a given value after an existing node in a doubly linked list.
638
- * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
639
- * after which the new value will be inserted. It can be either the value of the existing node or the existing node
640
- * itself.
641
- * @param {E} newValue - The value that you want to insert into the doubly linked list.
642
- * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
643
- * existing value or node is not found in the doubly linked list.
644
- */
645
- addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
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 based on either the node itself or its value.
662
- * @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
663
- * a `DoublyLinkedListNode<E>` object.
664
- * @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
665
- * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
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(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
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 the first occurrence of a given value in a linked list.
688
- * @param {E} value - The parameter `value` is of type `E`, which means it can be any data type. It represents the value
689
- * that we are searching for in the linked list.
690
- * @returns The method `indexOf` returns the index of the first occurrence of the specified value `value` in the linked
691
- * list. If the value is not found, it returns -1.
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
- indexOf(value: E): number;
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 `findBackward` function iterates through a linked list from the last node to the first node and returns the last
699
- * value that satisfies the given callback function, or undefined if no value satisfies the callback.
700
- * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
701
- * function is used to determine whether a given value satisfies a certain condition.
702
- * @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
703
- * the callback function. If no value satisfies the condition, it returns `undefined`.
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
- findBackward(callback: (value: E) => boolean): E | undefined;
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
  }