red-black-tree-typed 1.53.7 → 1.54.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/LICENSE +2 -2
- package/README.md +52 -0
- package/dist/common/index.js +5 -0
- package/dist/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -328
- package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
- package/dist/data-structures/binary-tree/avl-tree.js +130 -70
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +268 -202
- package/dist/data-structures/binary-tree/binary-tree.js +311 -263
- package/dist/data-structures/binary-tree/bst.d.ts +193 -139
- package/dist/data-structures/binary-tree/bst.js +248 -164
- package/dist/data-structures/binary-tree/index.d.ts +3 -1
- package/dist/data-structures/binary-tree/index.js +3 -1
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
- package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +176 -107
- package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/data-structures/binary-tree/tree-counter.js +444 -0
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
- package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/data-structures/graph/directed-graph.js +3 -0
- package/dist/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/data-structures/graph/map-graph.js +3 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/data-structures/graph/undirected-graph.js +3 -0
- package/dist/data-structures/hash/hash-map.d.ts +31 -1
- package/dist/data-structures/hash/hash-map.js +35 -5
- package/dist/data-structures/heap/heap.d.ts +20 -3
- package/dist/data-structures/heap/heap.js +31 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
- package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +47 -11
- package/dist/data-structures/linked-list/singly-linked-list.js +73 -26
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/data-structures/matrix/matrix.js +3 -0
- package/dist/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/data-structures/matrix/navigator.js +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
- 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 +8 -7
- package/dist/data-structures/trie/trie.js +8 -7
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/interfaces/binary-tree.d.ts +8 -8
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -1
- package/dist/types/data-structures/binary-tree/index.js +3 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
- package/package.json +3 -3
- package/src/common/index.ts +7 -1
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +151 -370
- package/src/data-structures/binary-tree/avl-tree.ts +162 -105
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +488 -416
- package/src/data-structures/binary-tree/bst.ts +326 -251
- package/src/data-structures/binary-tree/index.ts +3 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +219 -145
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/hash/hash-map.ts +37 -7
- package/src/data-structures/heap/heap.ts +33 -10
- package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
- package/src/data-structures/linked-list/singly-linked-list.ts +80 -27
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- 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 +8 -7
- package/src/index.ts +4 -4
- package/src/interfaces/binary-tree.ts +10 -21
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/index.ts +3 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -209
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
- /package/dist/types/data-structures/binary-tree/{rb-tree.js → avl-tree-counter.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022
|
|
3
|
+
Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -224,6 +224,58 @@ lastBFSNodes[0].id // 12
|
|
|
224
224
|
|
|
225
225
|
[//]: # (No deletion!!! Start of Example Replace Section)
|
|
226
226
|
|
|
227
|
+
### Find elements in a range
|
|
228
|
+
```typescript
|
|
229
|
+
const bst = new RedBlackTree<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
230
|
+
console.log(bst.search(new Range(5, 10))); // [5, 10, 7]
|
|
231
|
+
console.log(bst.search(new Range(4, 12))); // [5, 10, 12, 7]
|
|
232
|
+
console.log(bst.search(new Range(15, 20))); // [15, 18]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### using Red-Black Tree as a price-based index for stock data
|
|
236
|
+
```typescript
|
|
237
|
+
// Define the structure of individual stock records
|
|
238
|
+
interface StockRecord {
|
|
239
|
+
price: number; // Stock price (key for indexing)
|
|
240
|
+
symbol: string; // Stock ticker symbol
|
|
241
|
+
volume: number; // Trade volume
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Simulate stock market data as it might come from an external feed
|
|
245
|
+
const marketStockData: StockRecord[] = [
|
|
246
|
+
{ price: 142.5, symbol: 'AAPL', volume: 1000000 },
|
|
247
|
+
{ price: 335.2, symbol: 'MSFT', volume: 800000 },
|
|
248
|
+
{ price: 3285.04, symbol: 'AMZN', volume: 500000 },
|
|
249
|
+
{ price: 267.98, symbol: 'META', volume: 750000 },
|
|
250
|
+
{ price: 234.57, symbol: 'GOOGL', volume: 900000 }
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
// Extend the stock record type to include metadata for database usage
|
|
254
|
+
type StockTableRecord = StockRecord & { lastUpdated: Date };
|
|
255
|
+
|
|
256
|
+
// Create a Red-Black Tree to index stock records by price
|
|
257
|
+
// Simulates a database index with stock price as the key for quick lookups
|
|
258
|
+
const priceIndex = new RedBlackTree<number, StockTableRecord, StockRecord>(marketStockData, {
|
|
259
|
+
toEntryFn: stockRecord => [
|
|
260
|
+
stockRecord.price, // Use stock price as the key
|
|
261
|
+
{
|
|
262
|
+
...stockRecord,
|
|
263
|
+
lastUpdated: new Date() // Add a timestamp for when the record was indexed
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Query the stock with the highest price
|
|
269
|
+
const highestPricedStock = priceIndex.getRightMost();
|
|
270
|
+
console.log(priceIndex.get(highestPricedStock)?.symbol); // 'AMZN' // Amazon has the highest price
|
|
271
|
+
|
|
272
|
+
// Query stocks within a specific price range (200 to 400)
|
|
273
|
+
const stocksInRange = priceIndex.rangeSearch(
|
|
274
|
+
[200, 400], // Price range
|
|
275
|
+
node => priceIndex.get(node)?.symbol // Extract stock symbols for the result
|
|
276
|
+
);
|
|
277
|
+
console.log(stocksInRange); // ['GOOGL', 'MSFT', 'META']
|
|
278
|
+
```
|
|
227
279
|
|
|
228
280
|
[//]: # (No deletion!!! End of Example Replace Section)
|
|
229
281
|
|
package/dist/common/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Range = exports.DFSOperation = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
var DFSOperation;
|
|
5
6
|
(function (DFSOperation) {
|
|
6
7
|
DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
|
|
@@ -12,6 +13,10 @@ class Range {
|
|
|
12
13
|
this.high = high;
|
|
13
14
|
this.includeLow = includeLow;
|
|
14
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');
|
|
15
20
|
}
|
|
16
21
|
// Determine whether a key is within the range
|
|
17
22
|
isInRange(key, comparator) {
|
|
@@ -65,7 +65,7 @@ class IterableEntryBase {
|
|
|
65
65
|
every(predicate, thisArg) {
|
|
66
66
|
let index = 0;
|
|
67
67
|
for (const item of this) {
|
|
68
|
-
if (!predicate.call(thisArg, item[
|
|
68
|
+
if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -89,7 +89,7 @@ class IterableEntryBase {
|
|
|
89
89
|
some(predicate, thisArg) {
|
|
90
90
|
let index = 0;
|
|
91
91
|
for (const item of this) {
|
|
92
|
-
if (predicate.call(thisArg, item[
|
|
92
|
+
if (predicate.call(thisArg, item[0], item[1], index++, this)) {
|
|
93
93
|
return true;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
@@ -112,7 +112,7 @@ class IterableEntryBase {
|
|
|
112
112
|
let index = 0;
|
|
113
113
|
for (const item of this) {
|
|
114
114
|
const [key, value] = item;
|
|
115
|
-
callbackfn.call(thisArg,
|
|
115
|
+
callbackfn.call(thisArg, key, value, index++, this);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -136,7 +136,7 @@ class IterableEntryBase {
|
|
|
136
136
|
let index = 0;
|
|
137
137
|
for (const item of this) {
|
|
138
138
|
const [key, value] = item;
|
|
139
|
-
if (callbackfn.call(thisArg,
|
|
139
|
+
if (callbackfn.call(thisArg, key, value, index++, this))
|
|
140
140
|
return item;
|
|
141
141
|
}
|
|
142
142
|
return;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { AVLTreeCounterOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, EntryCallback, IterationType, OptNodeOrNull } from '../../types';
|
|
9
|
+
import { IBinaryTree } from '../../interfaces';
|
|
10
|
+
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
|
+
export declare class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
14
|
+
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
15
|
+
* of the binary tree node.
|
|
16
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
17
|
+
* tree node. If no value is provided, it will be `undefined`.
|
|
18
|
+
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
19
|
+
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
20
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
21
|
+
*/
|
|
22
|
+
constructor(key: K, value?: V, count?: number);
|
|
23
|
+
parent?: AVLTreeCounterNode<K, V>;
|
|
24
|
+
_left?: OptNodeOrNull<AVLTreeCounterNode<K, V>>;
|
|
25
|
+
get left(): OptNodeOrNull<AVLTreeCounterNode<K, V>>;
|
|
26
|
+
set left(v: OptNodeOrNull<AVLTreeCounterNode<K, V>>);
|
|
27
|
+
_right?: OptNodeOrNull<AVLTreeCounterNode<K, V>>;
|
|
28
|
+
get right(): OptNodeOrNull<AVLTreeCounterNode<K, V>>;
|
|
29
|
+
set right(v: OptNodeOrNull<AVLTreeCounterNode<K, V>>);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The only distinction between a AVLTreeCounter and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
33
|
+
*/
|
|
34
|
+
export declare class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends AVLTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
|
|
35
|
+
/**
|
|
36
|
+
* The constructor initializes a new AVLTreeCounter object with optional initial elements.
|
|
37
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
38
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
39
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
40
|
+
* behavior of the AVLTreeCounter. It can include properties such as `compareKeys` and
|
|
41
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
42
|
+
*/
|
|
43
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, AVLTreeCounterNode<K, V>> | R>, options?: AVLTreeCounterOptions<K, V, R>);
|
|
44
|
+
protected _count: number;
|
|
45
|
+
/**
|
|
46
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
47
|
+
* search.
|
|
48
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
49
|
+
*/
|
|
50
|
+
get count(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Time Complexity: O(n)
|
|
53
|
+
* Space Complexity: O(1)
|
|
54
|
+
*
|
|
55
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
56
|
+
* search.
|
|
57
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
58
|
+
*/
|
|
59
|
+
getComputedCount(): number;
|
|
60
|
+
/**
|
|
61
|
+
* The function creates a new AVLTreeCounterNode with the specified key, value, and count.
|
|
62
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
63
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
64
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
65
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
66
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
67
|
+
* key-value pair in the AVLTreeCounterNode. It is an optional parameter, so it can be omitted when
|
|
68
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
69
|
+
* @returns a new instance of the AVLTreeCounterNode class, casted as AVLTreeCounterNode<K, V>.
|
|
70
|
+
*/
|
|
71
|
+
createNode(key: K, value?: V, count?: number): AVLTreeCounterNode<K, V>;
|
|
72
|
+
/**
|
|
73
|
+
* The function creates a new AVLTreeCounter object with the specified options and returns it.
|
|
74
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
75
|
+
* configuration options for creating the AVLTreeCounter. It can have the following properties:
|
|
76
|
+
* @returns a new instance of the AVLTreeCounter class, with the specified options, as a TREE
|
|
77
|
+
* object.
|
|
78
|
+
*/
|
|
79
|
+
createTree(options?: AVLTreeCounterOptions<K, V, R>): AVLTreeCounter<K, V, R, MK, MV, MR>;
|
|
80
|
+
/**
|
|
81
|
+
* The function checks if the input is an instance of AVLTreeCounterNode.
|
|
82
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
|
|
83
|
+
* `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
|
|
84
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
85
|
+
* an instance of the `AVLTreeCounterNode` class.
|
|
86
|
+
*/
|
|
87
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, AVLTreeCounterNode<K, V>>): keyNodeOrEntry is AVLTreeCounterNode<K, V>;
|
|
88
|
+
/**
|
|
89
|
+
* Time Complexity: O(log n)
|
|
90
|
+
* Space Complexity: O(1)
|
|
91
|
+
*
|
|
92
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
93
|
+
* and update the count.
|
|
94
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
95
|
+
* `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
|
|
96
|
+
* can also accept a value of type `BTNRep<K, V, AVLTreeCounterNode<K, V>>`, which represents a key, node,
|
|
97
|
+
* entry, or raw element
|
|
98
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
99
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
100
|
+
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
101
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
102
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
103
|
+
* @returns a boolean value.
|
|
104
|
+
*/
|
|
105
|
+
add(keyNodeOrEntry: BTNRep<K, V, AVLTreeCounterNode<K, V>>, value?: V, count?: number): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Time Complexity: O(log n)
|
|
108
|
+
* Space Complexity: O(1)
|
|
109
|
+
*
|
|
110
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
111
|
+
* nodes and maintaining balance in the tree.
|
|
112
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
|
|
113
|
+
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
114
|
+
* binary tree. It can be a key, node, or entry that determines which
|
|
115
|
+
* node(s) should be deleted.
|
|
116
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
117
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
118
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
119
|
+
* `ignoreCount` is set to
|
|
120
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
121
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
122
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
123
|
+
* deleted node and whether balancing is needed in the tree.
|
|
124
|
+
*/
|
|
125
|
+
delete(keyNodeOrEntry: BTNRep<K, V, AVLTreeCounterNode<K, V>>, ignoreCount?: boolean): BinaryTreeDeleteResult<AVLTreeCounterNode<K, V>>[];
|
|
126
|
+
/**
|
|
127
|
+
* Time Complexity: O(1)
|
|
128
|
+
* Space Complexity: O(1)
|
|
129
|
+
*
|
|
130
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
131
|
+
* zero.
|
|
132
|
+
*/
|
|
133
|
+
clear(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Time Complexity: O(n log n)
|
|
136
|
+
* Space Complexity: O(log n)
|
|
137
|
+
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
138
|
+
* tree using either a recursive or iterative approach.
|
|
139
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
140
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
141
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
142
|
+
* the object.
|
|
143
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
144
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
145
|
+
*/
|
|
146
|
+
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Time complexity: O(n)
|
|
149
|
+
* Space complexity: O(n)
|
|
150
|
+
*
|
|
151
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
152
|
+
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
153
|
+
*/
|
|
154
|
+
clone(): AVLTreeCounter<K, V, R, MK, MV, MR>;
|
|
155
|
+
/**
|
|
156
|
+
* The `map` function in TypeScript overrides the default behavior to create a new AVLTreeCounter
|
|
157
|
+
* with modified entries based on a provided callback.
|
|
158
|
+
* @param callback - The `callback` parameter is a function that will be called for each entry in the
|
|
159
|
+
* AVLTreeCounter. It takes four arguments:
|
|
160
|
+
* @param [options] - The `options` parameter in the `override map` function is of type
|
|
161
|
+
* `AVLTreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional
|
|
162
|
+
* configuration options when creating a new `AVLTreeCounter` instance within the `map` function.
|
|
163
|
+
* These options
|
|
164
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
|
|
165
|
+
* the value of `this` when executing the `callback` function. It allows you to set the context
|
|
166
|
+
* (value of `this`) for the callback function. This can be useful when you want to access properties
|
|
167
|
+
* or
|
|
168
|
+
* @returns The `map` method is returning a new `AVLTreeCounter` instance with the entries
|
|
169
|
+
* transformed by the provided `callback` function. Each entry in the original tree is passed to the
|
|
170
|
+
* `callback` function along with the index and the original tree itself. The transformed entries are
|
|
171
|
+
* then added to the new `AVLTreeCounter` instance, which is returned at the end.
|
|
172
|
+
*/
|
|
173
|
+
map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: AVLTreeCounterOptions<MK, MV, MR>, thisArg?: any): AVLTreeCounter<MK, MV, MR>;
|
|
174
|
+
/**
|
|
175
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
176
|
+
* a node object.
|
|
177
|
+
* @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
|
|
178
|
+
* `keyNodeOrEntry` parameter can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
|
|
179
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
180
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
181
|
+
* value is provided, it will default to `undefined`.
|
|
182
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
183
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
184
|
+
* @returns either a AVLTreeCounterNode<K, V> object or undefined.
|
|
185
|
+
*/
|
|
186
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, AVLTreeCounterNode<K, V>>, value?: V, count?: number): [AVLTreeCounterNode<K, V> | undefined, V | undefined];
|
|
187
|
+
/**
|
|
188
|
+
* Time Complexity: O(1)
|
|
189
|
+
* Space Complexity: O(1)
|
|
190
|
+
*
|
|
191
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
192
|
+
* in a binary search tree.
|
|
193
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
|
|
194
|
+
* that will be swapped with the `destNode`.
|
|
195
|
+
* @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
|
|
196
|
+
* node where the properties will be swapped with the source node.
|
|
197
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
198
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
199
|
+
*/
|
|
200
|
+
protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>): AVLTreeCounterNode<K, V> | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Time Complexity: O(1)
|
|
203
|
+
* Space Complexity: O(1)
|
|
204
|
+
*
|
|
205
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
206
|
+
* @param {AVLTreeCounterNode<K, V>} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
207
|
+
* data structure. It is of type AVLTreeCounterNode<K, V>.
|
|
208
|
+
* @param {AVLTreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `AVLTreeCounterNode<K, V>` class.
|
|
209
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
210
|
+
* superclass, which is of type `AVLTreeCounterNode<K, V>`.
|
|
211
|
+
*/
|
|
212
|
+
protected _replaceNode(oldNode: AVLTreeCounterNode<K, V>, newNode: AVLTreeCounterNode<K, V>): AVLTreeCounterNode<K, V>;
|
|
213
|
+
}
|