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
@@ -2,10 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Trie = exports.TrieNode = void 0;
4
4
  const base_1 = require("../base");
5
- /**
6
- * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
7
- * and a flag indicating whether it's the end of a word.
8
- */
9
5
  class TrieNode {
10
6
  constructor(key) {
11
7
  this._key = key;
@@ -74,13 +70,100 @@ exports.TrieNode = TrieNode;
74
70
  * 9. Spell Check: Checking the spelling of words.
75
71
  * 10. IP Routing: Used in certain types of IP routing algorithms.
76
72
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
73
+ * @example
74
+ * // Autocomplete: Prefix validation and checking
75
+ * const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
76
+ *
77
+ * // Get all completions for a prefix
78
+ * const gmailCompletions = autocomplete.getWords('gmail');
79
+ * console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
80
+ * @example
81
+ * // File System Path Operations
82
+ * const fileSystem = new Trie<string>([
83
+ * '/home/user/documents/file1.txt',
84
+ * '/home/user/documents/file2.txt',
85
+ * '/home/user/pictures/photo.jpg',
86
+ * '/home/user/pictures/vacation/',
87
+ * '/home/user/downloads'
88
+ * ]);
89
+ *
90
+ * // Find common directory prefix
91
+ * console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
92
+ *
93
+ * // List all files in a directory
94
+ * const documentsFiles = fileSystem.getWords('/home/user/documents/');
95
+ * console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
96
+ * @example
97
+ * // Autocomplete: Basic word suggestions
98
+ * // Create a trie for autocomplete
99
+ * const autocomplete = new Trie<string>([
100
+ * 'function',
101
+ * 'functional',
102
+ * 'functions',
103
+ * 'class',
104
+ * 'classes',
105
+ * 'classical',
106
+ * 'closure',
107
+ * 'const',
108
+ * 'constructor'
109
+ * ]);
110
+ *
111
+ * // Test autocomplete with different prefixes
112
+ * console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
113
+ * console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
114
+ * console.log(autocomplete.getWords('con')); // ['constructor', 'const']
115
+ *
116
+ * // Test with non-matching prefix
117
+ * console.log(autocomplete.getWords('xyz')); // []
118
+ * @example
119
+ * // Dictionary: Case-insensitive word lookup
120
+ * // Create a case-insensitive dictionary
121
+ * const dictionary = new Trie<string>([], { caseSensitive: false });
122
+ *
123
+ * // Add words with mixed casing
124
+ * dictionary.add('Hello');
125
+ * dictionary.add('WORLD');
126
+ * dictionary.add('JavaScript');
127
+ *
128
+ * // Test lookups with different casings
129
+ * console.log(dictionary.has('hello')); // true
130
+ * console.log(dictionary.has('HELLO')); // true
131
+ * console.log(dictionary.has('Hello')); // true
132
+ * console.log(dictionary.has('javascript')); // true
133
+ * console.log(dictionary.has('JAVASCRIPT')); // true
134
+ * @example
135
+ * // IP Address Routing Table
136
+ * // Add IP address prefixes and their corresponding routes
137
+ * const routes = {
138
+ * '192.168.1': 'LAN_SUBNET_1',
139
+ * '192.168.2': 'LAN_SUBNET_2',
140
+ * '10.0.0': 'PRIVATE_NETWORK_1',
141
+ * '10.0.1': 'PRIVATE_NETWORK_2'
142
+ * };
143
+ *
144
+ * const ipRoutingTable = new Trie<string>(Object.keys(routes));
145
+ *
146
+ * // Check IP address prefix matching
147
+ * console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
148
+ * console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
149
+ *
150
+ * // Validate IP address belongs to subnet
151
+ * const ip = '192.168.1.100';
152
+ * const subnet = ip.split('.').slice(0, 3).join('.');
153
+ * console.log(ipRoutingTable.hasPrefix(subnet)); // true
77
154
  */
78
155
  class Trie extends base_1.IterableElementBase {
79
156
  /**
80
- * The constructor function for the Trie class.
81
- * @param words: Iterable string Initialize the trie with a set of words
82
- * @param options?: TrieOptions Allow the user to pass in options for the trie
83
- * @return This
157
+ * The constructor initializes a Trie data structure with optional options and words provided as
158
+ * input.
159
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
160
+ * iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
161
+ * a list of words or elements. If no `words` are provided, an empty iterable is used as the default
162
+ * value.
163
+ * @param [options] - The `options` parameter in the constructor is an optional object that can
164
+ * contain configuration options for the Trie data structure. One of the options it can have is
165
+ * `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
166
+ * not. If `caseSensitive` is set to `
84
167
  */
85
168
  constructor(words = [], options) {
86
169
  super(options);
@@ -93,14 +176,7 @@ class Trie extends base_1.IterableElementBase {
93
176
  this._caseSensitive = caseSensitive;
94
177
  }
95
178
  if (words) {
96
- for (const word of words) {
97
- if (this.toElementFn) {
98
- this.add(this.toElementFn(word));
99
- }
100
- else {
101
- this.add(word);
102
- }
103
- }
179
+ this.addMany(words);
104
180
  }
105
181
  }
106
182
  /**
@@ -151,6 +227,30 @@ class Trie extends base_1.IterableElementBase {
151
227
  }
152
228
  return isNewWord;
153
229
  }
230
+ /**
231
+ * Time Complexity: O(n * l)
232
+ * Space Complexity: O(1)
233
+ *
234
+ * The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
235
+ * them using a provided function if available, and adds them to a data structure while returning an
236
+ * array of boolean values indicating success.
237
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
238
+ * an iterable that contains either strings or elements of type `R`.
239
+ * @returns The `addMany` method returns an array of boolean values indicating whether each word in
240
+ * the input iterable was successfully added to the data structure.
241
+ */
242
+ addMany(words) {
243
+ const ans = [];
244
+ for (const word of words) {
245
+ if (this.toElementFn) {
246
+ ans.push(this.add(this.toElementFn(word)));
247
+ }
248
+ else {
249
+ ans.push(this.add(word));
250
+ }
251
+ }
252
+ return ans;
253
+ }
154
254
  /**
155
255
  * Time Complexity: O(l), where l is the length of the input word.
156
256
  * Space Complexity: O(1) - Constant space.
@@ -234,9 +334,14 @@ class Trie extends base_1.IterableElementBase {
234
334
  return isDeleted;
235
335
  }
236
336
  /**
237
- * Time Complexity: O(n), where n is the total number of nodes in the trie.
238
- * Space Complexity: O(1) - Constant space.
337
+ * Time Complexity: O(n)
338
+ * Space Complexity: O(1)
239
339
  *
340
+ * The function `getHeight` calculates the height of a trie data structure starting from the root
341
+ * node.
342
+ * @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
343
+ * the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
344
+ * tree and returns the maximum depth found.
240
345
  */
241
346
  getHeight() {
242
347
  const startNode = this.root;
package/dist/index.d.ts CHANGED
@@ -12,4 +12,5 @@ export * from './types/data-structures/binary-tree/rb-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';
package/dist/index.js CHANGED
@@ -28,4 +28,5 @@ __exportStar(require("./types/data-structures/binary-tree/rb-tree"), exports);
28
28
  __exportStar(require("./types/data-structures/binary-tree/bst"), exports);
29
29
  __exportStar(require("./types/data-structures/binary-tree/binary-tree"), exports);
30
30
  __exportStar(require("./types/common"), exports);
31
- __exportStar(require("./constants"), exports);
31
+ __exportStar(require("./types/utils"), exports);
32
+ __exportStar(require("./common"), exports);
@@ -1,9 +1,9 @@
1
- import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
3
- export interface IBinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
4
- createNode(key: K, value?: NODE['value']): NODE;
5
- createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
6
- add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, NODE>, value?: V, count?: number): boolean;
7
- addMany(nodes: Iterable<BTNRep<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
8
- delete(predicate: R | BTNRep<K, V, NODE> | NodePredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
1
+ import { BinaryTreeNode } from '../data-structures';
2
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
3
+ export interface IBinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> {
4
+ createNode(key: K, value?: BinaryTreeNode['value']): BinaryTreeNode;
5
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): IBinaryTree<K, V, R, MK, MV, MR>;
6
+ add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
7
+ addMany(nodes: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>>>, values?: Iterable<V | undefined>): boolean[];
8
+ delete(predicate: R | BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
9
9
  }
@@ -1,5 +1,5 @@
1
1
  import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
- export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
2
+ export type EntryCallback<K, V, R> = (key: K, value: V, index: number, container: IterableEntryBase<K, V>) => R;
3
3
  export type ElementCallback<E, R, RT, C> = (element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
4
4
  export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
5
5
  export type ReduceElementCallback<E, R, RT, C> = (accumulator: RT, element: E, index: number, container: IterableElementBase<E, R, C>) => RT;
@@ -0,0 +1,2 @@
1
+ import { AVLTreeOptions } from './avl-tree';
2
+ export type AVLTreeCounterOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,2 @@
1
- import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
2
1
  import type { AVLTreeOptions } from './avl-tree';
3
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type AVLTreeMultiMapOptions<K, V, R> = AVLTreeOptions<K, V, R> & {};
2
+ export type AVLTreeMultiMapOptions<K, V, R> = Omit<AVLTreeOptions<K, V, R>, 'isMapMode'> & {};
@@ -1,5 +1,2 @@
1
- import { AVLTree, AVLTreeNode } from '../../../data-structures';
2
1
  import { BSTOptions } from './bst';
3
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
2
  export type AVLTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -1,8 +1,5 @@
1
- import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
1
  import { IterationType, OptValue } from '../../common';
3
- import { DFSOperation } from '../../../constants';
4
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- 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';
6
3
  export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
7
4
  export type BinaryTreeOptions<K, V, R> = {
8
5
  iterationType?: IterationType;
@@ -1,11 +1,12 @@
1
- import { BST, BSTNode } from '../../../data-structures';
2
1
  import type { BinaryTreeOptions } from './binary-tree';
3
- import { Comparator } from '../../common';
4
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- 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';
6
4
  export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
7
- comparator?: Comparator<K>;
5
+ specifyComparable?: (key: K) => Comparable;
6
+ isReverse?: boolean;
8
7
  };
9
8
  export type BSTNOptKey<K> = K | undefined;
10
9
  export type OptNode<NODE> = NODE | undefined;
10
+ export type BSTNEntry<K, V> = [BSTNOptKey<K>, OptValue<V>];
11
11
  export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
12
+ export type BSTNRep<K, V, NODE> = BSTNEntry<K, V> | BSTNOptKeyOrNode<K, NODE>;
@@ -5,3 +5,5 @@ export * from './segment-tree';
5
5
  export * from './avl-tree-multi-map';
6
6
  export * from './rb-tree';
7
7
  export * from './tree-multi-map';
8
+ export * from './tree-counter';
9
+ export * from './avl-tree-counter';
@@ -21,3 +21,5 @@ __exportStar(require("./segment-tree"), exports);
21
21
  __exportStar(require("./avl-tree-multi-map"), exports);
22
22
  __exportStar(require("./rb-tree"), exports);
23
23
  __exportStar(require("./tree-multi-map"), exports);
24
+ __exportStar(require("./tree-counter"), exports);
25
+ __exportStar(require("./avl-tree-counter"), exports);
@@ -1,6 +1,3 @@
1
- import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
2
- import type { BSTOptions } from "./bst";
1
+ import type { BSTOptions } from './bst';
3
2
  export type RBTNColor = 'RED' | 'BLACK';
4
- export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type RedBlackTreeNested<K, V, R, NODE extends RedBlackTreeNode<K, V, NODE>> = RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, RedBlackTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
- export type RBTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
3
+ export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ import type { RedBlackTreeOptions } from './rb-tree';
2
+ export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,2 @@
1
- import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
2
- import type { RBTreeOptions } from './rb-tree';
3
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type TreeMultiMapOptions<K, V, R> = RBTreeOptions<K, V, R> & {};
1
+ import type { RedBlackTreeOptions } from './rb-tree';
2
+ export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {};
@@ -6,13 +6,17 @@ export type TrlFn<A extends any[] = any[], R = any> = (...args: A) => R;
6
6
  export type TrlAsyncFn = (...args: any[]) => any;
7
7
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
8
  export type Any = string | number | bigint | boolean | symbol | undefined | object;
9
+ export type Arithmetic = number | bigint;
9
10
  export type ComparablePrimitive = number | bigint | string | boolean;
10
- export type ComparableObject = {
11
- [key in string]: any;
12
- } & ({
13
- valueOf: () => ComparablePrimitive | ComparableObject;
11
+ export interface BaseComparableObject {
12
+ [key: string]: unknown;
13
+ }
14
+ export interface ValueComparableObject extends BaseComparableObject {
15
+ valueOf: () => ComparablePrimitive | ValueComparableObject;
14
16
  toString?: () => string;
15
- } | {
17
+ }
18
+ export interface StringComparableObject extends BaseComparableObject {
16
19
  toString: () => string;
17
- });
20
+ }
21
+ export type ComparableObject = ValueComparableObject | StringComparableObject;
18
22
  export type Comparable = ComparablePrimitive | Date | ComparableObject;
@@ -213,7 +213,8 @@ exports.roundFixed = roundFixed;
213
213
  function isPrimitiveComparable(value) {
214
214
  const valueType = typeof value;
215
215
  if (valueType === 'number')
216
- return !Number.isNaN(value);
216
+ return true;
217
+ // if (valueType === 'number') return !Number.isNaN(value);
217
218
  return valueType === 'bigint' || valueType === 'string' || valueType === 'boolean';
218
219
  }
219
220
  /**
@@ -265,7 +266,8 @@ function isComparable(value, isForceObjectComparable = false) {
265
266
  if (typeof value !== 'object')
266
267
  return false;
267
268
  if (value instanceof Date)
268
- return !Number.isNaN(value.getTime());
269
+ return true;
270
+ // if (value instanceof Date) return !Number.isNaN(value.getTime());
269
271
  if (isForceObjectComparable)
270
272
  return true;
271
273
  const comparableValue = tryObjectToPrimitive(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "red-black-tree-typed",
3
- "version": "1.53.6",
3
+ "version": "1.54.1",
4
4
  "description": "RedBlackTree. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -142,6 +142,6 @@
142
142
  "typescript": "^4.9.5"
143
143
  },
144
144
  "dependencies": {
145
- "data-structure-typed": "^1.53.6"
145
+ "data-structure-typed": "^1.54.1"
146
146
  }
147
147
  }
@@ -0,0 +1,25 @@
1
+ import { isComparable } from '../utils';
2
+
3
+ export enum DFSOperation {
4
+ VISIT = 0,
5
+ PROCESS = 1
6
+ }
7
+
8
+ export class Range<K> {
9
+ constructor(
10
+ public low: K,
11
+ public high: K,
12
+ public includeLow: boolean = true,
13
+ public includeHigh: boolean = true
14
+ ) {
15
+ if (!(isComparable(low) && isComparable(high))) throw new RangeError('low or high is not comparable');
16
+ if (low > high) throw new RangeError('low must be less than or equal to high');
17
+ }
18
+
19
+ // Determine whether a key is within the range
20
+ isInRange(key: K, comparator: (a: K, b: K) => number): boolean {
21
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
22
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
23
+ return lowCheck && highCheck;
24
+ }
25
+ }
@@ -70,7 +70,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
70
70
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
71
71
  let index = 0;
72
72
  for (const item of this) {
73
- if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
73
+ if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
74
74
  return false;
75
75
  }
76
76
  }
@@ -95,7 +95,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
95
95
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
96
96
  let index = 0;
97
97
  for (const item of this) {
98
- if (predicate.call(thisArg, item[1], item[0], index++, this)) {
98
+ if (predicate.call(thisArg, item[0], item[1], index++, this)) {
99
99
  return true;
100
100
  }
101
101
  }
@@ -119,7 +119,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
119
119
  let index = 0;
120
120
  for (const item of this) {
121
121
  const [key, value] = item;
122
- callbackfn.call(thisArg, value, key, index++, this);
122
+ callbackfn.call(thisArg, key, value, index++, this);
123
123
  }
124
124
  }
125
125
 
@@ -144,7 +144,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
144
144
  let index = 0;
145
145
  for (const item of this) {
146
146
  const [key, value] = item;
147
- if (callbackfn.call(thisArg, value, key, index++, this)) return item;
147
+ if (callbackfn.call(thisArg, key, value, index++, this)) return item;
148
148
  }
149
149
  return;
150
150
  }