queue-typed 1.48.8 → 1.49.0
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/dist/data-structures/binary-tree/avl-tree.d.ts +8 -1
- package/dist/data-structures/binary-tree/avl-tree.js +9 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +15 -10
- package/dist/data-structures/binary-tree/binary-tree.js +55 -49
- package/dist/data-structures/binary-tree/bst.d.ts +8 -1
- package/dist/data-structures/binary-tree/bst.js +9 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -16
- package/dist/data-structures/binary-tree/rb-tree.js +16 -29
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +8 -1
- package/dist/data-structures/binary-tree/tree-multimap.js +9 -0
- package/dist/data-structures/queue/deque.d.ts +0 -110
- package/dist/data-structures/queue/deque.js +1 -172
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +11 -1
- package/src/data-structures/binary-tree/binary-tree.ts +65 -56
- package/src/data-structures/binary-tree/bst.ts +11 -1
- package/src/data-structures/binary-tree/rb-tree.ts +18 -32
- package/src/data-structures/binary-tree/tree-multimap.ts +17 -1
- package/src/data-structures/queue/deque.ts +1 -191
|
@@ -849,194 +849,4 @@ export class Deque<E> extends IterableElementBase<E> {
|
|
|
849
849
|
|
|
850
850
|
return { bucketIndex, indexInBucket };
|
|
851
851
|
}
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// O(1) time complexity of obtaining the element
|
|
855
|
-
// O(n) time complexity of adding at the beginning and the end
|
|
856
|
-
// todo tested slowest one
|
|
857
|
-
export class ObjectDeque<E = number> {
|
|
858
|
-
constructor(capacity?: number) {
|
|
859
|
-
if (capacity !== undefined) this._capacity = capacity;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
protected _nodes: { [key: number]: E } = {};
|
|
863
|
-
|
|
864
|
-
get nodes(): { [p: number]: E } {
|
|
865
|
-
return this._nodes;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
protected _capacity = Number.MAX_SAFE_INTEGER;
|
|
869
|
-
|
|
870
|
-
get capacity(): number {
|
|
871
|
-
return this._capacity;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
protected _first = -1;
|
|
875
|
-
|
|
876
|
-
get first(): number {
|
|
877
|
-
return this._first;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
protected _last = -1;
|
|
881
|
-
|
|
882
|
-
get last(): number {
|
|
883
|
-
return this._last;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
protected _size = 0;
|
|
887
|
-
|
|
888
|
-
get size(): number {
|
|
889
|
-
return this._size;
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Time Complexity: O(1)
|
|
894
|
-
* Space Complexity: O(1)
|
|
895
|
-
*/
|
|
896
|
-
|
|
897
|
-
/**
|
|
898
|
-
* Time Complexity: O(1)
|
|
899
|
-
* Space Complexity: O(1)
|
|
900
|
-
*
|
|
901
|
-
* The "addFirst" function adds an element to the beginning of an array-like data structure.
|
|
902
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the beginning of the data
|
|
903
|
-
* structure.
|
|
904
|
-
*/
|
|
905
|
-
addFirst(element: E) {
|
|
906
|
-
if (this.size === 0) {
|
|
907
|
-
const mid = Math.floor(this.capacity / 2);
|
|
908
|
-
this._first = mid;
|
|
909
|
-
this._last = mid;
|
|
910
|
-
} else {
|
|
911
|
-
this._first--;
|
|
912
|
-
}
|
|
913
|
-
this.nodes[this.first] = element;
|
|
914
|
-
this._size++;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
/**
|
|
918
|
-
* Time Complexity: O(1)
|
|
919
|
-
* Space Complexity: O(1)
|
|
920
|
-
*/
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Time Complexity: O(1)
|
|
924
|
-
* Space Complexity: O(1)
|
|
925
|
-
*
|
|
926
|
-
* The addLast function adds an element to the end of an array-like data structure.
|
|
927
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the end of the data structure.
|
|
928
|
-
*/
|
|
929
|
-
addLast(element: E) {
|
|
930
|
-
if (this.size === 0) {
|
|
931
|
-
const mid = Math.floor(this.capacity / 2);
|
|
932
|
-
this._first = mid;
|
|
933
|
-
this._last = mid;
|
|
934
|
-
} else {
|
|
935
|
-
this._last++;
|
|
936
|
-
}
|
|
937
|
-
this.nodes[this.last] = element;
|
|
938
|
-
this._size++;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* Time Complexity: O(1)
|
|
943
|
-
* Space Complexity: O(1)
|
|
944
|
-
*/
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Time Complexity: O(1)
|
|
948
|
-
* Space Complexity: O(1)
|
|
949
|
-
*
|
|
950
|
-
* The function `pollFirst()` removes and returns the first element in a data structure.
|
|
951
|
-
* @returns The element of the first element in the data structure.
|
|
952
|
-
*/
|
|
953
|
-
pollFirst() {
|
|
954
|
-
if (!this.size) return;
|
|
955
|
-
const element = this.getFirst();
|
|
956
|
-
delete this.nodes[this.first];
|
|
957
|
-
this._first++;
|
|
958
|
-
this._size--;
|
|
959
|
-
return element;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
/**
|
|
963
|
-
* Time Complexity: O(1)
|
|
964
|
-
* Space Complexity: O(1)
|
|
965
|
-
*/
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* Time Complexity: O(1)
|
|
969
|
-
* Space Complexity: O(1)
|
|
970
|
-
*
|
|
971
|
-
* The `getFirst` function returns the first element in an array-like data structure if it exists.
|
|
972
|
-
* @returns The element at the first position of the `_nodes` array.
|
|
973
|
-
*/
|
|
974
|
-
getFirst() {
|
|
975
|
-
if (this.size) return this.nodes[this.first];
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
/**
|
|
979
|
-
* Time Complexity: O(1)
|
|
980
|
-
* Space Complexity: O(1)
|
|
981
|
-
*/
|
|
982
|
-
|
|
983
|
-
/**
|
|
984
|
-
* Time Complexity: O(1)
|
|
985
|
-
* Space Complexity: O(1)
|
|
986
|
-
*
|
|
987
|
-
* The `pollLast()` function removes and returns the last element in a data structure.
|
|
988
|
-
* @returns The element that was removed from the data structure.
|
|
989
|
-
*/
|
|
990
|
-
pollLast() {
|
|
991
|
-
if (!this.size) return;
|
|
992
|
-
const element = this.getLast();
|
|
993
|
-
delete this.nodes[this.last];
|
|
994
|
-
this._last--;
|
|
995
|
-
this._size--;
|
|
996
|
-
|
|
997
|
-
return element;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* Time Complexity: O(1)
|
|
1002
|
-
* Space Complexity: O(1)
|
|
1003
|
-
*/
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* Time Complexity: O(1)
|
|
1007
|
-
* Space Complexity: O(1)
|
|
1008
|
-
*
|
|
1009
|
-
* The `getLast()` function returns the last element in an array-like data structure.
|
|
1010
|
-
* @returns The last element in the array "_nodes" is being returned.
|
|
1011
|
-
*/
|
|
1012
|
-
getLast() {
|
|
1013
|
-
if (this.size) return this.nodes[this.last];
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
/**
|
|
1017
|
-
* Time Complexity: O(1)
|
|
1018
|
-
* Space Complexity: O(1)
|
|
1019
|
-
*/
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* Time Complexity: O(1)
|
|
1023
|
-
* Space Complexity: O(1)
|
|
1024
|
-
*
|
|
1025
|
-
* The get function returns the element at the specified index in an array-like data structure.
|
|
1026
|
-
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
1027
|
-
* retrieve from the array.
|
|
1028
|
-
* @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
|
|
1029
|
-
* index, `undefined` is returned.
|
|
1030
|
-
*/
|
|
1031
|
-
get(index: number) {
|
|
1032
|
-
return this.nodes[this.first + index] || undefined;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
/**
|
|
1036
|
-
* The function checks if the size of a data structure is less than or equal to zero.
|
|
1037
|
-
* @returns The method is returning a boolean element indicating whether the size of the object is less than or equal to 0.
|
|
1038
|
-
*/
|
|
1039
|
-
isEmpty() {
|
|
1040
|
-
return this.size <= 0;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
852
|
+
}
|