data-structure-typed 1.45.0 → 1.45.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/.eslintrc.js +6 -6
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +6 -1
- package/README.md +18 -15
- package/benchmark/report.html +18 -15
- package/benchmark/report.json +157 -116
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/cjs/data-structures/hash/hash-map.js +73 -73
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +21 -12
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/mjs/data-structures/hash/hash-map.js +76 -76
- package/dist/mjs/data-structures/heap/heap.js +21 -12
- package/dist/umd/data-structure-typed.js +83 -83
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +7 -7
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
- package/src/data-structures/binary-tree/binary-tree.ts +39 -31
- package/src/data-structures/binary-tree/bst.ts +12 -8
- package/src/data-structures/binary-tree/rb-tree.ts +17 -6
- package/src/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
- package/src/data-structures/graph/abstract-graph.ts +46 -31
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +9 -9
- package/src/data-structures/hash/hash-map.ts +103 -103
- package/src/data-structures/hash/hash-table.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +30 -17
- package/src/data-structures/heap/max-heap.ts +3 -3
- package/src/data-structures/heap/min-heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +3 -3
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +5 -4
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +6 -6
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +18 -4
- package/src/utils/utils.ts +6 -6
- package/test/integration/all-in-one.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +19 -19
- package/test/integration/heap.test.js +1 -1
- package/test/integration/index.html +7 -7
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/performance/data-structures/comparation.test.ts +142 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
- package/test/performance/data-structures/heap/heap.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
- package/test/performance/data-structures/queue/deque.test.ts +6 -6
- package/test/performance/data-structures/queue/queue.test.ts +7 -7
- package/test/performance/data-structures/stack/stack.test.ts +8 -8
- package/test/performance/data-structures/trie/trie.test.ts +4 -4
- package/test/performance/reportor.ts +48 -20
- package/test/performance/types/reportor.ts +1 -1
- package/test/types/utils/json2html.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
- package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
- package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
- package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
- package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/overall.test.ts +1 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +73 -23
- package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
- package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
- package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
- package/test/unit/data-structures/queue/deque.test.ts +3 -3
- package/test/unit/data-structures/queue/queue.test.ts +3 -3
- package/test/unit/data-structures/stack/stack.test.ts +1 -1
- package/test/unit/data-structures/tree/tree.test.ts +1 -1
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
- package/test/utils/array.ts +1 -1
- package/test/utils/big-o.ts +4 -4
- package/test/utils/index.ts +1 -0
- package/test/utils/json2html.ts +7 -3
- package/test/utils/performanc.ts +7 -0
|
@@ -624,8 +624,8 @@ var dataStructureTyped = (() => {
|
|
|
624
624
|
*/
|
|
625
625
|
constructor(node, sentinel, hashMap, iterateDirection = 0 /* DEFAULT */) {
|
|
626
626
|
__publicField(this, "hashMap");
|
|
627
|
-
__publicField(this, "_node");
|
|
628
627
|
__publicField(this, "iterateDirection");
|
|
628
|
+
__publicField(this, "_node");
|
|
629
629
|
__publicField(this, "_sentinel");
|
|
630
630
|
this._node = node;
|
|
631
631
|
this._sentinel = sentinel;
|
|
@@ -713,12 +713,12 @@ var dataStructureTyped = (() => {
|
|
|
713
713
|
* `K` represents the type of the key and `V` represents the
|
|
714
714
|
*/
|
|
715
715
|
constructor(hashMap = []) {
|
|
716
|
+
__publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
|
|
716
717
|
__publicField(this, "_nodes", []);
|
|
717
718
|
__publicField(this, "_orgMap", {});
|
|
718
719
|
__publicField(this, "_head");
|
|
719
720
|
__publicField(this, "_tail");
|
|
720
721
|
__publicField(this, "_sentinel");
|
|
721
|
-
__publicField(this, "OBJ_KEY_INDEX", Symbol("OBJ_KEY_INDEX"));
|
|
722
722
|
__publicField(this, "_size", 0);
|
|
723
723
|
Object.setPrototypeOf(this._orgMap, null);
|
|
724
724
|
this._sentinel = {};
|
|
@@ -730,6 +730,75 @@ var dataStructureTyped = (() => {
|
|
|
730
730
|
get size() {
|
|
731
731
|
return this._size;
|
|
732
732
|
}
|
|
733
|
+
/**
|
|
734
|
+
* Time Complexity: O(1)
|
|
735
|
+
* Space Complexity: O(1)
|
|
736
|
+
*
|
|
737
|
+
* The function returns a new iterator object for a HashMap.
|
|
738
|
+
* @returns A new instance of the HashMapIterator class is being returned.
|
|
739
|
+
*/
|
|
740
|
+
get begin() {
|
|
741
|
+
return new HashMapIterator(this._head, this._sentinel, this);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Time Complexity: O(1)
|
|
745
|
+
* Space Complexity: O(1)
|
|
746
|
+
*
|
|
747
|
+
* The function returns a new HashMapIterator object with the _sentinel value as both the start and
|
|
748
|
+
* end values.
|
|
749
|
+
* @returns A new instance of the HashMapIterator class is being returned.
|
|
750
|
+
*/
|
|
751
|
+
get end() {
|
|
752
|
+
return new HashMapIterator(this._sentinel, this._sentinel, this);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Time Complexity: O(1)
|
|
756
|
+
* Space Complexity: O(1)
|
|
757
|
+
*
|
|
758
|
+
* The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
|
|
759
|
+
* a HashMap in reverse order.
|
|
760
|
+
* @returns A new instance of the HashMapIterator class is being returned.
|
|
761
|
+
*/
|
|
762
|
+
get reverseBegin() {
|
|
763
|
+
return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Time Complexity: O(1)
|
|
767
|
+
* Space Complexity: O(1)
|
|
768
|
+
*
|
|
769
|
+
* The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
|
|
770
|
+
* HashMap in reverse order.
|
|
771
|
+
* @returns A new instance of the HashMapIterator class is being returned.
|
|
772
|
+
*/
|
|
773
|
+
get reverseEnd() {
|
|
774
|
+
return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Time Complexity: O(1)
|
|
778
|
+
* Space Complexity: O(1)
|
|
779
|
+
*
|
|
780
|
+
* The function returns the key-value pair at the front of a data structure.
|
|
781
|
+
* @returns The front element of the data structure, represented as a tuple with a key (K) and a
|
|
782
|
+
* value (V).
|
|
783
|
+
*/
|
|
784
|
+
get front() {
|
|
785
|
+
if (this._size === 0)
|
|
786
|
+
return;
|
|
787
|
+
return [this._head.key, this._head.value];
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Time Complexity: O(1)
|
|
791
|
+
* Space Complexity: O(1)
|
|
792
|
+
*
|
|
793
|
+
* The function returns the key-value pair at the end of a data structure.
|
|
794
|
+
* @returns The method is returning an array containing the key-value pair of the tail element in the
|
|
795
|
+
* data structure.
|
|
796
|
+
*/
|
|
797
|
+
get back() {
|
|
798
|
+
if (this._size === 0)
|
|
799
|
+
return;
|
|
800
|
+
return [this._tail.key, this._tail.value];
|
|
801
|
+
}
|
|
733
802
|
/**
|
|
734
803
|
* Time Complexity: O(1)
|
|
735
804
|
* Space Complexity: O(1)
|
|
@@ -928,75 +997,6 @@ var dataStructureTyped = (() => {
|
|
|
928
997
|
this._size = 0;
|
|
929
998
|
this._head = this._tail = this._sentinel.prev = this._sentinel.next = this._sentinel;
|
|
930
999
|
}
|
|
931
|
-
/**
|
|
932
|
-
* Time Complexity: O(1)
|
|
933
|
-
* Space Complexity: O(1)
|
|
934
|
-
*
|
|
935
|
-
* The function returns a new iterator object for a HashMap.
|
|
936
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
937
|
-
*/
|
|
938
|
-
get begin() {
|
|
939
|
-
return new HashMapIterator(this._head, this._sentinel, this);
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Time Complexity: O(1)
|
|
943
|
-
* Space Complexity: O(1)
|
|
944
|
-
*
|
|
945
|
-
* The function returns a new HashMapIterator object with the _sentinel value as both the start and
|
|
946
|
-
* end values.
|
|
947
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
948
|
-
*/
|
|
949
|
-
get end() {
|
|
950
|
-
return new HashMapIterator(this._sentinel, this._sentinel, this);
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Time Complexity: O(1)
|
|
954
|
-
* Space Complexity: O(1)
|
|
955
|
-
*
|
|
956
|
-
* The reverseBegin function returns a new HashMapIterator object that iterates over the elements of
|
|
957
|
-
* a HashMap in reverse order.
|
|
958
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
959
|
-
*/
|
|
960
|
-
get reverseBegin() {
|
|
961
|
-
return new HashMapIterator(this._tail, this._sentinel, this, 1 /* REVERSE */);
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Time Complexity: O(1)
|
|
965
|
-
* Space Complexity: O(1)
|
|
966
|
-
*
|
|
967
|
-
* The reverseEnd function returns a new HashMapIterator object that iterates over the elements of a
|
|
968
|
-
* HashMap in reverse order.
|
|
969
|
-
* @returns A new instance of the HashMapIterator class is being returned.
|
|
970
|
-
*/
|
|
971
|
-
get reverseEnd() {
|
|
972
|
-
return new HashMapIterator(this._sentinel, this._sentinel, this, 1 /* REVERSE */);
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* Time Complexity: O(1)
|
|
976
|
-
* Space Complexity: O(1)
|
|
977
|
-
*
|
|
978
|
-
* The function returns the key-value pair at the front of a data structure.
|
|
979
|
-
* @returns The front element of the data structure, represented as a tuple with a key (K) and a
|
|
980
|
-
* value (V).
|
|
981
|
-
*/
|
|
982
|
-
get front() {
|
|
983
|
-
if (this._size === 0)
|
|
984
|
-
return;
|
|
985
|
-
return [this._head.key, this._head.value];
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Time Complexity: O(1)
|
|
989
|
-
* Space Complexity: O(1)
|
|
990
|
-
*
|
|
991
|
-
* The function returns the key-value pair at the end of a data structure.
|
|
992
|
-
* @returns The method is returning an array containing the key-value pair of the tail element in the
|
|
993
|
-
* data structure.
|
|
994
|
-
*/
|
|
995
|
-
get back() {
|
|
996
|
-
if (this._size === 0)
|
|
997
|
-
return;
|
|
998
|
-
return [this._tail.key, this._tail.value];
|
|
999
|
-
}
|
|
1000
1000
|
/**
|
|
1001
1001
|
* Time Complexity: O(n), where n is the number of elements in the HashMap.
|
|
1002
1002
|
* Space Complexity: O(1)
|
|
@@ -3773,18 +3773,16 @@ var dataStructureTyped = (() => {
|
|
|
3773
3773
|
* @param index - The index of the newly added element.
|
|
3774
3774
|
*/
|
|
3775
3775
|
bubbleUp(index) {
|
|
3776
|
-
const
|
|
3776
|
+
const item = this.nodes[index];
|
|
3777
3777
|
while (index > 0) {
|
|
3778
|
-
const
|
|
3779
|
-
const
|
|
3780
|
-
if (this.comparator(
|
|
3781
|
-
this.nodes[index] = parent;
|
|
3782
|
-
this.nodes[parentIndex] = element;
|
|
3783
|
-
index = parentIndex;
|
|
3784
|
-
} else {
|
|
3778
|
+
const parent = index - 1 >> 1;
|
|
3779
|
+
const parentItem = this.nodes[parent];
|
|
3780
|
+
if (this.comparator(parentItem, item) <= 0)
|
|
3785
3781
|
break;
|
|
3786
|
-
|
|
3782
|
+
this.nodes[index] = parentItem;
|
|
3783
|
+
index = parent;
|
|
3787
3784
|
}
|
|
3785
|
+
this.nodes[index] = item;
|
|
3788
3786
|
}
|
|
3789
3787
|
/**
|
|
3790
3788
|
* Time Complexity: O(log n)
|
|
@@ -3798,8 +3796,8 @@ var dataStructureTyped = (() => {
|
|
|
3798
3796
|
* @param index - The index from which to start sinking.
|
|
3799
3797
|
*/
|
|
3800
3798
|
sinkDown(index) {
|
|
3801
|
-
const leftChildIndex =
|
|
3802
|
-
const rightChildIndex =
|
|
3799
|
+
const leftChildIndex = index << 1 | 1;
|
|
3800
|
+
const rightChildIndex = leftChildIndex + 1;
|
|
3803
3801
|
const length = this.nodes.length;
|
|
3804
3802
|
let targetIndex = index;
|
|
3805
3803
|
if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
|
|
@@ -7860,7 +7858,9 @@ var dataStructureTyped = (() => {
|
|
|
7860
7858
|
return super.addMany(keysOrNodes, data).map((n) => n != null ? n : void 0);
|
|
7861
7859
|
}
|
|
7862
7860
|
const inserted = [];
|
|
7863
|
-
const combinedArr = keysOrNodes.map(
|
|
7861
|
+
const combinedArr = keysOrNodes.map(
|
|
7862
|
+
(value, index) => [value, data == null ? void 0 : data[index]]
|
|
7863
|
+
);
|
|
7864
7864
|
let sorted = [];
|
|
7865
7865
|
function _isNodeOrUndefinedTuple(arr) {
|
|
7866
7866
|
for (const [keyOrNode] of arr)
|