red-black-tree-typed 1.53.6 → 1.54.1
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 +52 -0
- package/dist/common/index.d.ts +12 -0
- package/dist/common/index.js +28 -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 -331
- package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
- package/dist/data-structures/binary-tree/avl-tree.js +131 -71
- 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 +309 -208
- package/dist/data-structures/binary-tree/binary-tree.js +382 -300
- package/dist/data-structures/binary-tree/bst.d.ts +245 -127
- package/dist/data-structures/binary-tree/bst.js +366 -163
- 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} +181 -108
- 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 +26 -9
- package/dist/data-structures/heap/heap.js +37 -17
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +64 -19
- package/dist/data-structures/linked-list/doubly-linked-list.js +92 -31
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +48 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +74 -27
- 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 +111 -10
- package/dist/data-structures/trie/trie.js +123 -18
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- 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-counter.js +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 +1 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/index.js +2 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
- 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/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/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 +152 -373
- package/src/data-structures/binary-tree/avl-tree.ts +164 -106
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +563 -447
- package/src/data-structures/binary-tree/bst.ts +433 -237
- package/src/data-structures/binary-tree/index.ts +3 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +224 -146
- 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 +72 -49
- package/src/data-structures/linked-list/doubly-linked-list.ts +186 -118
- package/src/data-structures/linked-list/singly-linked-list.ts +81 -28
- 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 +123 -17
- package/src/index.ts +4 -3
- 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 +1 -6
- package/src/types/data-structures/binary-tree/bst.ts +8 -7
- 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/src/types/utils/utils.ts +16 -10
- package/src/utils/utils.ts +4 -2
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -205
- package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
import type { ElementCallback, TrieOptions } from '../../types';
|
|
9
9
|
import { IterableElementBase } from '../base';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
13
|
-
* and a flag indicating whether it's the end of a word.
|
|
14
|
-
*/
|
|
15
11
|
export class TrieNode {
|
|
16
12
|
constructor(key: string) {
|
|
17
13
|
this._key = key;
|
|
@@ -92,13 +88,100 @@ export class TrieNode {
|
|
|
92
88
|
* 9. Spell Check: Checking the spelling of words.
|
|
93
89
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
94
90
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
91
|
+
* @example
|
|
92
|
+
* // Autocomplete: Prefix validation and checking
|
|
93
|
+
* const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
|
|
94
|
+
*
|
|
95
|
+
* // Get all completions for a prefix
|
|
96
|
+
* const gmailCompletions = autocomplete.getWords('gmail');
|
|
97
|
+
* console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
|
|
98
|
+
* @example
|
|
99
|
+
* // File System Path Operations
|
|
100
|
+
* const fileSystem = new Trie<string>([
|
|
101
|
+
* '/home/user/documents/file1.txt',
|
|
102
|
+
* '/home/user/documents/file2.txt',
|
|
103
|
+
* '/home/user/pictures/photo.jpg',
|
|
104
|
+
* '/home/user/pictures/vacation/',
|
|
105
|
+
* '/home/user/downloads'
|
|
106
|
+
* ]);
|
|
107
|
+
*
|
|
108
|
+
* // Find common directory prefix
|
|
109
|
+
* console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
|
|
110
|
+
*
|
|
111
|
+
* // List all files in a directory
|
|
112
|
+
* const documentsFiles = fileSystem.getWords('/home/user/documents/');
|
|
113
|
+
* console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
|
|
114
|
+
* @example
|
|
115
|
+
* // Autocomplete: Basic word suggestions
|
|
116
|
+
* // Create a trie for autocomplete
|
|
117
|
+
* const autocomplete = new Trie<string>([
|
|
118
|
+
* 'function',
|
|
119
|
+
* 'functional',
|
|
120
|
+
* 'functions',
|
|
121
|
+
* 'class',
|
|
122
|
+
* 'classes',
|
|
123
|
+
* 'classical',
|
|
124
|
+
* 'closure',
|
|
125
|
+
* 'const',
|
|
126
|
+
* 'constructor'
|
|
127
|
+
* ]);
|
|
128
|
+
*
|
|
129
|
+
* // Test autocomplete with different prefixes
|
|
130
|
+
* console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
|
|
131
|
+
* console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
|
|
132
|
+
* console.log(autocomplete.getWords('con')); // ['constructor', 'const']
|
|
133
|
+
*
|
|
134
|
+
* // Test with non-matching prefix
|
|
135
|
+
* console.log(autocomplete.getWords('xyz')); // []
|
|
136
|
+
* @example
|
|
137
|
+
* // Dictionary: Case-insensitive word lookup
|
|
138
|
+
* // Create a case-insensitive dictionary
|
|
139
|
+
* const dictionary = new Trie<string>([], { caseSensitive: false });
|
|
140
|
+
*
|
|
141
|
+
* // Add words with mixed casing
|
|
142
|
+
* dictionary.add('Hello');
|
|
143
|
+
* dictionary.add('WORLD');
|
|
144
|
+
* dictionary.add('JavaScript');
|
|
145
|
+
*
|
|
146
|
+
* // Test lookups with different casings
|
|
147
|
+
* console.log(dictionary.has('hello')); // true
|
|
148
|
+
* console.log(dictionary.has('HELLO')); // true
|
|
149
|
+
* console.log(dictionary.has('Hello')); // true
|
|
150
|
+
* console.log(dictionary.has('javascript')); // true
|
|
151
|
+
* console.log(dictionary.has('JAVASCRIPT')); // true
|
|
152
|
+
* @example
|
|
153
|
+
* // IP Address Routing Table
|
|
154
|
+
* // Add IP address prefixes and their corresponding routes
|
|
155
|
+
* const routes = {
|
|
156
|
+
* '192.168.1': 'LAN_SUBNET_1',
|
|
157
|
+
* '192.168.2': 'LAN_SUBNET_2',
|
|
158
|
+
* '10.0.0': 'PRIVATE_NETWORK_1',
|
|
159
|
+
* '10.0.1': 'PRIVATE_NETWORK_2'
|
|
160
|
+
* };
|
|
161
|
+
*
|
|
162
|
+
* const ipRoutingTable = new Trie<string>(Object.keys(routes));
|
|
163
|
+
*
|
|
164
|
+
* // Check IP address prefix matching
|
|
165
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
|
|
166
|
+
* console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
|
|
167
|
+
*
|
|
168
|
+
* // Validate IP address belongs to subnet
|
|
169
|
+
* const ip = '192.168.1.100';
|
|
170
|
+
* const subnet = ip.split('.').slice(0, 3).join('.');
|
|
171
|
+
* console.log(ipRoutingTable.hasPrefix(subnet)); // true
|
|
95
172
|
*/
|
|
96
173
|
export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
97
174
|
/**
|
|
98
|
-
* The constructor
|
|
99
|
-
*
|
|
100
|
-
* @param
|
|
101
|
-
*
|
|
175
|
+
* The constructor initializes a Trie data structure with optional options and words provided as
|
|
176
|
+
* input.
|
|
177
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
|
|
178
|
+
* iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
|
|
179
|
+
* a list of words or elements. If no `words` are provided, an empty iterable is used as the default
|
|
180
|
+
* value.
|
|
181
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
182
|
+
* contain configuration options for the Trie data structure. One of the options it can have is
|
|
183
|
+
* `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
|
|
184
|
+
* not. If `caseSensitive` is set to `
|
|
102
185
|
*/
|
|
103
186
|
constructor(words: Iterable<string> | Iterable<R> = [], options?: TrieOptions<R>) {
|
|
104
187
|
super(options);
|
|
@@ -107,13 +190,7 @@ export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
|
107
190
|
if (caseSensitive !== undefined) this._caseSensitive = caseSensitive;
|
|
108
191
|
}
|
|
109
192
|
if (words) {
|
|
110
|
-
|
|
111
|
-
if (this.toElementFn) {
|
|
112
|
-
this.add(this.toElementFn(word as R));
|
|
113
|
-
} else {
|
|
114
|
-
this.add(word as string);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
193
|
+
this.addMany(words);
|
|
117
194
|
}
|
|
118
195
|
}
|
|
119
196
|
|
|
@@ -175,6 +252,30 @@ export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
|
175
252
|
return isNewWord;
|
|
176
253
|
}
|
|
177
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Time Complexity: O(n * l)
|
|
257
|
+
* Space Complexity: O(1)
|
|
258
|
+
*
|
|
259
|
+
* The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
|
|
260
|
+
* them using a provided function if available, and adds them to a data structure while returning an
|
|
261
|
+
* array of boolean values indicating success.
|
|
262
|
+
* @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
|
|
263
|
+
* an iterable that contains either strings or elements of type `R`.
|
|
264
|
+
* @returns The `addMany` method returns an array of boolean values indicating whether each word in
|
|
265
|
+
* the input iterable was successfully added to the data structure.
|
|
266
|
+
*/
|
|
267
|
+
addMany(words: Iterable<string> | Iterable<R>): boolean[] {
|
|
268
|
+
const ans: boolean[] = [];
|
|
269
|
+
for (const word of words) {
|
|
270
|
+
if (this.toElementFn) {
|
|
271
|
+
ans.push(this.add(this.toElementFn(word as R)));
|
|
272
|
+
} else {
|
|
273
|
+
ans.push(this.add(word as string));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return ans;
|
|
277
|
+
}
|
|
278
|
+
|
|
178
279
|
/**
|
|
179
280
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
180
281
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -261,9 +362,14 @@ export class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
|
|
|
261
362
|
}
|
|
262
363
|
|
|
263
364
|
/**
|
|
264
|
-
* Time Complexity: O(n)
|
|
265
|
-
* Space Complexity: O(1)
|
|
365
|
+
* Time Complexity: O(n)
|
|
366
|
+
* Space Complexity: O(1)
|
|
266
367
|
*
|
|
368
|
+
* The function `getHeight` calculates the height of a trie data structure starting from the root
|
|
369
|
+
* node.
|
|
370
|
+
* @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
|
|
371
|
+
* the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
|
|
372
|
+
* tree and returns the maximum depth found.
|
|
267
373
|
*/
|
|
268
374
|
getHeight(): number {
|
|
269
375
|
const startNode = this.root;
|
package/src/index.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export * from './data-structures/binary-tree/
|
|
8
|
+
export * from './data-structures/binary-tree/red-black-tree';
|
|
9
9
|
export * from './data-structures/binary-tree/bst';
|
|
10
10
|
export * from './data-structures/binary-tree/binary-tree';
|
|
11
|
-
export * from './types/data-structures/binary-tree/
|
|
11
|
+
export * from './types/data-structures/binary-tree/red-black-tree';
|
|
12
12
|
export * from './types/data-structures/binary-tree/bst';
|
|
13
13
|
export * from './types/data-structures/binary-tree/binary-tree';
|
|
14
14
|
export * from './types/common';
|
|
15
|
-
export * from './
|
|
15
|
+
export * from './types/utils';
|
|
16
|
+
export * from './common';
|
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
BinaryTreeDeleteResult,
|
|
4
|
-
BinaryTreeNested,
|
|
5
|
-
BinaryTreeNodeNested,
|
|
6
|
-
BinaryTreeOptions,
|
|
7
|
-
BTNRep,
|
|
8
|
-
NodePredicate
|
|
9
|
-
} from '../types';
|
|
1
|
+
import { BinaryTreeNode } from '../data-structures';
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
|
|
10
3
|
|
|
11
|
-
export interface IBinaryTree<
|
|
12
|
-
K
|
|
13
|
-
V = any,
|
|
14
|
-
R = object,
|
|
15
|
-
NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>,
|
|
16
|
-
TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>
|
|
17
|
-
> {
|
|
18
|
-
createNode(key: K, value?: NODE['value']): NODE;
|
|
4
|
+
export interface IBinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> {
|
|
5
|
+
createNode(key: K, value?: BinaryTreeNode['value']): BinaryTreeNode;
|
|
19
6
|
|
|
20
|
-
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>):
|
|
7
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R, MK, MV, MR>;
|
|
21
8
|
|
|
22
|
-
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V,
|
|
9
|
+
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
|
|
23
10
|
|
|
24
|
-
addMany(nodes: Iterable<BTNRep<K, V,
|
|
11
|
+
addMany(nodes: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>>>, values?: Iterable<V | undefined>): boolean[];
|
|
25
12
|
|
|
26
|
-
delete(
|
|
13
|
+
delete(
|
|
14
|
+
predicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>
|
|
15
|
+
): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
27
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
2
|
|
|
3
|
-
export type EntryCallback<K, V, R> = (
|
|
3
|
+
export type EntryCallback<K, V, R> = (key: K, value: V, index: number, container: IterableEntryBase<K, V>) => R;
|
|
4
4
|
export type ElementCallback<E, R, RT, C> = (element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
|
|
5
5
|
export type ReduceEntryCallback<K, V, R> = (
|
|
6
6
|
accumulator: R,
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
1
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
2
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
export type AVLTreeMultiMapNested<K, V, R, NODE extends AVLTreeMultiMapNode<K, V, NODE>> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMap<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
-
|
|
8
|
-
export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {}
|
|
3
|
+
export type AVLTreeMultiMapOptions<K, V, R> = Omit<AVLTreeOptions<K, V, R>, 'isMapMode'> & {}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
1
|
import { BSTOptions } from './bst';
|
|
3
2
|
|
|
4
|
-
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
|
-
|
|
6
|
-
export type AVLTreeNested<K, V, R, NODE extends AVLTreeNode<K, V, NODE>> = AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, AVLTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
-
|
|
8
3
|
export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
1
|
import { IterationType, OptValue } from '../../common';
|
|
3
|
-
import { DFSOperation } from '../../../
|
|
4
|
-
|
|
5
|
-
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
6
|
-
|
|
7
|
-
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
2
|
+
import { DFSOperation } from '../../../common';
|
|
8
3
|
|
|
9
4
|
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
10
5
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { BST, BSTNode } from '../../../data-structures';
|
|
2
1
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
6
|
-
|
|
7
|
-
export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, BST<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
2
|
+
import { Comparable } from '../../utils';
|
|
3
|
+
import { OptValue } from '../../common';
|
|
8
4
|
|
|
9
5
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
10
|
-
|
|
6
|
+
specifyComparable?: (key: K) => Comparable
|
|
7
|
+
isReverse?: boolean;
|
|
11
8
|
}
|
|
12
9
|
|
|
13
10
|
export type BSTNOptKey<K> = K | undefined;
|
|
14
11
|
|
|
15
12
|
export type OptNode<NODE> = NODE | undefined;
|
|
16
13
|
|
|
14
|
+
export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
|
|
15
|
+
|
|
17
16
|
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|
|
18
17
|
|
|
18
|
+
export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
|
|
19
|
+
|
|
@@ -3,5 +3,7 @@ export * from './bst';
|
|
|
3
3
|
export * from './avl-tree';
|
|
4
4
|
export * from './segment-tree';
|
|
5
5
|
export * from './avl-tree-multi-map';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './red-black-tree';
|
|
7
7
|
export * from './tree-multi-map';
|
|
8
|
+
export * from './tree-counter';
|
|
9
|
+
export * from './avl-tree-counter';
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { RBTreeOptions } from './rb-tree';
|
|
1
|
+
import type { RedBlackTreeOptions } from './red-black-tree';
|
|
3
2
|
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
export type TreeMultiMapNested<K, V, R, NODE extends TreeMultiMapNode<K, V, NODE>> = TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, TreeMultiMap<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
-
|
|
8
|
-
export type TreeMultiMapOptions<K, V, R> = RBTreeOptions<K, V, R> & {}
|
|
3
|
+
export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {}
|
package/src/types/utils/utils.ts
CHANGED
|
@@ -7,17 +7,23 @@ export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T,
|
|
|
7
7
|
|
|
8
8
|
export type Any = string | number | bigint | boolean | symbol | undefined | object;
|
|
9
9
|
|
|
10
|
+
export type Arithmetic = number | bigint;
|
|
11
|
+
|
|
10
12
|
export type ComparablePrimitive = number | bigint | string | boolean;
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export interface BaseComparableObject {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ValueComparableObject extends BaseComparableObject {
|
|
19
|
+
valueOf: () => ComparablePrimitive | ValueComparableObject;
|
|
20
|
+
toString?: () => string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface StringComparableObject extends BaseComparableObject {
|
|
24
|
+
toString: () => string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ComparableObject = ValueComparableObject | StringComparableObject;
|
|
22
28
|
|
|
23
29
|
export type Comparable = ComparablePrimitive | Date | ComparableObject;
|
package/src/utils/utils.ts
CHANGED
|
@@ -226,7 +226,8 @@ export const roundFixed = (num: number, digit: number = 10) => {
|
|
|
226
226
|
*/
|
|
227
227
|
function isPrimitiveComparable(value: unknown): value is ComparablePrimitive {
|
|
228
228
|
const valueType = typeof value;
|
|
229
|
-
if (valueType === 'number') return
|
|
229
|
+
if (valueType === 'number') return true;
|
|
230
|
+
// if (valueType === 'number') return !Number.isNaN(value);
|
|
230
231
|
return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
|
|
231
232
|
}
|
|
232
233
|
|
|
@@ -274,7 +275,8 @@ export function isComparable(value: unknown, isForceObjectComparable = false): v
|
|
|
274
275
|
if (isPrimitiveComparable(value)) return true;
|
|
275
276
|
|
|
276
277
|
if (typeof value !== 'object') return false;
|
|
277
|
-
if (value instanceof Date) return
|
|
278
|
+
if (value instanceof Date) return true;
|
|
279
|
+
// if (value instanceof Date) return !Number.isNaN(value.getTime());
|
|
278
280
|
if (isForceObjectComparable) return true;
|
|
279
281
|
const comparableValue = tryObjectToPrimitive(value);
|
|
280
282
|
if (comparableValue === null || comparableValue === undefined) return false;
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult, BTNRep, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
|
-
import { BST, BSTNode } from './bst';
|
|
3
|
-
import { IBinaryTree } from '../../interfaces';
|
|
4
|
-
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
5
|
-
/**
|
|
6
|
-
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
7
|
-
* color.
|
|
8
|
-
* @param {K} key - The key parameter is of type K and represents the key of the node in the
|
|
9
|
-
* Red-Black Tree.
|
|
10
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
11
|
-
* associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
|
|
12
|
-
* creating a new instance of the Red-Black Tree Node.
|
|
13
|
-
* @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
|
|
14
|
-
* Tree Node. It is an optional parameter with a default value of `'BLACK'`.
|
|
15
|
-
*/
|
|
16
|
-
constructor(key: K, value?: V, color?: RBTNColor);
|
|
17
|
-
protected _color: RBTNColor;
|
|
18
|
-
/**
|
|
19
|
-
* The function returns the color value of a variable.
|
|
20
|
-
* @returns The color value stored in the private variable `_color`.
|
|
21
|
-
*/
|
|
22
|
-
get color(): RBTNColor;
|
|
23
|
-
/**
|
|
24
|
-
* The function sets the color property to the specified value.
|
|
25
|
-
* @param {RBTNColor} value - The value parameter is of type RBTNColor.
|
|
26
|
-
*/
|
|
27
|
-
set color(value: RBTNColor);
|
|
28
|
-
}
|
|
29
|
-
export declare class RedBlackTree<K = any, V = any, R = object, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
30
|
-
/**
|
|
31
|
-
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
32
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
33
|
-
* iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
|
|
34
|
-
* initialize the RBTree with the provided elements.
|
|
35
|
-
* @param [options] - The `options` parameter is an optional object that can be passed to the
|
|
36
|
-
* constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
|
|
37
|
-
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
38
|
-
* depend on the implementation
|
|
39
|
-
*/
|
|
40
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
|
|
41
|
-
protected _root: NODE | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* The function returns the root node of a tree or undefined if there is no root.
|
|
44
|
-
* @returns The root node of the tree structure, or undefined if there is no root node.
|
|
45
|
-
*/
|
|
46
|
-
get root(): NODE | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
49
|
-
* @param {K} key - The key parameter represents the key value of the node being created. It is of
|
|
50
|
-
* type K, which is a generic type that can be replaced with any specific type when using the
|
|
51
|
-
* function.
|
|
52
|
-
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
53
|
-
* associated with the key in the node. It is not required and can be omitted if you only need to
|
|
54
|
-
* create a node with a key.
|
|
55
|
-
* @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
|
|
56
|
-
* in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
|
|
57
|
-
* set to "BLACK" if not specified.
|
|
58
|
-
* @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
|
|
59
|
-
* returned.
|
|
60
|
-
*/
|
|
61
|
-
createNode(key: K, value?: V, color?: RBTNColor): NODE;
|
|
62
|
-
/**
|
|
63
|
-
* The function creates a new Red-Black Tree with the specified options.
|
|
64
|
-
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
65
|
-
* configuration options for creating the Red-Black Tree. It has the following properties:
|
|
66
|
-
* @returns a new instance of a RedBlackTree object.
|
|
67
|
-
*/
|
|
68
|
-
createTree(options?: RBTreeOptions<K, V, R>): TREE;
|
|
69
|
-
/**
|
|
70
|
-
* Time Complexity: O(1)
|
|
71
|
-
* Space Complexity: O(1)
|
|
72
|
-
*
|
|
73
|
-
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
74
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
75
|
-
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
76
|
-
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
77
|
-
* an instance of the `RedBlackTreeNode` class.
|
|
78
|
-
*/
|
|
79
|
-
isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
80
|
-
/**
|
|
81
|
-
* Time Complexity: O(1)
|
|
82
|
-
* Space Complexity: O(1)
|
|
83
|
-
*
|
|
84
|
-
* The "clear" function sets the root node of a data structure to a sentinel value and resets the
|
|
85
|
-
* size counter to zero.
|
|
86
|
-
*/
|
|
87
|
-
clear(): void;
|
|
88
|
-
/**
|
|
89
|
-
* Time Complexity: O(log n)
|
|
90
|
-
* Space Complexity: O(1)
|
|
91
|
-
*
|
|
92
|
-
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
93
|
-
* added.
|
|
94
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
95
|
-
* `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
|
|
96
|
-
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
97
|
-
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
98
|
-
* structure.
|
|
99
|
-
* @returns The method is returning a boolean value. If a new node is successfully added to the tree,
|
|
100
|
-
* the method returns true. If the node already exists and its value is updated, the method also
|
|
101
|
-
* returns true. If the node cannot be added or updated, the method returns false.
|
|
102
|
-
*/
|
|
103
|
-
add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Time Complexity: O(log n)
|
|
106
|
-
* Space Complexity: O(1)
|
|
107
|
-
*
|
|
108
|
-
* The function overrides the delete method in a binary tree data structure to remove a node based on
|
|
109
|
-
* a given predicate and maintain the binary search tree properties.
|
|
110
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
111
|
-
* parameter in the `override delete` method is used to specify the condition or key based on which a
|
|
112
|
-
* node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
|
|
113
|
-
* function that determines which node(s) should be deleted.
|
|
114
|
-
* @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
|
|
115
|
-
* objects. Each object in the array contains information about the deleted node and whether
|
|
116
|
-
* balancing is needed.
|
|
117
|
-
*/
|
|
118
|
-
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
|
|
119
|
-
/**
|
|
120
|
-
* Time Complexity: O(1)
|
|
121
|
-
* Space Complexity: O(1)
|
|
122
|
-
*
|
|
123
|
-
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
124
|
-
* root.
|
|
125
|
-
* @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
|
|
126
|
-
*/
|
|
127
|
-
protected _setRoot(v: NODE | undefined): void;
|
|
128
|
-
/**
|
|
129
|
-
* Time Complexity: O(1)
|
|
130
|
-
* Space Complexity: O(1)
|
|
131
|
-
*
|
|
132
|
-
* The function replaces an old node with a new node while preserving the color of the old node.
|
|
133
|
-
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
134
|
-
* the data structure.
|
|
135
|
-
* @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
|
|
136
|
-
* data structure.
|
|
137
|
-
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
138
|
-
* superclass, with the `oldNode` and `newNode` parameters.
|
|
139
|
-
*/
|
|
140
|
-
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
141
|
-
/**
|
|
142
|
-
* Time Complexity: O(log n)
|
|
143
|
-
* Space Complexity: O(1)
|
|
144
|
-
*
|
|
145
|
-
* The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
|
|
146
|
-
* maintain the red-black tree properties.
|
|
147
|
-
* @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
|
|
148
|
-
* binary search tree.
|
|
149
|
-
* @returns a string value indicating the result of the insertion operation. It can return either
|
|
150
|
-
* 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
|
|
151
|
-
* was created and inserted into the tree.
|
|
152
|
-
*/
|
|
153
|
-
protected _insert(node: NODE): CRUD;
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(1)
|
|
156
|
-
* Space Complexity: O(1)
|
|
157
|
-
*
|
|
158
|
-
* The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
|
|
159
|
-
* @param {NODE} u - The parameter "u" represents a node in a binary tree.
|
|
160
|
-
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`, which means it can
|
|
161
|
-
* either be a `NODE` object or `undefined`.
|
|
162
|
-
*/
|
|
163
|
-
protected _transplant(u: NODE, v: NODE | undefined): void;
|
|
164
|
-
/**
|
|
165
|
-
* Time Complexity: O(log n)
|
|
166
|
-
* Space Complexity: O(1)
|
|
167
|
-
*
|
|
168
|
-
* The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
|
|
169
|
-
* @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
|
|
170
|
-
* structure. It can either be a valid node or `undefined`.
|
|
171
|
-
*/
|
|
172
|
-
protected _insertFixup(z: NODE | undefined): void;
|
|
173
|
-
/**
|
|
174
|
-
* Time Complexity: O(log n)
|
|
175
|
-
* Space Complexity: O(1)
|
|
176
|
-
*
|
|
177
|
-
* The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
|
|
178
|
-
* the colors and performing rotations.
|
|
179
|
-
* @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
|
|
180
|
-
* be either a valid node object or `undefined`.
|
|
181
|
-
* @returns The function does not return any value. It has a return type of `void`, which means it
|
|
182
|
-
* does not return anything.
|
|
183
|
-
*/
|
|
184
|
-
protected _deleteFixup(node: NODE | undefined): void;
|
|
185
|
-
/**
|
|
186
|
-
* Time Complexity: O(1)
|
|
187
|
-
* Space Complexity: O(1)
|
|
188
|
-
*
|
|
189
|
-
* The `_leftRotate` function performs a left rotation on a given node in a binary tree.
|
|
190
|
-
* @param {NODE | undefined} x - The parameter `x` is of type `NODE | undefined`. It represents a
|
|
191
|
-
* node in a binary tree or `undefined` if there is no node.
|
|
192
|
-
* @returns void, which means it does not return any value.
|
|
193
|
-
*/
|
|
194
|
-
protected _leftRotate(x: NODE | undefined): void;
|
|
195
|
-
/**
|
|
196
|
-
* Time Complexity: O(1)
|
|
197
|
-
* Space Complexity: O(1)
|
|
198
|
-
*
|
|
199
|
-
* The `_rightRotate` function performs a right rotation on a given node in a binary tree.
|
|
200
|
-
* @param {NODE | undefined} y - The parameter `y` is of type `NODE | undefined`. It represents a
|
|
201
|
-
* node in a binary tree or `undefined` if there is no node.
|
|
202
|
-
* @returns void, which means it does not return any value.
|
|
203
|
-
*/
|
|
204
|
-
protected _rightRotate(y: NODE | undefined): void;
|
|
205
|
-
}
|