data-structure-typed 2.6.1 → 2.6.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 +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +72 -104
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +68 -98
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +33 -53
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
- package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
|
@@ -733,10 +733,10 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
733
733
|
*/
|
|
734
734
|
constructor(elements = [], options) {
|
|
735
735
|
super(options);
|
|
736
|
-
__publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
|
|
737
736
|
__publicField(this, "_head");
|
|
738
737
|
__publicField(this, "_tail");
|
|
739
738
|
__publicField(this, "_length", 0);
|
|
739
|
+
__publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
|
|
740
740
|
this.pushMany(elements);
|
|
741
741
|
}
|
|
742
742
|
/**
|
|
@@ -798,68 +798,26 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
798
798
|
return list;
|
|
799
799
|
}
|
|
800
800
|
/**
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
* @example
|
|
848
|
-
* // basic SinglyLinkedList creation and push operation
|
|
849
|
-
* // Create a simple SinglyLinkedList with initial values
|
|
850
|
-
* const list = new SinglyLinkedList([1, 2, 3, 4, 5]);
|
|
851
|
-
*
|
|
852
|
-
* // Verify the list maintains insertion order
|
|
853
|
-
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
854
|
-
*
|
|
855
|
-
* // Check length
|
|
856
|
-
* console.log(list.length); // 5;
|
|
857
|
-
*
|
|
858
|
-
* // Push a new element to the end
|
|
859
|
-
* list.push(6);
|
|
860
|
-
* console.log(list.length); // 6;
|
|
861
|
-
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
862
|
-
*/
|
|
801
|
+
* Append an element/node to the tail.
|
|
802
|
+
* @remarks Time O(1), Space O(1)
|
|
803
|
+
* @param elementOrNode - Element or node to append.
|
|
804
|
+
* @returns True when appended.
|
|
805
|
+
* @example
|
|
806
|
+
* // basic SinglyLinkedList creation and push operation
|
|
807
|
+
* // Create a simple SinglyLinkedList with initial values
|
|
808
|
+
* const list = new SinglyLinkedList([1, 2, 3, 4, 5]);
|
|
809
|
+
*
|
|
810
|
+
* // Verify the list maintains insertion order
|
|
811
|
+
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
812
|
+
*
|
|
813
|
+
* // Check length
|
|
814
|
+
* console.log(list.length); // 5;
|
|
815
|
+
*
|
|
816
|
+
* // Push a new element to the end
|
|
817
|
+
* list.push(6);
|
|
818
|
+
* console.log(list.length); // 6;
|
|
819
|
+
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
820
|
+
*/
|
|
863
821
|
push(elementOrNode) {
|
|
864
822
|
const newNode = this._ensureNode(elementOrNode);
|
|
865
823
|
if (!this.head) {
|
|
@@ -873,67 +831,25 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
873
831
|
return true;
|
|
874
832
|
}
|
|
875
833
|
/**
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
* @example
|
|
922
|
-
* // SinglyLinkedList pop and shift operations
|
|
923
|
-
* const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
924
|
-
*
|
|
925
|
-
* // Pop removes from the end
|
|
926
|
-
* const last = list.pop();
|
|
927
|
-
* console.log(last); // 50;
|
|
928
|
-
*
|
|
929
|
-
* // Shift removes from the beginning
|
|
930
|
-
* const first = list.shift();
|
|
931
|
-
* console.log(first); // 10;
|
|
932
|
-
*
|
|
933
|
-
* // Verify remaining elements
|
|
934
|
-
* console.log([...list]); // [20, 30, 40];
|
|
935
|
-
* console.log(list.length); // 3;
|
|
936
|
-
*/
|
|
834
|
+
* Remove and return the tail element.
|
|
835
|
+
* @remarks Time O(N), Space O(1)
|
|
836
|
+
* @returns Removed element or undefined.
|
|
837
|
+
* @example
|
|
838
|
+
* // SinglyLinkedList pop and shift operations
|
|
839
|
+
* const list = new SinglyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
840
|
+
*
|
|
841
|
+
* // Pop removes from the end
|
|
842
|
+
* const last = list.pop();
|
|
843
|
+
* console.log(last); // 50;
|
|
844
|
+
*
|
|
845
|
+
* // Shift removes from the beginning
|
|
846
|
+
* const first = list.shift();
|
|
847
|
+
* console.log(first); // 10;
|
|
848
|
+
*
|
|
849
|
+
* // Verify remaining elements
|
|
850
|
+
* console.log([...list]); // [20, 30, 40];
|
|
851
|
+
* console.log(list.length); // 3;
|
|
852
|
+
*/
|
|
937
853
|
pop() {
|
|
938
854
|
var _a;
|
|
939
855
|
if (!this.head) return void 0;
|
|
@@ -953,57 +869,15 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
953
869
|
return value;
|
|
954
870
|
}
|
|
955
871
|
/**
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
* @example
|
|
1002
|
-
* // Remove from the front
|
|
1003
|
-
* const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
1004
|
-
* console.log(list.shift()); // 10;
|
|
1005
|
-
* console.log(list.length); // 2;
|
|
1006
|
-
*/
|
|
872
|
+
* Remove and return the head element.
|
|
873
|
+
* @remarks Time O(1), Space O(1)
|
|
874
|
+
* @returns Removed element or undefined.
|
|
875
|
+
* @example
|
|
876
|
+
* // Remove from the front
|
|
877
|
+
* const list = new SinglyLinkedList<number>([10, 20, 30]);
|
|
878
|
+
* console.log(list.shift()); // 10;
|
|
879
|
+
* console.log(list.length); // 2;
|
|
880
|
+
*/
|
|
1007
881
|
shift() {
|
|
1008
882
|
if (!this.head) return void 0;
|
|
1009
883
|
const removed = this.head;
|
|
@@ -1013,73 +887,31 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1013
887
|
return removed.value;
|
|
1014
888
|
}
|
|
1015
889
|
/**
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
* @example
|
|
1063
|
-
* // SinglyLinkedList unshift and forward traversal
|
|
1064
|
-
* const list = new SinglyLinkedList<number>([20, 30, 40]);
|
|
1065
|
-
*
|
|
1066
|
-
* // Unshift adds to the beginning
|
|
1067
|
-
* list.unshift(10);
|
|
1068
|
-
* console.log([...list]); // [10, 20, 30, 40];
|
|
1069
|
-
*
|
|
1070
|
-
* // Access elements (forward traversal only for singly linked)
|
|
1071
|
-
* const second = list.at(1);
|
|
1072
|
-
* console.log(second); // 20;
|
|
1073
|
-
*
|
|
1074
|
-
* // SinglyLinkedList allows forward iteration only
|
|
1075
|
-
* const elements: number[] = [];
|
|
1076
|
-
* for (const item of list) {
|
|
1077
|
-
* elements.push(item);
|
|
1078
|
-
* }
|
|
1079
|
-
* console.log(elements); // [10, 20, 30, 40];
|
|
1080
|
-
*
|
|
1081
|
-
* console.log(list.length); // 4;
|
|
1082
|
-
*/
|
|
890
|
+
* Prepend an element/node to the head.
|
|
891
|
+
* @remarks Time O(1), Space O(1)
|
|
892
|
+
* @param elementOrNode - Element or node to prepend.
|
|
893
|
+
* @returns True when prepended.
|
|
894
|
+
* @example
|
|
895
|
+
* // SinglyLinkedList unshift and forward traversal
|
|
896
|
+
* const list = new SinglyLinkedList<number>([20, 30, 40]);
|
|
897
|
+
*
|
|
898
|
+
* // Unshift adds to the beginning
|
|
899
|
+
* list.unshift(10);
|
|
900
|
+
* console.log([...list]); // [10, 20, 30, 40];
|
|
901
|
+
*
|
|
902
|
+
* // Access elements (forward traversal only for singly linked)
|
|
903
|
+
* const second = list.at(1);
|
|
904
|
+
* console.log(second); // 20;
|
|
905
|
+
*
|
|
906
|
+
* // SinglyLinkedList allows forward iteration only
|
|
907
|
+
* const elements: number[] = [];
|
|
908
|
+
* for (const item of list) {
|
|
909
|
+
* elements.push(item);
|
|
910
|
+
* }
|
|
911
|
+
* console.log(elements); // [10, 20, 30, 40];
|
|
912
|
+
*
|
|
913
|
+
* console.log(list.length); // 4;
|
|
914
|
+
*/
|
|
1083
915
|
unshift(elementOrNode) {
|
|
1084
916
|
const newNode = this._ensureNode(elementOrNode);
|
|
1085
917
|
if (!this.head) {
|
|
@@ -1135,59 +967,17 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1135
967
|
return void 0;
|
|
1136
968
|
}
|
|
1137
969
|
/**
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
* @example
|
|
1185
|
-
* // Access element by index
|
|
1186
|
-
* const list = new SinglyLinkedList<string>(['a', 'b', 'c', 'd']);
|
|
1187
|
-
* console.log(list.at(0)); // 'a';
|
|
1188
|
-
* console.log(list.at(2)); // 'c';
|
|
1189
|
-
* console.log(list.at(3)); // 'd';
|
|
1190
|
-
*/
|
|
970
|
+
* Get the element at a given index.
|
|
971
|
+
* @remarks Time O(N), Space O(1)
|
|
972
|
+
* @param index - Zero-based index.
|
|
973
|
+
* @returns Element or undefined.
|
|
974
|
+
* @example
|
|
975
|
+
* // Access element by index
|
|
976
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c', 'd']);
|
|
977
|
+
* console.log(list.at(0)); // 'a';
|
|
978
|
+
* console.log(list.at(2)); // 'c';
|
|
979
|
+
* console.log(list.at(3)); // 'd';
|
|
980
|
+
*/
|
|
1191
981
|
at(index) {
|
|
1192
982
|
if (index < 0 || index >= this._length) return void 0;
|
|
1193
983
|
let current = this.head;
|
|
@@ -1204,54 +994,15 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1204
994
|
return elementNodeOrPredicate instanceof SinglyLinkedListNode;
|
|
1205
995
|
}
|
|
1206
996
|
/**
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
* @example
|
|
1251
|
-
* // Get node at index
|
|
1252
|
-
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
1253
|
-
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
1254
|
-
*/
|
|
997
|
+
* Get the node reference at a given index.
|
|
998
|
+
* @remarks Time O(N), Space O(1)
|
|
999
|
+
* @param index - Zero-based index.
|
|
1000
|
+
* @returns Node or undefined.
|
|
1001
|
+
* @example
|
|
1002
|
+
* // Get node at index
|
|
1003
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
1004
|
+
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
1005
|
+
*/
|
|
1255
1006
|
getNodeAt(index) {
|
|
1256
1007
|
if (index < 0 || index >= this._length) return void 0;
|
|
1257
1008
|
let current = this.head;
|
|
@@ -1259,55 +1010,16 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1259
1010
|
return current;
|
|
1260
1011
|
}
|
|
1261
1012
|
/**
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
* @example
|
|
1306
|
-
* // Remove by index
|
|
1307
|
-
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
1308
|
-
* list.deleteAt(1);
|
|
1309
|
-
* console.log(list.toArray()); // ['a', 'c'];
|
|
1310
|
-
*/
|
|
1013
|
+
* Delete the element at an index.
|
|
1014
|
+
* @remarks Time O(N), Space O(1)
|
|
1015
|
+
* @param index - Zero-based index.
|
|
1016
|
+
* @returns Removed element or undefined.
|
|
1017
|
+
* @example
|
|
1018
|
+
* // Remove by index
|
|
1019
|
+
* const list = new SinglyLinkedList<string>(['a', 'b', 'c']);
|
|
1020
|
+
* list.deleteAt(1);
|
|
1021
|
+
* console.log(list.toArray()); // ['a', 'c'];
|
|
1022
|
+
*/
|
|
1311
1023
|
deleteAt(index) {
|
|
1312
1024
|
if (index < 0 || index >= this._length) return void 0;
|
|
1313
1025
|
if (index === 0) return this.shift();
|
|
@@ -1320,55 +1032,16 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1320
1032
|
return value;
|
|
1321
1033
|
}
|
|
1322
1034
|
/**
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
* @example
|
|
1367
|
-
* // Remove first occurrence
|
|
1368
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3, 2]);
|
|
1369
|
-
* list.delete(2);
|
|
1370
|
-
* console.log(list.toArray()); // [1, 3, 2];
|
|
1371
|
-
*/
|
|
1035
|
+
* Delete the first match by value/node.
|
|
1036
|
+
* @remarks Time O(N), Space O(1)
|
|
1037
|
+
* @param [elementOrNode] - Element or node to remove; if omitted/undefined, nothing happens.
|
|
1038
|
+
* @returns True if removed.
|
|
1039
|
+
* @example
|
|
1040
|
+
* // Remove first occurrence
|
|
1041
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 2]);
|
|
1042
|
+
* list.delete(2);
|
|
1043
|
+
* console.log(list.toArray()); // [1, 3, 2];
|
|
1044
|
+
*/
|
|
1372
1045
|
delete(elementOrNode) {
|
|
1373
1046
|
if (elementOrNode === void 0 || !this.head) return false;
|
|
1374
1047
|
const node = this.isNode(elementOrNode) ? elementOrNode : this.getNode(elementOrNode);
|
|
@@ -1385,56 +1058,17 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1385
1058
|
return true;
|
|
1386
1059
|
}
|
|
1387
1060
|
/**
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
* @example
|
|
1433
|
-
* // Insert at index
|
|
1434
|
-
* const list = new SinglyLinkedList<number>([1, 3]);
|
|
1435
|
-
* list.addAt(1, 2);
|
|
1436
|
-
* console.log(list.toArray()); // [1, 2, 3];
|
|
1437
|
-
*/
|
|
1061
|
+
* Insert a new element/node at an index, shifting following nodes.
|
|
1062
|
+
* @remarks Time O(N), Space O(1)
|
|
1063
|
+
* @param index - Zero-based index.
|
|
1064
|
+
* @param newElementOrNode - Element or node to insert.
|
|
1065
|
+
* @returns True if inserted.
|
|
1066
|
+
* @example
|
|
1067
|
+
* // Insert at index
|
|
1068
|
+
* const list = new SinglyLinkedList<number>([1, 3]);
|
|
1069
|
+
* list.addAt(1, 2);
|
|
1070
|
+
* console.log(list.toArray()); // [1, 2, 3];
|
|
1071
|
+
*/
|
|
1438
1072
|
addAt(index, newElementOrNode) {
|
|
1439
1073
|
if (index < 0 || index > this._length) return false;
|
|
1440
1074
|
if (index === 0) return this.unshift(newElementOrNode);
|
|
@@ -1460,163 +1094,41 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1460
1094
|
return true;
|
|
1461
1095
|
}
|
|
1462
1096
|
/**
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
* @example
|
|
1507
|
-
* // Check empty
|
|
1508
|
-
* console.log(new SinglyLinkedList().isEmpty()); // true;
|
|
1509
|
-
*/
|
|
1097
|
+
* Check whether the list is empty.
|
|
1098
|
+
* @remarks Time O(1), Space O(1)
|
|
1099
|
+
* @returns True if length is 0.
|
|
1100
|
+
* @example
|
|
1101
|
+
* // Check empty
|
|
1102
|
+
* console.log(new SinglyLinkedList().isEmpty()); // true;
|
|
1103
|
+
*/
|
|
1510
1104
|
isEmpty() {
|
|
1511
1105
|
return this._length === 0;
|
|
1512
1106
|
}
|
|
1513
1107
|
/**
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
* @example
|
|
1558
|
-
* // Remove all
|
|
1559
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1560
|
-
* list.clear();
|
|
1561
|
-
* console.log(list.isEmpty()); // true;
|
|
1562
|
-
*/
|
|
1108
|
+
* Remove all nodes and reset length.
|
|
1109
|
+
* @remarks Time O(N), Space O(1)
|
|
1110
|
+
* @returns void
|
|
1111
|
+
* @example
|
|
1112
|
+
* // Remove all
|
|
1113
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1114
|
+
* list.clear();
|
|
1115
|
+
* console.log(list.isEmpty()); // true;
|
|
1116
|
+
*/
|
|
1563
1117
|
clear() {
|
|
1564
1118
|
this._head = void 0;
|
|
1565
1119
|
this._tail = void 0;
|
|
1566
1120
|
this._length = 0;
|
|
1567
1121
|
}
|
|
1568
1122
|
/**
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
* @example
|
|
1615
|
-
* // Reverse the list in-place
|
|
1616
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3, 4]);
|
|
1617
|
-
* list.reverse();
|
|
1618
|
-
* console.log([...list]); // [4, 3, 2, 1];
|
|
1619
|
-
*/
|
|
1123
|
+
* Reverse the list in place.
|
|
1124
|
+
* @remarks Time O(N), Space O(1)
|
|
1125
|
+
* @returns This list.
|
|
1126
|
+
* @example
|
|
1127
|
+
* // Reverse the list in-place
|
|
1128
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 4]);
|
|
1129
|
+
* list.reverse();
|
|
1130
|
+
* console.log([...list]); // [4, 3, 2, 1];
|
|
1131
|
+
*/
|
|
1620
1132
|
reverse() {
|
|
1621
1133
|
if (!this.head || this.head === this.tail) return this;
|
|
1622
1134
|
let prev;
|
|
@@ -1791,126 +1303,44 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1791
1303
|
return false;
|
|
1792
1304
|
}
|
|
1793
1305
|
/**
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
* @example
|
|
1838
|
-
* // Deep copy
|
|
1839
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1840
|
-
* const copy = list.clone();
|
|
1841
|
-
* copy.pop();
|
|
1842
|
-
* console.log(list.length); // 3;
|
|
1843
|
-
* console.log(copy.length); // 2;
|
|
1844
|
-
*/
|
|
1306
|
+
* Deep clone this list (values are copied by reference).
|
|
1307
|
+
* @remarks Time O(N), Space O(N)
|
|
1308
|
+
* @returns A new list with the same element sequence.
|
|
1309
|
+
* @example
|
|
1310
|
+
* // Deep copy
|
|
1311
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1312
|
+
* const copy = list.clone();
|
|
1313
|
+
* copy.pop();
|
|
1314
|
+
* console.log(list.length); // 3;
|
|
1315
|
+
* console.log(copy.length); // 2;
|
|
1316
|
+
*/
|
|
1845
1317
|
clone() {
|
|
1846
1318
|
const out = this._createInstance();
|
|
1847
1319
|
for (const v of this) out.push(v);
|
|
1848
1320
|
return out;
|
|
1849
1321
|
}
|
|
1850
1322
|
/**
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
* @example
|
|
1899
|
-
* // SinglyLinkedList filter and map operations
|
|
1900
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
1901
|
-
*
|
|
1902
|
-
* // Filter even numbers
|
|
1903
|
-
* const filtered = list.filter(value => value % 2 === 0);
|
|
1904
|
-
* console.log(filtered.length); // 2;
|
|
1905
|
-
*
|
|
1906
|
-
* // Map to double values
|
|
1907
|
-
* const doubled = list.map(value => value * 2);
|
|
1908
|
-
* console.log(doubled.length); // 5;
|
|
1909
|
-
*
|
|
1910
|
-
* // Use reduce to sum
|
|
1911
|
-
* const sum = list.reduce((acc, value) => acc + value, 0);
|
|
1912
|
-
* console.log(sum); // 15;
|
|
1913
|
-
*/
|
|
1323
|
+
* Filter values into a new list of the same class.
|
|
1324
|
+
* @remarks Time O(N), Space O(N)
|
|
1325
|
+
* @param callback - Predicate (value, index, list) → boolean to keep value.
|
|
1326
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
1327
|
+
* @returns A new list with kept values.
|
|
1328
|
+
* @example
|
|
1329
|
+
* // SinglyLinkedList filter and map operations
|
|
1330
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
1331
|
+
*
|
|
1332
|
+
* // Filter even numbers
|
|
1333
|
+
* const filtered = list.filter(value => value % 2 === 0);
|
|
1334
|
+
* console.log(filtered.length); // 2;
|
|
1335
|
+
*
|
|
1336
|
+
* // Map to double values
|
|
1337
|
+
* const doubled = list.map(value => value * 2);
|
|
1338
|
+
* console.log(doubled.length); // 5;
|
|
1339
|
+
*
|
|
1340
|
+
* // Use reduce to sum
|
|
1341
|
+
* const sum = list.reduce((acc, value) => acc + value, 0);
|
|
1342
|
+
* console.log(sum); // 15;
|
|
1343
|
+
*/
|
|
1914
1344
|
filter(callback, thisArg) {
|
|
1915
1345
|
const out = this._createInstance();
|
|
1916
1346
|
let index = 0;
|
|
@@ -1934,62 +1364,20 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1934
1364
|
return out;
|
|
1935
1365
|
}
|
|
1936
1366
|
/**
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
* @example
|
|
1988
|
-
* // Transform elements
|
|
1989
|
-
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1990
|
-
* const doubled = list.map(n => n * 2);
|
|
1991
|
-
* console.log([...doubled]); // [2, 4, 6];
|
|
1992
|
-
*/
|
|
1367
|
+
* Map values into a new list (possibly different element type).
|
|
1368
|
+
* @remarks Time O(N), Space O(N)
|
|
1369
|
+
* @template EM
|
|
1370
|
+
* @template RM
|
|
1371
|
+
* @param callback - Mapping function (value, index, list) → newElement.
|
|
1372
|
+
* @param [options] - Options for the output list (e.g., maxLen, toElementFn).
|
|
1373
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
1374
|
+
* @returns A new SinglyLinkedList with mapped values.
|
|
1375
|
+
* @example
|
|
1376
|
+
* // Transform elements
|
|
1377
|
+
* const list = new SinglyLinkedList<number>([1, 2, 3]);
|
|
1378
|
+
* const doubled = list.map(n => n * 2);
|
|
1379
|
+
* console.log([...doubled]); // [2, 4, 6];
|
|
1380
|
+
*/
|
|
1993
1381
|
map(callback, options, thisArg) {
|
|
1994
1382
|
const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
|
|
1995
1383
|
let index = 0;
|
|
@@ -2189,10 +1577,10 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2189
1577
|
*/
|
|
2190
1578
|
constructor(elements = [], options) {
|
|
2191
1579
|
super(options);
|
|
2192
|
-
__publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
|
|
2193
1580
|
__publicField(this, "_head");
|
|
2194
1581
|
__publicField(this, "_tail");
|
|
2195
1582
|
__publicField(this, "_length", 0);
|
|
1583
|
+
__publicField(this, "_equals", /* @__PURE__ */ __name((a, b) => Object.is(a, b), "_equals"));
|
|
2196
1584
|
this._head = void 0;
|
|
2197
1585
|
this._tail = void 0;
|
|
2198
1586
|
this._length = 0;
|
|
@@ -2265,68 +1653,26 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2265
1653
|
return elementNodeOrPredicate instanceof DoublyLinkedListNode;
|
|
2266
1654
|
}
|
|
2267
1655
|
/**
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
* @example
|
|
2315
|
-
* // basic DoublyLinkedList creation and push operation
|
|
2316
|
-
* // Create a simple DoublyLinkedList with initial values
|
|
2317
|
-
* const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
|
|
2318
|
-
*
|
|
2319
|
-
* // Verify the list maintains insertion order
|
|
2320
|
-
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
2321
|
-
*
|
|
2322
|
-
* // Check length
|
|
2323
|
-
* console.log(list.length); // 5;
|
|
2324
|
-
*
|
|
2325
|
-
* // Push a new element to the end
|
|
2326
|
-
* list.push(6);
|
|
2327
|
-
* console.log(list.length); // 6;
|
|
2328
|
-
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
2329
|
-
*/
|
|
1656
|
+
* Append an element/node to the tail.
|
|
1657
|
+
* @remarks Time O(1), Space O(1)
|
|
1658
|
+
* @param elementOrNode - Element or node to append.
|
|
1659
|
+
* @returns True when appended.
|
|
1660
|
+
* @example
|
|
1661
|
+
* // basic DoublyLinkedList creation and push operation
|
|
1662
|
+
* // Create a simple DoublyLinkedList with initial values
|
|
1663
|
+
* const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
|
|
1664
|
+
*
|
|
1665
|
+
* // Verify the list maintains insertion order
|
|
1666
|
+
* console.log([...list]); // [1, 2, 3, 4, 5];
|
|
1667
|
+
*
|
|
1668
|
+
* // Check length
|
|
1669
|
+
* console.log(list.length); // 5;
|
|
1670
|
+
*
|
|
1671
|
+
* // Push a new element to the end
|
|
1672
|
+
* list.push(6);
|
|
1673
|
+
* console.log(list.length); // 6;
|
|
1674
|
+
* console.log([...list]); // [1, 2, 3, 4, 5, 6];
|
|
1675
|
+
*/
|
|
2330
1676
|
push(elementOrNode) {
|
|
2331
1677
|
const newNode = this._ensureNode(elementOrNode);
|
|
2332
1678
|
if (!this.head) {
|
|
@@ -2342,67 +1688,25 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2342
1688
|
return true;
|
|
2343
1689
|
}
|
|
2344
1690
|
/**
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
* @example
|
|
2391
|
-
* // DoublyLinkedList pop and shift operations
|
|
2392
|
-
* const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
2393
|
-
*
|
|
2394
|
-
* // Pop removes from the end
|
|
2395
|
-
* const last = list.pop();
|
|
2396
|
-
* console.log(last); // 50;
|
|
2397
|
-
*
|
|
2398
|
-
* // Shift removes from the beginning
|
|
2399
|
-
* const first = list.shift();
|
|
2400
|
-
* console.log(first); // 10;
|
|
2401
|
-
*
|
|
2402
|
-
* // Verify remaining elements
|
|
2403
|
-
* console.log([...list]); // [20, 30, 40];
|
|
2404
|
-
* console.log(list.length); // 3;
|
|
2405
|
-
*/
|
|
1691
|
+
* Remove and return the tail element.
|
|
1692
|
+
* @remarks Time O(1), Space O(1)
|
|
1693
|
+
* @returns Removed element or undefined.
|
|
1694
|
+
* @example
|
|
1695
|
+
* // DoublyLinkedList pop and shift operations
|
|
1696
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
|
|
1697
|
+
*
|
|
1698
|
+
* // Pop removes from the end
|
|
1699
|
+
* const last = list.pop();
|
|
1700
|
+
* console.log(last); // 50;
|
|
1701
|
+
*
|
|
1702
|
+
* // Shift removes from the beginning
|
|
1703
|
+
* const first = list.shift();
|
|
1704
|
+
* console.log(first); // 10;
|
|
1705
|
+
*
|
|
1706
|
+
* // Verify remaining elements
|
|
1707
|
+
* console.log([...list]); // [20, 30, 40];
|
|
1708
|
+
* console.log(list.length); // 3;
|
|
1709
|
+
*/
|
|
2406
1710
|
pop() {
|
|
2407
1711
|
if (!this.tail) return void 0;
|
|
2408
1712
|
const removed = this.tail;
|
|
@@ -2417,57 +1721,15 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2417
1721
|
return removed.value;
|
|
2418
1722
|
}
|
|
2419
1723
|
/**
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
* @example
|
|
2466
|
-
* // Remove from the front
|
|
2467
|
-
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
2468
|
-
* console.log(list.shift()); // 10;
|
|
2469
|
-
* console.log(list.first); // 20;
|
|
2470
|
-
*/
|
|
1724
|
+
* Remove and return the head element.
|
|
1725
|
+
* @remarks Time O(1), Space O(1)
|
|
1726
|
+
* @returns Removed element or undefined.
|
|
1727
|
+
* @example
|
|
1728
|
+
* // Remove from the front
|
|
1729
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
1730
|
+
* console.log(list.shift()); // 10;
|
|
1731
|
+
* console.log(list.first); // 20;
|
|
1732
|
+
*/
|
|
2471
1733
|
shift() {
|
|
2472
1734
|
if (!this.head) return void 0;
|
|
2473
1735
|
const removed = this.head;
|
|
@@ -2482,58 +1744,16 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2482
1744
|
return removed.value;
|
|
2483
1745
|
}
|
|
2484
1746
|
/**
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
* @example
|
|
2532
|
-
* // Add to the front
|
|
2533
|
-
* const list = new DoublyLinkedList<number>([2, 3]);
|
|
2534
|
-
* list.unshift(1);
|
|
2535
|
-
* console.log([...list]); // [1, 2, 3];
|
|
2536
|
-
*/
|
|
1747
|
+
* Prepend an element/node to the head.
|
|
1748
|
+
* @remarks Time O(1), Space O(1)
|
|
1749
|
+
* @param elementOrNode - Element or node to prepend.
|
|
1750
|
+
* @returns True when prepended.
|
|
1751
|
+
* @example
|
|
1752
|
+
* // Add to the front
|
|
1753
|
+
* const list = new DoublyLinkedList<number>([2, 3]);
|
|
1754
|
+
* list.unshift(1);
|
|
1755
|
+
* console.log([...list]); // [1, 2, 3];
|
|
1756
|
+
*/
|
|
2537
1757
|
unshift(elementOrNode) {
|
|
2538
1758
|
const newNode = this._ensureNode(elementOrNode);
|
|
2539
1759
|
if (!this.head) {
|
|
@@ -2577,58 +1797,16 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2577
1797
|
return ans;
|
|
2578
1798
|
}
|
|
2579
1799
|
/**
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
* @example
|
|
2627
|
-
* // Access by index
|
|
2628
|
-
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
2629
|
-
* console.log(list.at(1)); // 'b';
|
|
2630
|
-
* console.log(list.at(2)); // 'c';
|
|
2631
|
-
*/
|
|
1800
|
+
* Get the element at a given index.
|
|
1801
|
+
* @remarks Time O(N), Space O(1)
|
|
1802
|
+
* @param index - Zero-based index.
|
|
1803
|
+
* @returns Element or undefined.
|
|
1804
|
+
* @example
|
|
1805
|
+
* // Access by index
|
|
1806
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
1807
|
+
* console.log(list.at(1)); // 'b';
|
|
1808
|
+
* console.log(list.at(2)); // 'c';
|
|
1809
|
+
*/
|
|
2632
1810
|
at(index) {
|
|
2633
1811
|
if (index < 0 || index >= this._length) return void 0;
|
|
2634
1812
|
let current = this.head;
|
|
@@ -2636,54 +1814,15 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2636
1814
|
return current == null ? void 0 : current.value;
|
|
2637
1815
|
}
|
|
2638
1816
|
/**
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
* @example
|
|
2683
|
-
* // Get node at index
|
|
2684
|
-
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
2685
|
-
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
2686
|
-
*/
|
|
1817
|
+
* Get the node reference at a given index.
|
|
1818
|
+
* @remarks Time O(N), Space O(1)
|
|
1819
|
+
* @param index - Zero-based index.
|
|
1820
|
+
* @returns Node or undefined.
|
|
1821
|
+
* @example
|
|
1822
|
+
* // Get node at index
|
|
1823
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
1824
|
+
* console.log(list.getNodeAt(1)?.value); // 'b';
|
|
1825
|
+
*/
|
|
2687
1826
|
getNodeAt(index) {
|
|
2688
1827
|
if (index < 0 || index >= this._length) return void 0;
|
|
2689
1828
|
let current = this.head;
|
|
@@ -2722,56 +1861,17 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2722
1861
|
return void 0;
|
|
2723
1862
|
}
|
|
2724
1863
|
/**
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
* @example
|
|
2770
|
-
* // Insert at position
|
|
2771
|
-
* const list = new DoublyLinkedList<number>([1, 3]);
|
|
2772
|
-
* list.addAt(1, 2);
|
|
2773
|
-
* console.log(list.toArray()); // [1, 2, 3];
|
|
2774
|
-
*/
|
|
1864
|
+
* Insert a new element/node at an index, shifting following nodes.
|
|
1865
|
+
* @remarks Time O(N), Space O(1)
|
|
1866
|
+
* @param index - Zero-based index.
|
|
1867
|
+
* @param newElementOrNode - Element or node to insert.
|
|
1868
|
+
* @returns True if inserted.
|
|
1869
|
+
* @example
|
|
1870
|
+
* // Insert at position
|
|
1871
|
+
* const list = new DoublyLinkedList<number>([1, 3]);
|
|
1872
|
+
* list.addAt(1, 2);
|
|
1873
|
+
* console.log(list.toArray()); // [1, 2, 3];
|
|
1874
|
+
*/
|
|
2775
1875
|
addAt(index, newElementOrNode) {
|
|
2776
1876
|
if (index < 0 || index > this._length) return false;
|
|
2777
1877
|
if (index === 0) return this.unshift(newElementOrNode);
|
|
@@ -2838,55 +1938,16 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2838
1938
|
return true;
|
|
2839
1939
|
}
|
|
2840
1940
|
/**
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
* @example
|
|
2885
|
-
* // Remove by index
|
|
2886
|
-
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
2887
|
-
* list.deleteAt(1);
|
|
2888
|
-
* console.log(list.toArray()); // ['a', 'c'];
|
|
2889
|
-
*/
|
|
1941
|
+
* Delete the element at an index.
|
|
1942
|
+
* @remarks Time O(N), Space O(1)
|
|
1943
|
+
* @param index - Zero-based index.
|
|
1944
|
+
* @returns Removed element or undefined.
|
|
1945
|
+
* @example
|
|
1946
|
+
* // Remove by index
|
|
1947
|
+
* const list = new DoublyLinkedList<string>(['a', 'b', 'c']);
|
|
1948
|
+
* list.deleteAt(1);
|
|
1949
|
+
* console.log(list.toArray()); // ['a', 'c'];
|
|
1950
|
+
*/
|
|
2890
1951
|
deleteAt(index) {
|
|
2891
1952
|
if (index < 0 || index >= this._length) return;
|
|
2892
1953
|
if (index === 0) return this.shift();
|
|
@@ -2900,55 +1961,16 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2900
1961
|
return removedNode.value;
|
|
2901
1962
|
}
|
|
2902
1963
|
/**
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
* @example
|
|
2947
|
-
* // Remove first occurrence
|
|
2948
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3, 2]);
|
|
2949
|
-
* list.delete(2);
|
|
2950
|
-
* console.log(list.toArray()); // [1, 3, 2];
|
|
2951
|
-
*/
|
|
1964
|
+
* Delete the first match by value/node.
|
|
1965
|
+
* @remarks Time O(N), Space O(1)
|
|
1966
|
+
* @param [elementOrNode] - Element or node to remove.
|
|
1967
|
+
* @returns True if removed.
|
|
1968
|
+
* @example
|
|
1969
|
+
* // Remove first occurrence
|
|
1970
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 2]);
|
|
1971
|
+
* list.delete(2);
|
|
1972
|
+
* console.log(list.toArray()); // [1, 3, 2];
|
|
1973
|
+
*/
|
|
2952
1974
|
delete(elementOrNode) {
|
|
2953
1975
|
const node = this.getNode(elementOrNode);
|
|
2954
1976
|
if (!node) return false;
|
|
@@ -2964,161 +1986,42 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
2964
1986
|
return true;
|
|
2965
1987
|
}
|
|
2966
1988
|
/**
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
* @example
|
|
3011
|
-
* // Check empty
|
|
3012
|
-
* console.log(new DoublyLinkedList().isEmpty()); // true;
|
|
3013
|
-
*/
|
|
1989
|
+
* Check whether the list is empty.
|
|
1990
|
+
* @remarks Time O(1), Space O(1)
|
|
1991
|
+
* @returns True if length is 0.
|
|
1992
|
+
* @example
|
|
1993
|
+
* // Check empty
|
|
1994
|
+
* console.log(new DoublyLinkedList().isEmpty()); // true;
|
|
1995
|
+
*/
|
|
3014
1996
|
isEmpty() {
|
|
3015
1997
|
return this._length === 0;
|
|
3016
1998
|
}
|
|
3017
1999
|
/**
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
* @example
|
|
3062
|
-
* // Remove all
|
|
3063
|
-
* const list = new DoublyLinkedList<number>([1, 2]);
|
|
3064
|
-
* list.clear();
|
|
3065
|
-
* console.log(list.isEmpty()); // true;
|
|
3066
|
-
*/
|
|
2000
|
+
* Remove all nodes and reset length.
|
|
2001
|
+
* @remarks Time O(N), Space O(1)
|
|
2002
|
+
* @returns void
|
|
2003
|
+
* @example
|
|
2004
|
+
* // Remove all
|
|
2005
|
+
* const list = new DoublyLinkedList<number>([1, 2]);
|
|
2006
|
+
* list.clear();
|
|
2007
|
+
* console.log(list.isEmpty()); // true;
|
|
2008
|
+
*/
|
|
3067
2009
|
clear() {
|
|
3068
2010
|
this._head = void 0;
|
|
3069
2011
|
this._tail = void 0;
|
|
3070
2012
|
this._length = 0;
|
|
3071
2013
|
}
|
|
3072
2014
|
/**
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
* @example
|
|
3117
|
-
* // Search with predicate
|
|
3118
|
-
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
3119
|
-
* const found = list.search(node => node.value > 15);
|
|
3120
|
-
* console.log(found); // 20;
|
|
3121
|
-
*/
|
|
2015
|
+
* Find the first value matching a predicate scanning forward.
|
|
2016
|
+
* @remarks Time O(N), Space O(1)
|
|
2017
|
+
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
2018
|
+
* @returns Matched value or undefined.
|
|
2019
|
+
* @example
|
|
2020
|
+
* // Search with predicate
|
|
2021
|
+
* const list = new DoublyLinkedList<number>([10, 20, 30]);
|
|
2022
|
+
* const found = list.search(node => node.value > 15);
|
|
2023
|
+
* console.log(found); // 20;
|
|
2024
|
+
*/
|
|
3122
2025
|
search(elementNodeOrPredicate) {
|
|
3123
2026
|
const predicate = this._ensurePredicate(elementNodeOrPredicate);
|
|
3124
2027
|
let current = this.head;
|
|
@@ -3129,53 +2032,17 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
3129
2032
|
return void 0;
|
|
3130
2033
|
}
|
|
3131
2034
|
/**
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
* @example
|
|
3173
|
-
* // Find value scanning from tail
|
|
3174
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
|
|
3175
|
-
* // findLast scans from tail to head, returns first match
|
|
3176
|
-
* const found = list.findLast(node => node.value < 4);
|
|
3177
|
-
* console.log(found); // 3;
|
|
3178
|
-
*/
|
|
2035
|
+
* Find the first value matching a predicate scanning backward.
|
|
2036
|
+
* @remarks Time O(N), Space O(1)
|
|
2037
|
+
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
2038
|
+
* @returns Matched value or undefined.
|
|
2039
|
+
* @example
|
|
2040
|
+
* // Find value scanning from tail
|
|
2041
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
|
|
2042
|
+
* // findLast scans from tail to head, returns first match
|
|
2043
|
+
* const found = list.findLast(node => node.value < 4);
|
|
2044
|
+
* console.log(found); // 3;
|
|
2045
|
+
*/
|
|
3179
2046
|
/**
|
|
3180
2047
|
* @deprecated Use `findLast` instead. Will be removed in a future major version.
|
|
3181
2048
|
*/
|
|
@@ -3183,19 +2050,17 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
3183
2050
|
return this.findLast(elementNodeOrPredicate);
|
|
3184
2051
|
}
|
|
3185
2052
|
/**
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
* console.log(found); // 3;
|
|
3198
|
-
*/
|
|
2053
|
+
* Find the first value matching a predicate scanning backward (tail → head).
|
|
2054
|
+
* @remarks Time O(N), Space O(1)
|
|
2055
|
+
* @param elementNodeOrPredicate - Element, node, or predicate to match.
|
|
2056
|
+
* @returns Matching value or undefined.
|
|
2057
|
+
* @example
|
|
2058
|
+
* // Find value scanning from tail
|
|
2059
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
|
|
2060
|
+
* // findLast scans from tail to head, returns first match
|
|
2061
|
+
* const found = list.findLast(node => node.value < 4);
|
|
2062
|
+
* console.log(found); // 3;
|
|
2063
|
+
*/
|
|
3199
2064
|
findLast(elementNodeOrPredicate) {
|
|
3200
2065
|
const predicate = this._ensurePredicate(elementNodeOrPredicate);
|
|
3201
2066
|
let current = this.tail;
|
|
@@ -3222,57 +2087,15 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
3222
2087
|
return -1;
|
|
3223
2088
|
}
|
|
3224
2089
|
/**
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
* @example
|
|
3271
|
-
* // Reverse in-place
|
|
3272
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
3273
|
-
* list.reverse();
|
|
3274
|
-
* console.log([...list]); // [3, 2, 1];
|
|
3275
|
-
*/
|
|
2090
|
+
* Reverse the list in place.
|
|
2091
|
+
* @remarks Time O(N), Space O(1)
|
|
2092
|
+
* @returns This list.
|
|
2093
|
+
* @example
|
|
2094
|
+
* // Reverse in-place
|
|
2095
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
2096
|
+
* list.reverse();
|
|
2097
|
+
* console.log([...list]); // [3, 2, 1];
|
|
2098
|
+
*/
|
|
3276
2099
|
reverse() {
|
|
3277
2100
|
let current = this.head;
|
|
3278
2101
|
[this._head, this._tail] = [this.tail, this.head];
|
|
@@ -3313,115 +2136,33 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
3313
2136
|
return this;
|
|
3314
2137
|
}
|
|
3315
2138
|
/**
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
* @example
|
|
3360
|
-
* // Deep copy
|
|
3361
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
3362
|
-
* const copy = list.clone();
|
|
3363
|
-
* copy.pop();
|
|
3364
|
-
* console.log(list.length); // 3;
|
|
3365
|
-
*/
|
|
2139
|
+
* Deep clone this list (values are copied by reference).
|
|
2140
|
+
* @remarks Time O(N), Space O(N)
|
|
2141
|
+
* @returns A new list with the same element sequence.
|
|
2142
|
+
* @example
|
|
2143
|
+
* // Deep copy
|
|
2144
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3]);
|
|
2145
|
+
* const copy = list.clone();
|
|
2146
|
+
* copy.pop();
|
|
2147
|
+
* console.log(list.length); // 3;
|
|
2148
|
+
*/
|
|
3366
2149
|
clone() {
|
|
3367
2150
|
const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
|
|
3368
2151
|
for (const v of this) out.push(v);
|
|
3369
2152
|
return out;
|
|
3370
2153
|
}
|
|
3371
2154
|
/**
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
* @example
|
|
3420
|
-
* // Filter elements
|
|
3421
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
3422
|
-
* const evens = list.filter(n => n % 2 === 0);
|
|
3423
|
-
* console.log([...evens]); // [2, 4];
|
|
3424
|
-
*/
|
|
2155
|
+
* Filter values into a new list of the same class.
|
|
2156
|
+
* @remarks Time O(N), Space O(N)
|
|
2157
|
+
* @param callback - Predicate (value, index, list) → boolean to keep value.
|
|
2158
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
2159
|
+
* @returns A new list with kept values.
|
|
2160
|
+
* @example
|
|
2161
|
+
* // Filter elements
|
|
2162
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
2163
|
+
* const evens = list.filter(n => n % 2 === 0);
|
|
2164
|
+
* console.log([...evens]); // [2, 4];
|
|
2165
|
+
*/
|
|
3425
2166
|
filter(callback, thisArg) {
|
|
3426
2167
|
const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
|
|
3427
2168
|
let index = 0;
|
|
@@ -3445,71 +2186,29 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
|
|
|
3445
2186
|
return out;
|
|
3446
2187
|
}
|
|
3447
2188
|
/**
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
* @example
|
|
3499
|
-
* // DoublyLinkedList for...of iteration and map operation
|
|
3500
|
-
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
3501
|
-
*
|
|
3502
|
-
* // Iterate through list
|
|
3503
|
-
* const doubled = list.map(value => value * 2);
|
|
3504
|
-
* console.log(doubled.length); // 5;
|
|
3505
|
-
*
|
|
3506
|
-
* // Use for...of loop
|
|
3507
|
-
* const result: number[] = [];
|
|
3508
|
-
* for (const item of list) {
|
|
3509
|
-
* result.push(item);
|
|
3510
|
-
* }
|
|
3511
|
-
* console.log(result); // [1, 2, 3, 4, 5];
|
|
3512
|
-
*/
|
|
2189
|
+
* Map values into a new list (possibly different element type).
|
|
2190
|
+
* @remarks Time O(N), Space O(N)
|
|
2191
|
+
* @template EM
|
|
2192
|
+
* @template RM
|
|
2193
|
+
* @param callback - Mapping function (value, index, list) → newElement.
|
|
2194
|
+
* @param [options] - Options for the output list (e.g., maxLen, toElementFn).
|
|
2195
|
+
* @param [thisArg] - Value for `this` inside the callback.
|
|
2196
|
+
* @returns A new DoublyLinkedList with mapped values.
|
|
2197
|
+
* @example
|
|
2198
|
+
* // DoublyLinkedList for...of iteration and map operation
|
|
2199
|
+
* const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
|
|
2200
|
+
*
|
|
2201
|
+
* // Iterate through list
|
|
2202
|
+
* const doubled = list.map(value => value * 2);
|
|
2203
|
+
* console.log(doubled.length); // 5;
|
|
2204
|
+
*
|
|
2205
|
+
* // Use for...of loop
|
|
2206
|
+
* const result: number[] = [];
|
|
2207
|
+
* for (const item of list) {
|
|
2208
|
+
* result.push(item);
|
|
2209
|
+
* }
|
|
2210
|
+
* console.log(result); // [1, 2, 3, 4, 5];
|
|
2211
|
+
*/
|
|
3513
2212
|
map(callback, options, thisArg) {
|
|
3514
2213
|
const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
|
|
3515
2214
|
let index = 0;
|
|
@@ -3798,11 +2497,11 @@ var _comparator, _isDefaultComparator;
|
|
|
3798
2497
|
var _SkipList = class _SkipList extends IterableEntryBase {
|
|
3799
2498
|
constructor(entries = [], options = {}) {
|
|
3800
2499
|
super();
|
|
3801
|
-
__privateAdd(this, _comparator);
|
|
3802
|
-
__privateAdd(this, _isDefaultComparator);
|
|
3803
2500
|
// ─── Internal state ──────────────────────────────────────────
|
|
3804
2501
|
__publicField(this, "_head");
|
|
3805
2502
|
__publicField(this, "_level", 0);
|
|
2503
|
+
__privateAdd(this, _comparator);
|
|
2504
|
+
__privateAdd(this, _isDefaultComparator);
|
|
3806
2505
|
__publicField(this, "_size", 0);
|
|
3807
2506
|
__publicField(this, "_maxLevel", 16);
|
|
3808
2507
|
__publicField(this, "_probability", 0.5);
|
|
@@ -3826,6 +2525,19 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
3826
2525
|
this.set(k, v);
|
|
3827
2526
|
}
|
|
3828
2527
|
}
|
|
2528
|
+
// ─── Size & lifecycle ────────────────────────────────────────
|
|
2529
|
+
get size() {
|
|
2530
|
+
return this._size;
|
|
2531
|
+
}
|
|
2532
|
+
get maxLevel() {
|
|
2533
|
+
return this._maxLevel;
|
|
2534
|
+
}
|
|
2535
|
+
get probability() {
|
|
2536
|
+
return this._probability;
|
|
2537
|
+
}
|
|
2538
|
+
get comparator() {
|
|
2539
|
+
return __privateGet(this, _comparator);
|
|
2540
|
+
}
|
|
3829
2541
|
/**
|
|
3830
2542
|
* Creates a default comparator supporting number, string, Date, and bigint.
|
|
3831
2543
|
*/
|
|
@@ -3849,168 +2561,44 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
3849
2561
|
raise(TypeError, ERR.comparatorRequired("SkipList"));
|
|
3850
2562
|
};
|
|
3851
2563
|
}
|
|
3852
|
-
// ─── Size & lifecycle ────────────────────────────────────────
|
|
3853
|
-
get size() {
|
|
3854
|
-
return this._size;
|
|
3855
|
-
}
|
|
3856
|
-
get maxLevel() {
|
|
3857
|
-
return this._maxLevel;
|
|
3858
|
-
}
|
|
3859
|
-
get probability() {
|
|
3860
|
-
return this._probability;
|
|
3861
|
-
}
|
|
3862
|
-
get comparator() {
|
|
3863
|
-
return __privateGet(this, _comparator);
|
|
3864
|
-
}
|
|
3865
2564
|
/**
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
* @example
|
|
3907
|
-
* // Check if empty
|
|
3908
|
-
* const sl = new SkipList<number, string>();
|
|
3909
|
-
* console.log(sl.isEmpty()); // true;
|
|
3910
|
-
*/
|
|
2565
|
+
* Check if empty
|
|
2566
|
+
* @example
|
|
2567
|
+
* // Check if empty
|
|
2568
|
+
* const sl = new SkipList<number, string>();
|
|
2569
|
+
* console.log(sl.isEmpty()); // true;
|
|
2570
|
+
*/
|
|
3911
2571
|
isEmpty() {
|
|
3912
2572
|
return this._size === 0;
|
|
3913
2573
|
}
|
|
3914
2574
|
/**
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
* @example
|
|
3956
|
-
* // Remove all entries
|
|
3957
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
|
|
3958
|
-
* sl.clear();
|
|
3959
|
-
* console.log(sl.isEmpty()); // true;
|
|
3960
|
-
*/
|
|
2575
|
+
* Remove all entries
|
|
2576
|
+
* @example
|
|
2577
|
+
* // Remove all entries
|
|
2578
|
+
* const sl = new SkipList<number, string>([
|
|
2579
|
+
* [1, 'a'],
|
|
2580
|
+
* [2, 'b']
|
|
2581
|
+
* ]);
|
|
2582
|
+
* sl.clear();
|
|
2583
|
+
* console.log(sl.isEmpty()); // true;
|
|
2584
|
+
*/
|
|
3961
2585
|
clear() {
|
|
3962
2586
|
this._head = new SkipListNode(void 0, void 0, this._maxLevel);
|
|
3963
2587
|
this._level = 0;
|
|
3964
2588
|
this._size = 0;
|
|
3965
2589
|
}
|
|
3966
2590
|
/**
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
* @example
|
|
4008
|
-
* // Create independent copy
|
|
4009
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
|
|
4010
|
-
* const copy = sl.clone();
|
|
4011
|
-
* copy.delete(1);
|
|
4012
|
-
* console.log(sl.has(1)); // true;
|
|
4013
|
-
*/
|
|
2591
|
+
* Create independent copy
|
|
2592
|
+
* @example
|
|
2593
|
+
* // Create independent copy
|
|
2594
|
+
* const sl = new SkipList<number, string>([
|
|
2595
|
+
* [1, 'a'],
|
|
2596
|
+
* [2, 'b']
|
|
2597
|
+
* ]);
|
|
2598
|
+
* const copy = sl.clone();
|
|
2599
|
+
* copy.delete(1);
|
|
2600
|
+
* console.log(sl.has(1)); // true;
|
|
2601
|
+
*/
|
|
4014
2602
|
clone() {
|
|
4015
2603
|
return new _SkipList(this, {
|
|
4016
2604
|
comparator: __privateGet(this, _isDefaultComparator) ? void 0 : __privateGet(this, _comparator),
|
|
@@ -4020,67 +2608,25 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4020
2608
|
}
|
|
4021
2609
|
// ─── Core CRUD ───────────────────────────────────────────────
|
|
4022
2610
|
/**
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
* @example
|
|
4068
|
-
* // In-memory sorted key-value store
|
|
4069
|
-
* const store = new SkipList<number, string>();
|
|
4070
|
-
*
|
|
4071
|
-
* store.set(3, 'three');
|
|
4072
|
-
* store.set(1, 'one');
|
|
4073
|
-
* store.set(5, 'five');
|
|
4074
|
-
* store.set(2, 'two');
|
|
4075
|
-
*
|
|
4076
|
-
* console.log(store.get(3)); // 'three';
|
|
4077
|
-
* console.log(store.get(1)); // 'one';
|
|
4078
|
-
* console.log(store.get(5)); // 'five';
|
|
4079
|
-
*
|
|
4080
|
-
* // Update existing key
|
|
4081
|
-
* store.set(3, 'THREE');
|
|
4082
|
-
* console.log(store.get(3)); // 'THREE';
|
|
4083
|
-
*/
|
|
2611
|
+
* Insert or update a key-value pair. Returns `this` for chaining.
|
|
2612
|
+
* Unique keys only — if key exists, value is updated in place.
|
|
2613
|
+
* @example
|
|
2614
|
+
* // In-memory sorted key-value store
|
|
2615
|
+
* const store = new SkipList<number, string>();
|
|
2616
|
+
*
|
|
2617
|
+
* store.set(3, 'three');
|
|
2618
|
+
* store.set(1, 'one');
|
|
2619
|
+
* store.set(5, 'five');
|
|
2620
|
+
* store.set(2, 'two');
|
|
2621
|
+
*
|
|
2622
|
+
* console.log(store.get(3)); // 'three';
|
|
2623
|
+
* console.log(store.get(1)); // 'one';
|
|
2624
|
+
* console.log(store.get(5)); // 'five';
|
|
2625
|
+
*
|
|
2626
|
+
* // Update existing key
|
|
2627
|
+
* store.set(3, 'THREE');
|
|
2628
|
+
* console.log(store.get(3)); // 'THREE';
|
|
2629
|
+
*/
|
|
4084
2630
|
set(key, value) {
|
|
4085
2631
|
const cmp = __privateGet(this, _comparator);
|
|
4086
2632
|
const update = this._findUpdate(key);
|
|
@@ -4105,186 +2651,64 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4105
2651
|
return this;
|
|
4106
2652
|
}
|
|
4107
2653
|
/**
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
* @example
|
|
4153
|
-
* // Building a sorted index
|
|
4154
|
-
* type Product = { id: number; name: string; price: number };
|
|
4155
|
-
* const products: Product[] = [
|
|
4156
|
-
* { id: 1, name: 'Widget', price: 25 },
|
|
4157
|
-
* { id: 2, name: 'Gadget', price: 50 },
|
|
4158
|
-
* { id: 3, name: 'Doohickey', price: 15 }
|
|
4159
|
-
* ];
|
|
4160
|
-
*
|
|
4161
|
-
* const index = new SkipList<number, Product, Product>(products, {
|
|
4162
|
-
* toEntryFn: (p: Product) => [p.price, p]
|
|
4163
|
-
* });
|
|
4164
|
-
*
|
|
4165
|
-
* // Iterate in sorted order by price
|
|
4166
|
-
* const names = [...index.values()].map(p => p!.name);
|
|
4167
|
-
* console.log(names); // ['Doohickey', 'Widget', 'Gadget'];
|
|
4168
|
-
*
|
|
4169
|
-
* // Range search: products between $20 and $60
|
|
4170
|
-
* const range = index.rangeSearch([20, 60]);
|
|
4171
|
-
* console.log(range.map(([, p]) => p!.name)); // ['Widget', 'Gadget'];
|
|
4172
|
-
*/
|
|
2654
|
+
* Get the value for a key, or `undefined` if not found.
|
|
2655
|
+
* Overrides base O(n) with O(log n) skip-list search.
|
|
2656
|
+
* @example
|
|
2657
|
+
* // Building a sorted index
|
|
2658
|
+
* type Product = { id: number; name: string; price: number };
|
|
2659
|
+
* const products: Product[] = [
|
|
2660
|
+
* { id: 1, name: 'Widget', price: 25 },
|
|
2661
|
+
* { id: 2, name: 'Gadget', price: 50 },
|
|
2662
|
+
* { id: 3, name: 'Doohickey', price: 15 }
|
|
2663
|
+
* ];
|
|
2664
|
+
*
|
|
2665
|
+
* const index = new SkipList<number, Product, Product>(products, {
|
|
2666
|
+
* toEntryFn: (p: Product) => [p.price, p]
|
|
2667
|
+
* });
|
|
2668
|
+
*
|
|
2669
|
+
* // Iterate in sorted order by price
|
|
2670
|
+
* const names = [...index.values()].map(p => p!.name);
|
|
2671
|
+
* console.log(names); // ['Doohickey', 'Widget', 'Gadget'];
|
|
2672
|
+
*
|
|
2673
|
+
* // Range search: products between $20 and $60
|
|
2674
|
+
* const range = index.rangeSearch([20, 60]);
|
|
2675
|
+
* console.log(range.map(([, p]) => p!.name)); // ['Widget', 'Gadget'];
|
|
2676
|
+
*/
|
|
4173
2677
|
get(key) {
|
|
4174
2678
|
const node = this._findNode(key);
|
|
4175
2679
|
return node ? node.value : void 0;
|
|
4176
2680
|
}
|
|
4177
2681
|
/**
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
* @example
|
|
4223
|
-
* // Check key existence
|
|
4224
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [3, 'c'], [5, 'e']]);
|
|
4225
|
-
* console.log(sl.has(3)); // true;
|
|
4226
|
-
* console.log(sl.has(4)); // false;
|
|
4227
|
-
*/
|
|
2682
|
+
* Check if a key exists.
|
|
2683
|
+
* Overrides base O(n) with O(log n) skip-list search.
|
|
2684
|
+
* @example
|
|
2685
|
+
* // Check key existence
|
|
2686
|
+
* const sl = new SkipList<number, string>([
|
|
2687
|
+
* [1, 'a'],
|
|
2688
|
+
* [3, 'c'],
|
|
2689
|
+
* [5, 'e']
|
|
2690
|
+
* ]);
|
|
2691
|
+
* console.log(sl.has(3)); // true;
|
|
2692
|
+
* console.log(sl.has(4)); // false;
|
|
2693
|
+
*/
|
|
4228
2694
|
has(key) {
|
|
4229
2695
|
return this._findNode(key) !== void 0;
|
|
4230
2696
|
}
|
|
4231
2697
|
/**
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
* @example
|
|
4276
|
-
* // Fast lookup with deletion
|
|
4277
|
-
* const cache = new SkipList<string, number>();
|
|
4278
|
-
*
|
|
4279
|
-
* cache.set('alpha', 1);
|
|
4280
|
-
* cache.set('beta', 2);
|
|
4281
|
-
* cache.set('gamma', 3);
|
|
4282
|
-
*
|
|
4283
|
-
* console.log(cache.has('beta')); // true;
|
|
4284
|
-
* cache.delete('beta');
|
|
4285
|
-
* console.log(cache.has('beta')); // false;
|
|
4286
|
-
* console.log(cache.size); // 2;
|
|
4287
|
-
*/
|
|
2698
|
+
* Delete a key. Returns `true` if the key was found and removed.
|
|
2699
|
+
* @example
|
|
2700
|
+
* // Fast lookup with deletion
|
|
2701
|
+
* const cache = new SkipList<string, number>();
|
|
2702
|
+
*
|
|
2703
|
+
* cache.set('alpha', 1);
|
|
2704
|
+
* cache.set('beta', 2);
|
|
2705
|
+
* cache.set('gamma', 3);
|
|
2706
|
+
*
|
|
2707
|
+
* console.log(cache.has('beta')); // true;
|
|
2708
|
+
* cache.delete('beta');
|
|
2709
|
+
* console.log(cache.has('beta')); // false;
|
|
2710
|
+
* console.log(cache.size); // 2;
|
|
2711
|
+
*/
|
|
4288
2712
|
delete(key) {
|
|
4289
2713
|
const cmp = __privateGet(this, _comparator);
|
|
4290
2714
|
const update = this._findUpdate(key);
|
|
@@ -4302,107 +2726,31 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4302
2726
|
}
|
|
4303
2727
|
// ─── Navigation ──────────────────────────────────────────────
|
|
4304
2728
|
/**
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
* @example
|
|
4349
|
-
* // Access the minimum entry
|
|
4350
|
-
* const sl = new SkipList<number, string>([[5, 'e'], [1, 'a'], [3, 'c']]);
|
|
4351
|
-
* console.log(sl.first()); // [1, 'a'];
|
|
4352
|
-
*/
|
|
2729
|
+
* Returns the first (smallest key) entry, or `undefined` if empty.
|
|
2730
|
+
* @example
|
|
2731
|
+
* // Access the minimum entry
|
|
2732
|
+
* const sl = new SkipList<number, string>([
|
|
2733
|
+
* [5, 'e'],
|
|
2734
|
+
* [1, 'a'],
|
|
2735
|
+
* [3, 'c']
|
|
2736
|
+
* ]);
|
|
2737
|
+
* console.log(sl.first()); // [1, 'a'];
|
|
2738
|
+
*/
|
|
4353
2739
|
first() {
|
|
4354
2740
|
const node = this._head.forward[0];
|
|
4355
2741
|
return node ? [node.key, node.value] : void 0;
|
|
4356
2742
|
}
|
|
4357
2743
|
/**
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
* @example
|
|
4402
|
-
* // Access the maximum entry
|
|
4403
|
-
* const sl = new SkipList<number, string>([[5, 'e'], [1, 'a'], [3, 'c']]);
|
|
4404
|
-
* console.log(sl.last()); // [5, 'e'];
|
|
4405
|
-
*/
|
|
2744
|
+
* Returns the last (largest key) entry, or `undefined` if empty.
|
|
2745
|
+
* @example
|
|
2746
|
+
* // Access the maximum entry
|
|
2747
|
+
* const sl = new SkipList<number, string>([
|
|
2748
|
+
* [5, 'e'],
|
|
2749
|
+
* [1, 'a'],
|
|
2750
|
+
* [3, 'c']
|
|
2751
|
+
* ]);
|
|
2752
|
+
* console.log(sl.last()); // [5, 'e'];
|
|
2753
|
+
*/
|
|
4406
2754
|
last() {
|
|
4407
2755
|
let current = this._head;
|
|
4408
2756
|
for (let i = this._level - 1; i >= 0; i--) {
|
|
@@ -4413,52 +2761,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4413
2761
|
return current === this._head ? void 0 : [current.key, current.value];
|
|
4414
2762
|
}
|
|
4415
2763
|
/**
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
* @example
|
|
4457
|
-
* // Remove and return smallest
|
|
4458
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
4459
|
-
* console.log(sl.pollFirst()); // [1, 'a'];
|
|
4460
|
-
* console.log(sl.size); // 2;
|
|
4461
|
-
*/
|
|
2764
|
+
* Remove and return the first (smallest key) entry.
|
|
2765
|
+
* @example
|
|
2766
|
+
* // Remove and return smallest
|
|
2767
|
+
* const sl = new SkipList<number, string>([
|
|
2768
|
+
* [1, 'a'],
|
|
2769
|
+
* [2, 'b'],
|
|
2770
|
+
* [3, 'c']
|
|
2771
|
+
* ]);
|
|
2772
|
+
* console.log(sl.pollFirst()); // [1, 'a'];
|
|
2773
|
+
* console.log(sl.size); // 2;
|
|
2774
|
+
*/
|
|
4462
2775
|
pollFirst() {
|
|
4463
2776
|
const entry = this.first();
|
|
4464
2777
|
if (!entry) return void 0;
|
|
@@ -4466,52 +2779,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4466
2779
|
return entry;
|
|
4467
2780
|
}
|
|
4468
2781
|
/**
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
* @example
|
|
4510
|
-
* // Remove and return largest
|
|
4511
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
4512
|
-
* console.log(sl.pollLast()); // [3, 'c'];
|
|
4513
|
-
* console.log(sl.size); // 2;
|
|
4514
|
-
*/
|
|
2782
|
+
* Remove and return the last (largest key) entry.
|
|
2783
|
+
* @example
|
|
2784
|
+
* // Remove and return largest
|
|
2785
|
+
* const sl = new SkipList<number, string>([
|
|
2786
|
+
* [1, 'a'],
|
|
2787
|
+
* [2, 'b'],
|
|
2788
|
+
* [3, 'c']
|
|
2789
|
+
* ]);
|
|
2790
|
+
* console.log(sl.pollLast()); // [3, 'c'];
|
|
2791
|
+
* console.log(sl.size); // 2;
|
|
2792
|
+
*/
|
|
4515
2793
|
pollLast() {
|
|
4516
2794
|
const entry = this.last();
|
|
4517
2795
|
if (!entry) return void 0;
|
|
@@ -4519,55 +2797,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4519
2797
|
return entry;
|
|
4520
2798
|
}
|
|
4521
2799
|
/**
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
* @example
|
|
4566
|
-
* // Least entry ≥ key
|
|
4567
|
-
* const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
|
|
4568
|
-
* console.log(sl.ceiling(15)); // [20, 'b'];
|
|
4569
|
-
* console.log(sl.ceiling(20)); // [20, 'b'];
|
|
4570
|
-
*/
|
|
2800
|
+
* Least entry ≥ key, or `undefined`.
|
|
2801
|
+
* @example
|
|
2802
|
+
* // Least entry ≥ key
|
|
2803
|
+
* const sl = new SkipList<number, string>([
|
|
2804
|
+
* [10, 'a'],
|
|
2805
|
+
* [20, 'b'],
|
|
2806
|
+
* [30, 'c']
|
|
2807
|
+
* ]);
|
|
2808
|
+
* console.log(sl.ceiling(15)); // [20, 'b'];
|
|
2809
|
+
* console.log(sl.ceiling(20)); // [20, 'b'];
|
|
2810
|
+
*/
|
|
4571
2811
|
ceiling(key) {
|
|
4572
2812
|
const cmp = __privateGet(this, _comparator);
|
|
4573
2813
|
let current = this._head;
|
|
@@ -4580,55 +2820,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4580
2820
|
return node ? [node.key, node.value] : void 0;
|
|
4581
2821
|
}
|
|
4582
2822
|
/**
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
* @example
|
|
4627
|
-
* // Greatest entry ≤ key
|
|
4628
|
-
* const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
|
|
4629
|
-
* console.log(sl.floor(25)); // [20, 'b'];
|
|
4630
|
-
* console.log(sl.floor(5)); // undefined;
|
|
4631
|
-
*/
|
|
2823
|
+
* Greatest entry ≤ key, or `undefined`.
|
|
2824
|
+
* @example
|
|
2825
|
+
* // Greatest entry ≤ key
|
|
2826
|
+
* const sl = new SkipList<number, string>([
|
|
2827
|
+
* [10, 'a'],
|
|
2828
|
+
* [20, 'b'],
|
|
2829
|
+
* [30, 'c']
|
|
2830
|
+
* ]);
|
|
2831
|
+
* console.log(sl.floor(25)); // [20, 'b'];
|
|
2832
|
+
* console.log(sl.floor(5)); // undefined;
|
|
2833
|
+
*/
|
|
4632
2834
|
floor(key) {
|
|
4633
2835
|
const cmp = __privateGet(this, _comparator);
|
|
4634
2836
|
let current = this._head;
|
|
@@ -4642,52 +2844,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4642
2844
|
return void 0;
|
|
4643
2845
|
}
|
|
4644
2846
|
/**
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
* @example
|
|
4686
|
-
* // Strictly greater entry
|
|
4687
|
-
* const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
|
|
4688
|
-
* console.log(sl.higher(15)); // [20, 'b'];
|
|
4689
|
-
* console.log(sl.higher(30)); // undefined;
|
|
4690
|
-
*/
|
|
2847
|
+
* Least entry strictly > key, or `undefined`.
|
|
2848
|
+
* @example
|
|
2849
|
+
* // Strictly greater entry
|
|
2850
|
+
* const sl = new SkipList<number, string>([
|
|
2851
|
+
* [10, 'a'],
|
|
2852
|
+
* [20, 'b'],
|
|
2853
|
+
* [30, 'c']
|
|
2854
|
+
* ]);
|
|
2855
|
+
* console.log(sl.higher(15)); // [20, 'b'];
|
|
2856
|
+
* console.log(sl.higher(30)); // undefined;
|
|
2857
|
+
*/
|
|
4691
2858
|
higher(key) {
|
|
4692
2859
|
const cmp = __privateGet(this, _comparator);
|
|
4693
2860
|
let current = this._head;
|
|
@@ -4700,52 +2867,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4700
2867
|
return node ? [node.key, node.value] : void 0;
|
|
4701
2868
|
}
|
|
4702
2869
|
/**
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
* @example
|
|
4744
|
-
* // Strictly less entry
|
|
4745
|
-
* const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
|
|
4746
|
-
* console.log(sl.lower(25)); // [20, 'b'];
|
|
4747
|
-
* console.log(sl.lower(10)); // undefined;
|
|
4748
|
-
*/
|
|
2870
|
+
* Greatest entry strictly < key, or `undefined`.
|
|
2871
|
+
* @example
|
|
2872
|
+
* // Strictly less entry
|
|
2873
|
+
* const sl = new SkipList<number, string>([
|
|
2874
|
+
* [10, 'a'],
|
|
2875
|
+
* [20, 'b'],
|
|
2876
|
+
* [30, 'c']
|
|
2877
|
+
* ]);
|
|
2878
|
+
* console.log(sl.lower(25)); // [20, 'b'];
|
|
2879
|
+
* console.log(sl.lower(10)); // undefined;
|
|
2880
|
+
*/
|
|
4749
2881
|
lower(key) {
|
|
4750
2882
|
const cmp = __privateGet(this, _comparator);
|
|
4751
2883
|
let current = this._head;
|
|
@@ -4761,55 +2893,23 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4761
2893
|
return result ? [result.key, result.value] : void 0;
|
|
4762
2894
|
}
|
|
4763
2895
|
/**
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
* @example
|
|
4808
|
-
* // Find entries in a range
|
|
4809
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd'], [5, 'e']]);
|
|
4810
|
-
* const result = sl.rangeSearch([2, 4]);
|
|
4811
|
-
* console.log(result); // [[2, 'b'], [3, 'c'], [4, 'd']];
|
|
4812
|
-
*/
|
|
2896
|
+
* Returns entries within the given key range.
|
|
2897
|
+
* @example
|
|
2898
|
+
* // Find entries in a range
|
|
2899
|
+
* const sl = new SkipList<number, string>([
|
|
2900
|
+
* [1, 'a'],
|
|
2901
|
+
* [2, 'b'],
|
|
2902
|
+
* [3, 'c'],
|
|
2903
|
+
* [4, 'd'],
|
|
2904
|
+
* [5, 'e']
|
|
2905
|
+
* ]);
|
|
2906
|
+
* const result = sl.rangeSearch([2, 4]);
|
|
2907
|
+
* console.log(result); // [
|
|
2908
|
+
* // [2, 'b'],
|
|
2909
|
+
* // [3, 'c'],
|
|
2910
|
+
* // [4, 'd']
|
|
2911
|
+
* // ];
|
|
2912
|
+
*/
|
|
4813
2913
|
rangeSearch(range, options = {}) {
|
|
4814
2914
|
const { lowInclusive = true, highInclusive = true } = options;
|
|
4815
2915
|
const [low, high] = range;
|
|
@@ -4836,52 +2936,16 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4836
2936
|
}
|
|
4837
2937
|
// ─── Functional (overrides) ──────────────────────────────────
|
|
4838
2938
|
/**
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
* @example
|
|
4880
|
-
* // Transform entries
|
|
4881
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
|
|
4882
|
-
* const mapped = sl.map((v, k) => [k, v?.toUpperCase()] as [number, string]);
|
|
4883
|
-
* console.log([...mapped.values()]); // ['A', 'B'];
|
|
4884
|
-
*/
|
|
2939
|
+
* Creates a new SkipList with entries transformed by callback.
|
|
2940
|
+
* @example
|
|
2941
|
+
* // Transform entries
|
|
2942
|
+
* const sl = new SkipList<number, string>([
|
|
2943
|
+
* [1, 'a'],
|
|
2944
|
+
* [2, 'b']
|
|
2945
|
+
* ]);
|
|
2946
|
+
* const mapped = sl.map((v, k) => [k, v?.toUpperCase()] as [number, string]);
|
|
2947
|
+
* console.log([...mapped.values()]); // ['A', 'B'];
|
|
2948
|
+
*/
|
|
4885
2949
|
map(callback, options) {
|
|
4886
2950
|
const out = new _SkipList([], options != null ? options : {});
|
|
4887
2951
|
let i = 0;
|
|
@@ -4892,52 +2956,17 @@ var _SkipList = class _SkipList extends IterableEntryBase {
|
|
|
4892
2956
|
return out;
|
|
4893
2957
|
}
|
|
4894
2958
|
/**
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
* @example
|
|
4936
|
-
* // Filter entries
|
|
4937
|
-
* const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
4938
|
-
* const result = sl.filter((v, k) => k > 1);
|
|
4939
|
-
* console.log(result.size); // 2;
|
|
4940
|
-
*/
|
|
2959
|
+
* Creates a new SkipList with entries that pass the predicate.
|
|
2960
|
+
* @example
|
|
2961
|
+
* // Filter entries
|
|
2962
|
+
* const sl = new SkipList<number, string>([
|
|
2963
|
+
* [1, 'a'],
|
|
2964
|
+
* [2, 'b'],
|
|
2965
|
+
* [3, 'c']
|
|
2966
|
+
* ]);
|
|
2967
|
+
* const result = sl.filter((v, k) => k > 1);
|
|
2968
|
+
* console.log(result.size); // 2;
|
|
2969
|
+
*/
|
|
4941
2970
|
filter(callbackfn, thisArg) {
|
|
4942
2971
|
const out = new _SkipList([], {
|
|
4943
2972
|
comparator: __privateGet(this, _isDefaultComparator) ? void 0 : __privateGet(this, _comparator),
|