doubly-linked-list-typed 1.53.6 → 1.53.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/README.md +6 -6
- package/dist/common/index.d.ts +12 -0
- package/dist/common/index.js +28 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -12
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +55 -20
- package/dist/data-structures/binary-tree/binary-tree.js +102 -68
- package/dist/data-structures/binary-tree/bst.d.ts +131 -37
- package/dist/data-structures/binary-tree/bst.js +222 -69
- package/dist/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/data-structures/binary-tree/index.js +1 -1
- package/dist/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +53 -0
- package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +56 -3
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/data-structures/binary-tree/tree-multi-map.js +7 -7
- package/dist/data-structures/hash/hash-map.d.ts +30 -0
- package/dist/data-structures/hash/hash-map.js +30 -0
- package/dist/data-structures/heap/heap.d.ts +26 -9
- package/dist/data-structures/heap/heap.js +37 -17
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +54 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +80 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +35 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +55 -11
- package/dist/data-structures/queue/deque.d.ts +37 -8
- package/dist/data-structures/queue/deque.js +73 -29
- package/dist/data-structures/queue/queue.d.ts +41 -1
- package/dist/data-structures/queue/queue.js +51 -9
- package/dist/data-structures/stack/stack.d.ts +27 -10
- package/dist/data-structures/stack/stack.js +39 -20
- package/dist/data-structures/trie/trie.d.ts +111 -6
- package/dist/data-structures/trie/trie.js +123 -14
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +10 -6
- package/dist/utils/utils.js +4 -2
- package/package.json +2 -2
- package/src/common/index.ts +25 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +9 -11
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-tree.ts +110 -66
- package/src/data-structures/binary-tree/bst.ts +232 -72
- package/src/data-structures/binary-tree/index.ts +1 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +56 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -6
- package/src/data-structures/hash/hash-map.ts +30 -0
- package/src/data-structures/heap/heap.ts +72 -49
- package/src/data-structures/linked-list/doubly-linked-list.ts +173 -105
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -11
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +123 -13
- package/src/index.ts +2 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +3 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/utils/utils.ts +16 -10
- package/src/utils/utils.ts +4 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ yarn add doubly-linked-list-typed
|
|
|
36
36
|
|
|
37
37
|
### text editor operation history
|
|
38
38
|
```typescript
|
|
39
|
-
const actions = [
|
|
39
|
+
const actions = [
|
|
40
40
|
{ type: 'insert', content: 'first line of text' },
|
|
41
41
|
{ type: 'insert', content: 'second line of text' },
|
|
42
42
|
{ type: 'delete', content: 'delete the first line' }
|
|
@@ -50,7 +50,7 @@ const actions = [
|
|
|
50
50
|
|
|
51
51
|
### Browser history
|
|
52
52
|
```typescript
|
|
53
|
-
const browserHistory = new DoublyLinkedList<string>();
|
|
53
|
+
const browserHistory = new DoublyLinkedList<string>();
|
|
54
54
|
|
|
55
55
|
browserHistory.push('home page');
|
|
56
56
|
browserHistory.push('search page');
|
|
@@ -63,7 +63,7 @@ const browserHistory = new DoublyLinkedList<string>();
|
|
|
63
63
|
|
|
64
64
|
### Use DoublyLinkedList to implement music player
|
|
65
65
|
```typescript
|
|
66
|
-
// Define the Song interface
|
|
66
|
+
// Define the Song interface
|
|
67
67
|
interface Song {
|
|
68
68
|
title: string;
|
|
69
69
|
artist: string;
|
|
@@ -190,7 +190,7 @@ const browserHistory = new DoublyLinkedList<string>();
|
|
|
190
190
|
|
|
191
191
|
### Use DoublyLinkedList to implement LRU cache
|
|
192
192
|
```typescript
|
|
193
|
-
interface CacheEntry<K, V> {
|
|
193
|
+
interface CacheEntry<K, V> {
|
|
194
194
|
key: K;
|
|
195
195
|
value: V;
|
|
196
196
|
}
|
|
@@ -354,7 +354,7 @@ interface CacheEntry<K, V> {
|
|
|
354
354
|
|
|
355
355
|
### finding lyrics by timestamp in Coldplay's "Fix You"
|
|
356
356
|
```typescript
|
|
357
|
-
// Create a DoublyLinkedList to store song lyrics with timestamps
|
|
357
|
+
// Create a DoublyLinkedList to store song lyrics with timestamps
|
|
358
358
|
const lyricsList = new DoublyLinkedList<{ time: number; text: string }>();
|
|
359
359
|
|
|
360
360
|
// Detailed lyrics with precise timestamps (in milliseconds)
|
|
@@ -396,7 +396,7 @@ interface CacheEntry<K, V> {
|
|
|
396
396
|
|
|
397
397
|
### cpu process schedules
|
|
398
398
|
```typescript
|
|
399
|
-
class Process {
|
|
399
|
+
class Process {
|
|
400
400
|
constructor(
|
|
401
401
|
public id: number,
|
|
402
402
|
public priority: number
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum DFSOperation {
|
|
2
|
+
VISIT = 0,
|
|
3
|
+
PROCESS = 1
|
|
4
|
+
}
|
|
5
|
+
export declare class Range<K> {
|
|
6
|
+
low: K;
|
|
7
|
+
high: K;
|
|
8
|
+
includeLow: boolean;
|
|
9
|
+
includeHigh: boolean;
|
|
10
|
+
constructor(low: K, high: K, includeLow?: boolean, includeHigh?: boolean);
|
|
11
|
+
isInRange(key: K, comparator: (a: K, b: K) => number): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Range = exports.DFSOperation = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
var DFSOperation;
|
|
6
|
+
(function (DFSOperation) {
|
|
7
|
+
DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
|
|
8
|
+
DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
|
|
9
|
+
})(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
|
|
10
|
+
class Range {
|
|
11
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
12
|
+
this.low = low;
|
|
13
|
+
this.high = high;
|
|
14
|
+
this.includeLow = includeLow;
|
|
15
|
+
this.includeHigh = includeHigh;
|
|
16
|
+
if (!((0, utils_1.isComparable)(low) && (0, utils_1.isComparable)(high)))
|
|
17
|
+
throw new RangeError('low or high is not comparable');
|
|
18
|
+
if (low > high)
|
|
19
|
+
throw new RangeError('low must be less than or equal to high');
|
|
20
|
+
}
|
|
21
|
+
// Determine whether a key is within the range
|
|
22
|
+
isInRange(key, comparator) {
|
|
23
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
24
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
25
|
+
return lowCheck && highCheck;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Range = Range;
|
|
@@ -102,7 +102,7 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = object, NODE extends
|
|
|
102
102
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
103
103
|
* @returns either a NODE object or undefined.
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
|
|
106
106
|
/**
|
|
107
107
|
* Time Complexity: O(log n)
|
|
108
108
|
* Space Complexity: O(1)
|
|
@@ -96,7 +96,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
96
96
|
* object.
|
|
97
97
|
*/
|
|
98
98
|
createTree(options) {
|
|
99
|
-
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode,
|
|
99
|
+
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, extractComparable: this._extractComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
@@ -120,7 +120,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
120
120
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
121
121
|
* @returns either a NODE object or undefined.
|
|
122
122
|
*/
|
|
123
|
-
|
|
123
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
124
124
|
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
|
|
125
125
|
return [undefined, undefined];
|
|
126
126
|
if (this.isNode(keyNodeEntryOrRaw))
|
|
@@ -132,17 +132,14 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
132
132
|
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
133
133
|
return [this.createNode(key, finalValue, count), finalValue];
|
|
134
134
|
}
|
|
135
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
136
|
-
return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
137
135
|
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return [this.createNode(key, finalValue, count), finalValue];
|
|
143
|
-
}
|
|
144
|
-
return [undefined, undefined];
|
|
136
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
137
|
+
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
138
|
+
if (this.isKey(key))
|
|
139
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
145
140
|
}
|
|
141
|
+
if (this.isKey(keyNodeEntryOrRaw))
|
|
142
|
+
return [this.createNode(keyNodeEntryOrRaw, value, count), value];
|
|
146
143
|
return [undefined, undefined];
|
|
147
144
|
}
|
|
148
145
|
/**
|
|
@@ -163,7 +160,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
163
160
|
* @returns a boolean value.
|
|
164
161
|
*/
|
|
165
162
|
add(keyNodeEntryOrRaw, value, count = 1) {
|
|
166
|
-
const [newNode, newValue] = this.
|
|
163
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
|
|
167
164
|
if (newNode === undefined)
|
|
168
165
|
return false;
|
|
169
166
|
const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
@@ -85,7 +85,7 @@ class AVLTree extends bst_1.BST {
|
|
|
85
85
|
* @returns a new AVLTree object.
|
|
86
86
|
*/
|
|
87
87
|
createTree(options) {
|
|
88
|
-
return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode,
|
|
88
|
+
return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, extractComparable: this._extractComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
@@ -409,7 +409,7 @@ class AVLTree extends bst_1.BST {
|
|
|
409
409
|
*/
|
|
410
410
|
_balancePath(node) {
|
|
411
411
|
node = this.ensureNode(node);
|
|
412
|
-
const path = this.getPathToRoot(node => node,
|
|
412
|
+
const path = this.getPathToRoot(node, node => node, false); // first O(log n) + O(log n)
|
|
413
413
|
for (let i = 0; i < path.length; i++) {
|
|
414
414
|
// second O(log n)
|
|
415
415
|
const A = path[i];
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, BTNRep, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate, OptNodeOrNull, ToEntryFn } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
|
+
import { Range } from '../../common';
|
|
11
12
|
/**
|
|
12
13
|
* Represents a node in a binary tree.
|
|
13
14
|
* @template V - The type of data stored in the node.
|
|
@@ -91,7 +92,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
91
92
|
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
92
93
|
* value.
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
+
protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNodeOrNull<NODE>, V | undefined];
|
|
95
96
|
/**
|
|
96
97
|
* Time Complexity: O(n)
|
|
97
98
|
* Space Complexity: O(log n)
|
|
@@ -120,6 +121,13 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
120
121
|
* is not a node.
|
|
121
122
|
*/
|
|
122
123
|
isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
124
|
+
/**
|
|
125
|
+
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
126
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V, NODE> | R
|
|
127
|
+
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
128
|
+
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
129
|
+
* indicating that it is of type `R`.
|
|
130
|
+
*/
|
|
123
131
|
isRaw(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is R;
|
|
124
132
|
/**
|
|
125
133
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
@@ -150,6 +158,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
150
158
|
* property of the current object and returning a boolean value based on that comparison.
|
|
151
159
|
*/
|
|
152
160
|
isNIL(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): boolean;
|
|
161
|
+
isRange(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE> | Range<K>): keyNodeEntryRawOrPredicate is Range<K>;
|
|
153
162
|
/**
|
|
154
163
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
155
164
|
* tree.
|
|
@@ -221,6 +230,15 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
221
230
|
* corresponds to the success of adding the corresponding key or value in the input iterable.
|
|
222
231
|
*/
|
|
223
232
|
addMany(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, NODE> | R>, values?: Iterable<V | undefined>): boolean[];
|
|
233
|
+
/**
|
|
234
|
+
* Time Complexity: O(k * n)
|
|
235
|
+
* Space Complexity: O(1)
|
|
236
|
+
*
|
|
237
|
+
* The `merge` function in TypeScript merges another binary tree into the current tree by adding all
|
|
238
|
+
* elements from the other tree.
|
|
239
|
+
* @param anotherTree - `BinaryTree<K, V, R, NODE, TREE>`
|
|
240
|
+
*/
|
|
241
|
+
merge(anotherTree: BinaryTree<K, V, R, NODE, TREE>): void;
|
|
224
242
|
/**
|
|
225
243
|
* Time Complexity: O(k * n)
|
|
226
244
|
* Space Complexity: O(1)
|
|
@@ -250,6 +268,31 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
250
268
|
* need to be balanced (`needBalanced`).
|
|
251
269
|
*/
|
|
252
270
|
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
|
|
271
|
+
/**
|
|
272
|
+
* Time Complexity: O(n)
|
|
273
|
+
* Space Complexity: O(k + log n)
|
|
274
|
+
*
|
|
275
|
+
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
276
|
+
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
277
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
|
|
278
|
+
* `keyNodeEntryRawOrPredicate` parameter in the `search` function can accept three types of values:
|
|
279
|
+
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
280
|
+
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
281
|
+
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
282
|
+
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
283
|
+
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
284
|
+
* extends `NodeCallback<NODE>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
285
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `search` function is
|
|
286
|
+
* used to specify the node from which the search operation should begin. It represents the starting
|
|
287
|
+
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
288
|
+
* provided, the search operation will start from the root
|
|
289
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `search` function
|
|
290
|
+
* specifies the type of iteration to be used when searching for nodes in a binary tree. It can have
|
|
291
|
+
* two possible values:
|
|
292
|
+
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
293
|
+
* on the search algorithm implemented within the function.
|
|
294
|
+
*/
|
|
295
|
+
search<C extends NodeCallback<NODE>>(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>, onlyOne?: boolean, callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
|
|
253
296
|
/**
|
|
254
297
|
* Time Complexity: O(n)
|
|
255
298
|
* Space Complexity: O(k + log n)
|
|
@@ -293,20 +336,6 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
293
336
|
* or `null` if no matching node is found.
|
|
294
337
|
*/
|
|
295
338
|
getNode(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): OptNodeOrNull<NODE>;
|
|
296
|
-
/**
|
|
297
|
-
* Time Complexity: O(n)
|
|
298
|
-
* Space Complexity: O(log n)
|
|
299
|
-
*
|
|
300
|
-
* The function `getNodeByKey` retrieves a node by its key from a binary tree structure.
|
|
301
|
-
* @param {K} key - The `key` parameter is the value used to search for a specific node in a data
|
|
302
|
-
* structure.
|
|
303
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is a type of iteration that
|
|
304
|
-
* specifies how the tree nodes should be traversed when searching for a node with the given key. It
|
|
305
|
-
* is an optional parameter with a default value of `this.iterationType`.
|
|
306
|
-
* @returns The `getNodeByKey` function is returning an optional binary tree node
|
|
307
|
-
* (`OptNodeOrNull<NODE>`).
|
|
308
|
-
*/
|
|
309
|
-
getNodeByKey(key: K, iterationType?: IterationType): OptNodeOrNull<NODE>;
|
|
310
339
|
/**
|
|
311
340
|
* Time Complexity: O(n)
|
|
312
341
|
* Space Complexity: O(log n)
|
|
@@ -478,7 +507,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
478
507
|
* array is either in reverse order or in the original order based on the value of the `isReverse`
|
|
479
508
|
* parameter.
|
|
480
509
|
*/
|
|
481
|
-
getPathToRoot<C extends NodeCallback<OptNodeOrNull<NODE>>>(
|
|
510
|
+
getPathToRoot<C extends NodeCallback<OptNodeOrNull<NODE>>>(beginNode: BTNRep<K, V, NODE> | R, callback?: C, isReverse?: boolean): ReturnType<C>[];
|
|
482
511
|
/**
|
|
483
512
|
* Time Complexity: O(log n)
|
|
484
513
|
* Space Complexity: O(1)
|
|
@@ -825,16 +854,16 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
825
854
|
* Time Complexity: O(1)
|
|
826
855
|
* Space Complexity: O(1)
|
|
827
856
|
*
|
|
828
|
-
* The function `
|
|
857
|
+
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
829
858
|
* entry, raw data, or null/undefined.
|
|
830
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `
|
|
859
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `_extractKey` method you provided is a
|
|
831
860
|
* TypeScript method that takes in a parameter `keyNodeEntryOrRaw` of type `BTNRep<K, V, NODE> | R`,
|
|
832
861
|
* where `BTNRep` is a generic type with keys `K`, `V`, and `NODE`, and `
|
|
833
|
-
* @returns The `
|
|
862
|
+
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeEntryOrRaw`
|
|
834
863
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
835
864
|
* the conditions checked in the method.
|
|
836
865
|
*/
|
|
837
|
-
protected
|
|
866
|
+
protected _extractKey(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): K | null | undefined;
|
|
838
867
|
/**
|
|
839
868
|
* Time Complexity: O(1)
|
|
840
869
|
* Space Complexity: O(1)
|
|
@@ -851,10 +880,16 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
851
880
|
*/
|
|
852
881
|
protected _setValue(key: K | null | undefined, value: V | undefined): false | Map<K, V | undefined>;
|
|
853
882
|
/**
|
|
883
|
+
* Time Complexity: O(1)
|
|
884
|
+
* Space Complexity: O(1)
|
|
885
|
+
*
|
|
854
886
|
* The _clearNodes function sets the root node to undefined and resets the size to 0.
|
|
855
887
|
*/
|
|
856
888
|
protected _clearNodes(): void;
|
|
857
889
|
/**
|
|
890
|
+
* Time Complexity: O(1)
|
|
891
|
+
* Space Complexity: O(1)
|
|
892
|
+
*
|
|
858
893
|
* The _clearValues function clears all values stored in the _store object.
|
|
859
894
|
*/
|
|
860
895
|
protected _clearValues(): void;
|