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.
Files changed (121) hide show
  1. package/README.md +52 -0
  2. package/dist/common/index.d.ts +12 -0
  3. package/dist/common/index.js +28 -0
  4. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -331
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
  10. package/dist/data-structures/binary-tree/avl-tree.js +131 -71
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +309 -208
  14. package/dist/data-structures/binary-tree/binary-tree.js +382 -300
  15. package/dist/data-structures/binary-tree/bst.d.ts +245 -127
  16. package/dist/data-structures/binary-tree/bst.js +366 -163
  17. package/dist/data-structures/binary-tree/index.d.ts +3 -1
  18. package/dist/data-structures/binary-tree/index.js +3 -1
  19. package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
  20. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +181 -108
  21. package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
  22. package/dist/data-structures/binary-tree/tree-counter.js +444 -0
  23. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
  24. package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
  25. package/dist/data-structures/graph/abstract-graph.js +2 -2
  26. package/dist/data-structures/graph/directed-graph.d.ts +3 -0
  27. package/dist/data-structures/graph/directed-graph.js +3 -0
  28. package/dist/data-structures/graph/map-graph.d.ts +3 -0
  29. package/dist/data-structures/graph/map-graph.js +3 -0
  30. package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
  31. package/dist/data-structures/graph/undirected-graph.js +3 -0
  32. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  33. package/dist/data-structures/hash/hash-map.js +35 -5
  34. package/dist/data-structures/heap/heap.d.ts +26 -9
  35. package/dist/data-structures/heap/heap.js +37 -17
  36. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +64 -19
  37. package/dist/data-structures/linked-list/doubly-linked-list.js +92 -31
  38. package/dist/data-structures/linked-list/singly-linked-list.d.ts +48 -12
  39. package/dist/data-structures/linked-list/singly-linked-list.js +74 -27
  40. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  41. package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
  42. package/dist/data-structures/matrix/matrix.d.ts +3 -0
  43. package/dist/data-structures/matrix/matrix.js +3 -0
  44. package/dist/data-structures/matrix/navigator.d.ts +3 -0
  45. package/dist/data-structures/matrix/navigator.js +3 -0
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
  50. package/dist/data-structures/queue/deque.d.ts +37 -8
  51. package/dist/data-structures/queue/deque.js +73 -29
  52. package/dist/data-structures/queue/queue.d.ts +41 -1
  53. package/dist/data-structures/queue/queue.js +51 -9
  54. package/dist/data-structures/stack/stack.d.ts +27 -10
  55. package/dist/data-structures/stack/stack.js +39 -20
  56. package/dist/data-structures/trie/trie.d.ts +111 -10
  57. package/dist/data-structures/trie/trie.js +123 -18
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +2 -1
  60. package/dist/interfaces/binary-tree.d.ts +8 -8
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  63. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
  64. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  65. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  66. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -4
  67. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  68. package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
  69. package/dist/types/data-structures/binary-tree/index.js +2 -0
  70. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
  71. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  72. package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
  73. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  74. package/dist/types/utils/utils.d.ts +10 -6
  75. package/dist/utils/utils.js +4 -2
  76. package/package.json +2 -2
  77. package/src/common/index.ts +25 -0
  78. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  79. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  80. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +152 -373
  81. package/src/data-structures/binary-tree/avl-tree.ts +164 -106
  82. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  83. package/src/data-structures/binary-tree/binary-tree.ts +563 -447
  84. package/src/data-structures/binary-tree/bst.ts +433 -237
  85. package/src/data-structures/binary-tree/index.ts +3 -1
  86. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +224 -146
  87. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  88. package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
  89. package/src/data-structures/graph/abstract-graph.ts +2 -2
  90. package/src/data-structures/graph/directed-graph.ts +3 -0
  91. package/src/data-structures/graph/map-graph.ts +3 -0
  92. package/src/data-structures/graph/undirected-graph.ts +3 -0
  93. package/src/data-structures/hash/hash-map.ts +37 -7
  94. package/src/data-structures/heap/heap.ts +72 -49
  95. package/src/data-structures/linked-list/doubly-linked-list.ts +186 -118
  96. package/src/data-structures/linked-list/singly-linked-list.ts +81 -28
  97. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  98. package/src/data-structures/matrix/matrix.ts +3 -0
  99. package/src/data-structures/matrix/navigator.ts +3 -0
  100. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  101. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  102. package/src/data-structures/queue/deque.ts +72 -28
  103. package/src/data-structures/queue/queue.ts +50 -7
  104. package/src/data-structures/stack/stack.ts +39 -20
  105. package/src/data-structures/trie/trie.ts +123 -17
  106. package/src/index.ts +4 -3
  107. package/src/interfaces/binary-tree.ts +10 -21
  108. package/src/types/data-structures/base/base.ts +1 -1
  109. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  110. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  111. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  112. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -6
  113. package/src/types/data-structures/binary-tree/bst.ts +8 -7
  114. package/src/types/data-structures/binary-tree/index.ts +3 -1
  115. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  116. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  117. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
  118. package/src/types/utils/utils.ts +16 -10
  119. package/src/utils/utils.ts +4 -2
  120. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -205
  121. 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 function for the Trie class.
99
- * @param words: Iterable string Initialize the trie with a set of words
100
- * @param options?: TrieOptions Allow the user to pass in options for the trie
101
- * @return This
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
- for (const word of words) {
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), where n is the total number of nodes in the trie.
265
- * Space Complexity: O(1) - Constant space.
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/rb-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/rb-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 './constants';
15
+ export * from './types/utils';
16
+ export * from './common';
@@ -1,27 +1,16 @@
1
- import { BinaryTree, BinaryTreeNode } from '../data-structures';
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 = any,
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>>): TREE;
7
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R, MK, MV, MR>;
21
8
 
22
- add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, NODE>, value?: V, count?: number): boolean;
9
+ add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
23
10
 
24
- addMany(nodes: Iterable<BTNRep<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
11
+ addMany(nodes: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>>>, values?: Iterable<V | undefined>): boolean[];
25
12
 
26
- delete(predicate: R | BTNRep<K, V, NODE> | NodePredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
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> = (value: V, key: K, index: number, container: IterableEntryBase<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,
@@ -0,0 +1,3 @@
1
+ import { AVLTreeOptions } from './avl-tree';
2
+
3
+ export type AVLTreeCounterOptions<K, V, R> = AVLTreeOptions<K, V, 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 AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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 '../../../constants';
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 { Comparator } from '../../common';
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
- comparator?: Comparator<K>
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 './rb-tree';
6
+ export * from './red-black-tree';
7
7
  export * from './tree-multi-map';
8
+ export * from './tree-counter';
9
+ export * from './avl-tree-counter';
@@ -0,0 +1,5 @@
1
+ import type { BSTOptions } from './bst';
2
+
3
+ export type RBTNColor = 'RED' | 'BLACK';
4
+
5
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1,3 @@
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
+
3
+ export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -1,8 +1,3 @@
1
- import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
2
- import type { RBTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
3
2
 
4
- export type TreeMultiMapNodeNested<K, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
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'> & {}
@@ -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
- // TODO type safety looks not strict
13
- export type ComparableObject = { [key in string]: any } & (
14
- | {
15
- valueOf: () => ComparablePrimitive | ComparableObject;
16
- toString?: () => string;
17
- }
18
- | {
19
- toString: () => string;
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;
@@ -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 !Number.isNaN(value);
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 !Number.isNaN(value.getTime());
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
- }