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
|
@@ -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
|
|
81
|
-
*
|
|
82
|
-
* @param
|
|
83
|
-
*
|
|
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
|
-
|
|
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)
|
|
238
|
-
* Space Complexity: O(1)
|
|
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 './
|
|
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("./
|
|
31
|
+
__exportStar(require("./types/utils"), exports);
|
|
32
|
+
__exportStar(require("./common"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BinaryTreeDeleteResult,
|
|
3
|
-
export interface IBinaryTree<K = any, V = any, R = object,
|
|
4
|
-
createNode(key: K, value?:
|
|
5
|
-
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>):
|
|
6
|
-
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V,
|
|
7
|
-
addMany(nodes: Iterable<BTNRep<K, V,
|
|
8
|
-
delete(predicate: R | BTNRep<K, V,
|
|
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> = (
|
|
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;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
1
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
export type
|
|
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 '../../../
|
|
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 {
|
|
4
|
-
|
|
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
|
-
|
|
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>;
|
|
@@ -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 {
|
|
2
|
-
import type { BSTOptions } from "./bst";
|
|
1
|
+
import type { BSTOptions } from './bst';
|
|
3
2
|
export type RBTNColor = 'RED' | 'BLACK';
|
|
4
|
-
export type
|
|
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> & {};
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
|
11
|
-
[key
|
|
12
|
-
}
|
|
13
|
-
|
|
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;
|
package/dist/utils/utils.js
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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.
|
|
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[
|
|
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[
|
|
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,
|
|
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,
|
|
147
|
+
if (callbackfn.call(thisArg, key, value, index++, this)) return item;
|
|
148
148
|
}
|
|
149
149
|
return;
|
|
150
150
|
}
|