data-structure-typed 1.47.6 → 1.47.8
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/.github/ISSUE_TEMPLATE/bug_report.md +10 -7
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/release-package.yml +1 -1
- package/CHANGELOG.md +1 -1
- package/CODE_OF_CONDUCT.md +32 -10
- package/COMMANDS.md +3 -1
- package/CONTRIBUTING.md +4 -3
- package/README.md +188 -32
- package/SECURITY.md +1 -1
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +563 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +40 -22
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +45 -36
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +105 -113
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +133 -119
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +53 -44
- package/dist/cjs/data-structures/binary-tree/bst.js +137 -154
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +48 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +70 -33
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +26 -37
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -137
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/cjs/data-structures/hash/hash-map.js +5 -8
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/cjs/data-structures/trie/trie.js +19 -4
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +6 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +40 -22
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +45 -36
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +105 -113
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +133 -128
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +53 -44
- package/dist/mjs/data-structures/binary-tree/bst.js +137 -154
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +48 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +70 -33
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +26 -37
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +59 -138
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -6
- package/dist/mjs/data-structures/hash/hash-map.js +5 -8
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/data-structures/trie/trie.d.ts +3 -0
- package/dist/mjs/data-structures/trie/trie.js +20 -4
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +6 -1
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +1 -2
- package/dist/umd/data-structure-typed.js +583 -627
- package/dist/umd/data-structure-typed.min.js +2 -2
- 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 +59 -39
- package/src/data-structures/binary-tree/binary-tree.ts +192 -180
- package/src/data-structures/binary-tree/bst.ts +157 -154
- package/src/data-structures/binary-tree/rb-tree.ts +78 -37
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +67 -145
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/data-structures/trie/trie.ts +23 -4
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +11 -1
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +1 -2
- package/test/integration/{all-in-one.ts → all-in-one.test.ts} +1 -1
- package/test/integration/index.html +158 -2
- package/test/performance/data-structures/comparison/comparison.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +19 -19
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +50 -51
- package/test/unit/data-structures/binary-tree/bst.test.ts +49 -54
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +118 -66
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
- package/test/unit/unrestricted-interconversion.test.ts +61 -5
- package/tsconfig-cjs.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/skip-linked-list.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,MAAa,YAAY;IAKvB,YAAY,GAAM,EAAE,KAAQ,EAAE,KAAa;QACzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF;AAVD,oCAUC;AAED,MAAa,QAAQ;IACnB;;;;;;OAMG;IACH,YAAY,QAAQ,GAAG,EAAE,EAAE,WAAW,GAAG,GAAG;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAO,
|
|
1
|
+
{"version":3,"file":"skip-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/skip-linked-list.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,MAAa,YAAY;IAKvB,YAAY,GAAM,EAAE,KAAQ,EAAE,KAAa;QACzC,IAAI,CAAC,GAAG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AAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,KAAK,CAAC,GAAM;QACV,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,IAAI,QAAQ,GAAG,SAAS,CAAC;QAEzB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YACxC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE;gBACzD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aAC9B;YACD,IAAI,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE;gBACrB,QAAQ,GAAG,OAAO,CAAC;aACpB;SACF;QAED,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY;QACpB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE;YAChE,KAAK,EAAE,CAAC;SACT;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlRD,4BAkRC"}
|
|
@@ -11,8 +11,8 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
11
11
|
*/
|
|
12
12
|
enqueue(value: E): void;
|
|
13
13
|
/**
|
|
14
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
15
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
14
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
15
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
16
16
|
*/
|
|
17
17
|
dequeue(): E | undefined;
|
|
18
18
|
/**
|
|
@@ -75,7 +75,7 @@ export declare class Queue<E = any> {
|
|
|
75
75
|
*
|
|
76
76
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
77
77
|
* necessary to optimize performance.
|
|
78
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
78
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
79
79
|
*/
|
|
80
80
|
shift(): E | undefined;
|
|
81
81
|
/**
|
|
@@ -86,9 +86,9 @@ export declare class Queue<E = any> {
|
|
|
86
86
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
87
87
|
* Space Complexity: O(1) - no additional space is used.
|
|
88
88
|
*
|
|
89
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
89
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
90
90
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
91
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
91
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
92
92
|
*/
|
|
93
93
|
getFirst(): E | undefined;
|
|
94
94
|
/**
|
|
@@ -99,9 +99,9 @@ export declare class Queue<E = any> {
|
|
|
99
99
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
100
100
|
* Space Complexity: O(1) - no additional space is used.
|
|
101
101
|
*
|
|
102
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
102
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
103
103
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
104
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
104
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
105
105
|
*/
|
|
106
106
|
peek(): E | undefined;
|
|
107
107
|
/**
|
|
@@ -112,9 +112,9 @@ export declare class Queue<E = any> {
|
|
|
112
112
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
113
113
|
* Space Complexity: O(1) - no additional space is used.
|
|
114
114
|
*
|
|
115
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
115
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
116
116
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
117
|
-
* array is empty, it returns `
|
|
117
|
+
* array is empty, it returns `undefined`.
|
|
118
118
|
*/
|
|
119
119
|
getLast(): E | undefined;
|
|
120
120
|
/**
|
|
@@ -125,9 +125,9 @@ export declare class Queue<E = any> {
|
|
|
125
125
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
126
126
|
* Space Complexity: O(1) - no additional space is used.
|
|
127
127
|
*
|
|
128
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
128
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
129
129
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
130
|
-
* array is empty, it returns `
|
|
130
|
+
* array is empty, it returns `undefined`.
|
|
131
131
|
*/
|
|
132
132
|
peekLast(): E | undefined;
|
|
133
133
|
/**
|
|
@@ -150,8 +150,8 @@ export declare class Queue<E = any> {
|
|
|
150
150
|
* Time Complexity: O(n) - same as shift().
|
|
151
151
|
* Space Complexity: O(1) - same as shift().
|
|
152
152
|
*
|
|
153
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
154
|
-
* @returns The method is returning a value of type E or
|
|
153
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
154
|
+
* @returns The method is returning a value of type E or undefined.
|
|
155
155
|
*/
|
|
156
156
|
dequeue(): E | undefined;
|
|
157
157
|
/**
|
|
@@ -16,8 +16,8 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
16
16
|
this.push(value);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
20
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
19
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
20
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
21
21
|
*/
|
|
22
22
|
dequeue() {
|
|
23
23
|
return this.shift();
|
|
@@ -100,7 +100,7 @@ class Queue {
|
|
|
100
100
|
*
|
|
101
101
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
102
102
|
* necessary to optimize performance.
|
|
103
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
103
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
104
104
|
*/
|
|
105
105
|
shift() {
|
|
106
106
|
if (this.size === 0)
|
|
@@ -123,9 +123,9 @@ class Queue {
|
|
|
123
123
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
124
124
|
* Space Complexity: O(1) - no additional space is used.
|
|
125
125
|
*
|
|
126
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
126
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
127
127
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
128
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
128
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
129
129
|
*/
|
|
130
130
|
getFirst() {
|
|
131
131
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
@@ -138,9 +138,9 @@ class Queue {
|
|
|
138
138
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
139
139
|
* Space Complexity: O(1) - no additional space is used.
|
|
140
140
|
*
|
|
141
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
141
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
142
142
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
143
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
143
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
144
144
|
*/
|
|
145
145
|
peek() {
|
|
146
146
|
return this.getFirst();
|
|
@@ -153,9 +153,9 @@ class Queue {
|
|
|
153
153
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
154
154
|
* Space Complexity: O(1) - no additional space is used.
|
|
155
155
|
*
|
|
156
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
156
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
157
157
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
158
|
-
* array is empty, it returns `
|
|
158
|
+
* array is empty, it returns `undefined`.
|
|
159
159
|
*/
|
|
160
160
|
getLast() {
|
|
161
161
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
@@ -168,9 +168,9 @@ class Queue {
|
|
|
168
168
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
169
169
|
* Space Complexity: O(1) - no additional space is used.
|
|
170
170
|
*
|
|
171
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
171
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
172
172
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
173
|
-
* array is empty, it returns `
|
|
173
|
+
* array is empty, it returns `undefined`.
|
|
174
174
|
*/
|
|
175
175
|
peekLast() {
|
|
176
176
|
return this.getLast();
|
|
@@ -197,8 +197,8 @@ class Queue {
|
|
|
197
197
|
* Time Complexity: O(n) - same as shift().
|
|
198
198
|
* Space Complexity: O(1) - same as shift().
|
|
199
199
|
*
|
|
200
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
201
|
-
* @returns The method is returning a value of type E or
|
|
200
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
201
|
+
* @returns The method is returning a value of type E or undefined.
|
|
202
202
|
*/
|
|
203
203
|
dequeue() {
|
|
204
204
|
return this.shift();
|
|
@@ -45,10 +45,10 @@ export declare class Stack<E = any> {
|
|
|
45
45
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
46
46
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
47
47
|
*
|
|
48
|
-
* The `peek` function returns the last element of an array, or
|
|
49
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
48
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
49
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
50
50
|
*/
|
|
51
|
-
peek(): E |
|
|
51
|
+
peek(): E | undefined;
|
|
52
52
|
/**
|
|
53
53
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
54
54
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
@@ -70,11 +70,11 @@ export declare class Stack<E = any> {
|
|
|
70
70
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
71
71
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
72
72
|
*
|
|
73
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
73
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
74
74
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
75
|
-
* array is empty, it returns `
|
|
75
|
+
* array is empty, it returns `undefined`.
|
|
76
76
|
*/
|
|
77
|
-
pop(): E |
|
|
77
|
+
pop(): E | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* Time Complexity: O(n)
|
|
80
80
|
* Space Complexity: O(n)
|
|
@@ -62,12 +62,12 @@ class Stack {
|
|
|
62
62
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
63
63
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
64
64
|
*
|
|
65
|
-
* The `peek` function returns the last element of an array, or
|
|
66
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
65
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
66
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
67
67
|
*/
|
|
68
68
|
peek() {
|
|
69
69
|
if (this.isEmpty())
|
|
70
|
-
return
|
|
70
|
+
return undefined;
|
|
71
71
|
return this.elements[this.elements.length - 1];
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -94,14 +94,14 @@ class Stack {
|
|
|
94
94
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
95
95
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
96
96
|
*
|
|
97
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
97
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
98
98
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
99
|
-
* array is empty, it returns `
|
|
99
|
+
* array is empty, it returns `undefined`.
|
|
100
100
|
*/
|
|
101
101
|
pop() {
|
|
102
102
|
if (this.isEmpty())
|
|
103
|
-
return
|
|
104
|
-
return this.elements.pop() ||
|
|
103
|
+
return undefined;
|
|
104
|
+
return this.elements.pop() || undefined;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Time Complexity: O(n)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,KAAK;IAChB;;;;;OAKG;IACH,YAAY,QAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,QAAQ,EAAE;YACZ,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE;gBACzB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACf;SACF;IACH,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IAEH;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACH,IAAI;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,KAAK;IAChB;;;;;OAKG;IACH,YAAY,QAAsB;QAChC,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,QAAQ,EAAE;YACZ,KAAK,MAAM,EAAE,IAAI,QAAQ,EAAE;gBACzB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACf;SACF;IACH,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IAEH;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ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CAAC;SACT;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACzB,CAAC;CACF;AAjND,sBAiNC"}
|
|
@@ -20,6 +20,8 @@ export declare class TrieNode {
|
|
|
20
20
|
*/
|
|
21
21
|
export declare class Trie {
|
|
22
22
|
constructor(words?: string[], caseSensitive?: boolean);
|
|
23
|
+
protected _size: number;
|
|
24
|
+
get size(): number;
|
|
23
25
|
protected _caseSensitive: boolean;
|
|
24
26
|
get caseSensitive(): boolean;
|
|
25
27
|
protected _root: TrieNode;
|
|
@@ -145,6 +147,7 @@ export declare class Trie {
|
|
|
145
147
|
filter(predicate: (word: string, index: number, trie: this) => boolean): string[];
|
|
146
148
|
map(callback: (word: string, index: number, trie: this) => string): Trie;
|
|
147
149
|
reduce<T>(callback: (accumulator: T, word: string, index: number, trie: this) => T, initialValue: T): T;
|
|
150
|
+
print(): void;
|
|
148
151
|
/**
|
|
149
152
|
* Time Complexity: O(M), where M is the length of the input string.
|
|
150
153
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -27,12 +27,16 @@ class Trie {
|
|
|
27
27
|
constructor(words, caseSensitive = true) {
|
|
28
28
|
this._root = new TrieNode('');
|
|
29
29
|
this._caseSensitive = caseSensitive;
|
|
30
|
+
this._size = 0;
|
|
30
31
|
if (words) {
|
|
31
|
-
for (const
|
|
32
|
-
this.add(
|
|
32
|
+
for (const word of words) {
|
|
33
|
+
this.add(word);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
get size() {
|
|
38
|
+
return this._size;
|
|
39
|
+
}
|
|
36
40
|
get caseSensitive() {
|
|
37
41
|
return this._caseSensitive;
|
|
38
42
|
}
|
|
@@ -54,6 +58,7 @@ class Trie {
|
|
|
54
58
|
add(word) {
|
|
55
59
|
word = this._caseProcess(word);
|
|
56
60
|
let cur = this.root;
|
|
61
|
+
let isNewWord = false;
|
|
57
62
|
for (const c of word) {
|
|
58
63
|
let nodeC = cur.children.get(c);
|
|
59
64
|
if (!nodeC) {
|
|
@@ -62,8 +67,12 @@ class Trie {
|
|
|
62
67
|
}
|
|
63
68
|
cur = nodeC;
|
|
64
69
|
}
|
|
65
|
-
cur.isEnd
|
|
66
|
-
|
|
70
|
+
if (!cur.isEnd) {
|
|
71
|
+
isNewWord = true;
|
|
72
|
+
cur.isEnd = true;
|
|
73
|
+
this._size++;
|
|
74
|
+
}
|
|
75
|
+
return isNewWord;
|
|
67
76
|
}
|
|
68
77
|
/**
|
|
69
78
|
* Time Complexity: O(M), where M is the length of the input word.
|
|
@@ -130,6 +139,9 @@ class Trie {
|
|
|
130
139
|
return false;
|
|
131
140
|
};
|
|
132
141
|
dfs(this.root, 0);
|
|
142
|
+
if (isDeleted) {
|
|
143
|
+
this._size--;
|
|
144
|
+
}
|
|
133
145
|
return isDeleted;
|
|
134
146
|
}
|
|
135
147
|
/**
|
|
@@ -352,6 +364,9 @@ class Trie {
|
|
|
352
364
|
}
|
|
353
365
|
return accumulator;
|
|
354
366
|
}
|
|
367
|
+
print() {
|
|
368
|
+
console.log([...this]);
|
|
369
|
+
}
|
|
355
370
|
/**
|
|
356
371
|
* Time Complexity: O(M), where M is the length of the input string.
|
|
357
372
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;GAGG;AACH,MAAa,QAAQ;IAKnB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,CAAC;CACF;AAVD,4BAUC;AAED;;GAEG;AACH,MAAa,IAAI;IACf,YAAY,KAAgB,EAAE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AG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;YACvB,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;SACT;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK;QACH,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;SACzE;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArYD,oBAqYC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNKey,
|
|
2
|
+
import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNKey, BTNodeExemplar } from '../types';
|
|
3
3
|
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>, TREE extends BinaryTree<V, N, TREE> = BinaryTreeNested<V, N>> {
|
|
4
4
|
createNode(key: BTNKey, value?: N['value']): N;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions>): TREE;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>, count?: number): N | null | undefined;
|
|
7
|
+
addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
9
9
|
}
|
|
@@ -19,4 +19,9 @@ export type BinaryTreePrintOptions = {
|
|
|
19
19
|
isShowNull?: boolean;
|
|
20
20
|
isShowRedBlackNIL?: boolean;
|
|
21
21
|
};
|
|
22
|
-
export type
|
|
22
|
+
export type BTNodeEntry<T> = [BTNKey | null | undefined, T | undefined];
|
|
23
|
+
export type BTNodeKeyOrNode<N> = BTNKey | null | undefined | N;
|
|
24
|
+
export type BTNodeExemplar<T, N> = BTNodeEntry<T> | BTNodeKeyOrNode<N>;
|
|
25
|
+
export type BTNodePureExemplar<T, N> = [BTNKey, T | undefined] | BTNodePureKeyOrNode<N>;
|
|
26
|
+
export type BTNodePureKeyOrNode<N> = BTNKey | N;
|
|
27
|
+
export type BSTNodeKeyOrNode<N> = BTNKey | undefined | N;
|
|
@@ -2,9 +2,9 @@ export type VertexKey = string | number;
|
|
|
2
2
|
export type DijkstraResult<V> = {
|
|
3
3
|
distMap: Map<V, number>;
|
|
4
4
|
distPaths?: Map<V, V[]>;
|
|
5
|
-
preMap: Map<V, V |
|
|
5
|
+
preMap: Map<V, V | undefined>;
|
|
6
6
|
seen: Set<V>;
|
|
7
7
|
paths: V[][];
|
|
8
8
|
minDist: number;
|
|
9
9
|
minPath: V[];
|
|
10
|
-
} |
|
|
10
|
+
} | undefined;
|
|
@@ -4,8 +4,7 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
4
4
|
next: HashMapLinkedNode<K, V>;
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
|
-
export type HashMapOptions<K
|
|
8
|
-
elements: Iterable<[K, V]>;
|
|
7
|
+
export type HashMapOptions<K> = {
|
|
9
8
|
hashFn: (key: K) => string;
|
|
10
9
|
objHashFn: (key: K) => object;
|
|
11
10
|
};
|
|
@@ -6,21 +6,34 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BTNKey } from '../../types';
|
|
10
|
-
import { BTNCallback
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BSTNodeKeyOrNode, BTNKey, BTNodeExemplar } from '../../types';
|
|
10
|
+
import { BTNCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
13
|
height: number;
|
|
14
14
|
constructor(key: BTNKey, value?: V);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
|
|
18
|
+
* 2. Automatic Rebalancing: AVL trees rebalance themselves automatically during insertions and deletions.
|
|
19
|
+
* 3. Rotations for Balancing: Utilizes rotations (single or double) to maintain balance after updates.
|
|
20
|
+
* 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
|
|
21
|
+
* 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
|
|
22
|
+
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
23
|
+
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
24
|
+
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
25
|
+
*/
|
|
16
26
|
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>, TREE extends AVLTree<V, N, TREE> = AVLTree<V, N, AVLTreeNested<V, N>>> extends BST<V, N, TREE> implements IBinaryTree<V, N, TREE> {
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
20
|
-
*
|
|
21
|
-
*
|
|
28
|
+
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
29
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
30
|
+
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
31
|
+
* initialization.
|
|
32
|
+
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
33
|
+
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
34
|
+
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
22
35
|
*/
|
|
23
|
-
constructor(elements?:
|
|
36
|
+
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<AVLTreeOptions>);
|
|
24
37
|
/**
|
|
25
38
|
* The function creates a new AVL tree node with the specified key and value.
|
|
26
39
|
* @param {BTNKey} key - The key parameter is the key value that will be associated with
|
|
@@ -31,20 +44,29 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
31
44
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
32
45
|
*/
|
|
33
46
|
createNode(key: BTNKey, value?: V): N;
|
|
47
|
+
/**
|
|
48
|
+
* The function creates a new AVL tree with the specified options and returns it.
|
|
49
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
|
|
50
|
+
* passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
|
|
51
|
+
* being created.
|
|
52
|
+
* @returns a new AVLTree object.
|
|
53
|
+
*/
|
|
34
54
|
createTree(options?: AVLTreeOptions): TREE;
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
57
|
+
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
58
|
+
*/
|
|
35
59
|
/**
|
|
36
60
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
37
61
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
38
62
|
*
|
|
39
|
-
* The function overrides the add method of a
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
44
|
-
* added to the binary search tree.
|
|
45
|
-
* @returns The method is returning either a node (N) or undefined.
|
|
63
|
+
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
64
|
+
* a new node.
|
|
65
|
+
* @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be either a key, a node, or an
|
|
66
|
+
* entry.
|
|
67
|
+
* @returns The method is returning either the inserted node or `undefined`.
|
|
46
68
|
*/
|
|
47
|
-
add(
|
|
69
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | undefined;
|
|
48
70
|
/**
|
|
49
71
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
50
72
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -66,12 +88,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
66
88
|
*/
|
|
67
89
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
|
|
68
90
|
/**
|
|
69
|
-
*
|
|
70
|
-
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
71
|
-
*/
|
|
72
|
-
init(elements: IterableEntriesOrKeys<V>): void;
|
|
73
|
-
/**
|
|
74
|
-
* The `_swap` function swaps the key, value, and height properties between two nodes in a binary
|
|
91
|
+
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
75
92
|
* tree.
|
|
76
93
|
* @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
77
94
|
* needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
|
|
@@ -80,7 +97,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
80
97
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
81
98
|
* if either `srcNode` or `destNode` is undefined.
|
|
82
99
|
*/
|
|
83
|
-
protected
|
|
100
|
+
protected _swapProperties(srcNode: BSTNodeKeyOrNode<N>, destNode: BSTNodeKeyOrNode<N>): N | undefined;
|
|
84
101
|
/**
|
|
85
102
|
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
86
103
|
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
@@ -170,4 +187,5 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
170
187
|
* @param {N} A - A is a node in a binary tree.
|
|
171
188
|
*/
|
|
172
189
|
protected _balanceRL(A: N): void;
|
|
190
|
+
protected _replaceNode(oldNode: N, newNode: N): N;
|
|
173
191
|
}
|