max-priority-queue-typed 2.4.4 → 2.5.0
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 +63 -0
- package/dist/cjs/index.cjs +403 -98
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +402 -97
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +403 -99
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +402 -98
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +23 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +439 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +217 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +220 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +218 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +313 -66
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
- package/dist/umd/max-priority-queue-typed.js +400 -95
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +60 -0
- package/src/common/index.ts +2 -0
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +303 -247
- package/src/data-structures/binary-tree/binary-tree.ts +542 -121
- package/src/data-structures/binary-tree/bst.ts +346 -37
- package/src/data-structures/binary-tree/red-black-tree.ts +309 -96
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1292 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +1098 -215
- package/src/data-structures/binary-tree/tree-multi-set.ts +863 -69
- package/src/data-structures/binary-tree/tree-set.ts +1143 -15
- package/src/data-structures/graph/abstract-graph.ts +106 -1
- package/src/data-structures/graph/directed-graph.ts +223 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +299 -59
- package/src/data-structures/hash/hash-map.ts +243 -79
- package/src/data-structures/heap/heap.ts +291 -102
- package/src/data-structures/heap/max-heap.ts +48 -3
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +425 -22
- package/src/data-structures/priority-queue/max-priority-queue.ts +59 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +343 -68
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +215 -44
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/queue/deque.ts +7 -0
- package/src/utils/utils.ts +4 -2
|
@@ -13,6 +13,11 @@ import type { TreeMapEntryCallback, TreeMapOptions, TreeMapRangeOptions, TreeMap
|
|
|
13
13
|
*
|
|
14
14
|
* - Iteration order is ascending by key.
|
|
15
15
|
* - No node exposure: all APIs use keys/values only.
|
|
16
|
+
* @example
|
|
17
|
+
* // Set multiple key-value pairs
|
|
18
|
+
* const tm = new TreeMap<number, string>();
|
|
19
|
+
* tm.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
20
|
+
* console.log(tm.size); // 3;
|
|
16
21
|
*/
|
|
17
22
|
export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | undefined]> {
|
|
18
23
|
#private;
|
|
@@ -50,35 +55,408 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
50
55
|
get size(): number;
|
|
51
56
|
/**
|
|
52
57
|
* Whether the map is empty.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
* @example
|
|
97
|
+
* // Check empty
|
|
98
|
+
* console.log(new TreeMap().isEmpty()); // true;
|
|
53
99
|
*/
|
|
54
100
|
isEmpty(): boolean;
|
|
55
101
|
/**
|
|
56
102
|
* Set or overwrite a value for a key.
|
|
57
103
|
* @remarks Expected time O(log n)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
* @example
|
|
152
|
+
* // Sorted dictionary for a contact book
|
|
153
|
+
* const contacts = new TreeMap<string, string>([
|
|
154
|
+
* ['Bob', '555-0102'],
|
|
155
|
+
* ['Alice', '555-0101'],
|
|
156
|
+
* ['Charlie', '555-0103']
|
|
157
|
+
* ]);
|
|
158
|
+
*
|
|
159
|
+
* // Contacts are automatically sorted by name
|
|
160
|
+
* console.log([...contacts.keys()]); // ['Alice', 'Bob', 'Charlie'];
|
|
161
|
+
* console.log(contacts.get('Bob')); // '555-0102';
|
|
162
|
+
*
|
|
163
|
+
* // Find the first contact alphabetically after 'B'
|
|
164
|
+
* console.log(contacts.ceiling('B')); // ['Bob', '555-0102'];
|
|
165
|
+
*
|
|
166
|
+
* // Find contacts in range
|
|
167
|
+
* console.log(contacts.rangeSearch(['Alice', 'Bob'])); // [
|
|
168
|
+
* // ['Alice', '555-0101'],
|
|
169
|
+
* // ['Bob', '555-0102']
|
|
170
|
+
* // ];
|
|
58
171
|
*/
|
|
59
172
|
set(key: K, value: V | undefined): this;
|
|
60
173
|
/**
|
|
61
174
|
* Get the value under a key.
|
|
62
175
|
* @remarks Expected time O(log n)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
* @example
|
|
226
|
+
* // Configuration registry with typed lookups
|
|
227
|
+
* const config = new TreeMap<string, number>([
|
|
228
|
+
* ['maxRetries', 3],
|
|
229
|
+
* ['timeout', 5000],
|
|
230
|
+
* ['poolSize', 10]
|
|
231
|
+
* ]);
|
|
232
|
+
*
|
|
233
|
+
* console.log(config.get('timeout')); // 5000;
|
|
234
|
+
* console.log(config.get('missing')); // undefined;
|
|
235
|
+
* console.log(config.size); // 3;
|
|
63
236
|
*/
|
|
64
237
|
get(key: K): V | undefined;
|
|
65
238
|
/**
|
|
66
239
|
* Test whether a key exists.
|
|
67
240
|
* @remarks Expected time O(log n)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
* @example
|
|
291
|
+
* // Feature flag checking
|
|
292
|
+
* const flags = new TreeMap<string, boolean>([
|
|
293
|
+
* ['darkMode', true],
|
|
294
|
+
* ['betaFeature', false],
|
|
295
|
+
* ['notifications', true]
|
|
296
|
+
* ]);
|
|
297
|
+
*
|
|
298
|
+
* console.log(flags.has('darkMode')); // true;
|
|
299
|
+
* console.log(flags.has('unknownFlag')); // false;
|
|
68
300
|
*/
|
|
69
301
|
has(key: K): boolean;
|
|
70
302
|
/**
|
|
71
303
|
* Delete a key.
|
|
72
304
|
* @returns `true` if the key existed; otherwise `false`.
|
|
73
305
|
* @remarks Expected time O(log n)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
* @example
|
|
356
|
+
* // Session management with expiry
|
|
357
|
+
* const sessions = new TreeMap<string, number>([
|
|
358
|
+
* ['sess_abc', Date.now()],
|
|
359
|
+
* ['sess_def', Date.now()],
|
|
360
|
+
* ['sess_ghi', Date.now()]
|
|
361
|
+
* ]);
|
|
362
|
+
*
|
|
363
|
+
* console.log(sessions.size); // 3;
|
|
364
|
+
* sessions.delete('sess_def');
|
|
365
|
+
* console.log(sessions.has('sess_def')); // false;
|
|
366
|
+
* console.log(sessions.size); // 2;
|
|
74
367
|
*/
|
|
75
368
|
delete(key: K): boolean;
|
|
76
369
|
/**
|
|
77
370
|
* Remove all entries.
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
* @example
|
|
410
|
+
* // Remove all
|
|
411
|
+
* const tm = new TreeMap<number, string>([[1, 'a']]);
|
|
412
|
+
* tm.clear();
|
|
413
|
+
* console.log(tm.isEmpty()); // true;
|
|
78
414
|
*/
|
|
79
415
|
clear(): void;
|
|
80
416
|
/**
|
|
81
417
|
* Iterate over keys in ascending order.
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
* @example
|
|
457
|
+
* // Get sorted keys
|
|
458
|
+
* const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a']]);
|
|
459
|
+
* console.log([...tm.keys()]); // [1, 3];
|
|
82
460
|
*/
|
|
83
461
|
keys(): IterableIterator<K>;
|
|
84
462
|
private _entryFromKey;
|
|
@@ -86,12 +464,96 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
86
464
|
* Iterate over values in ascending key order.
|
|
87
465
|
*
|
|
88
466
|
* Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
* @example
|
|
506
|
+
* // Get values in key order
|
|
507
|
+
* const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
|
|
508
|
+
* console.log([...tm.values()]); // ['a', 'b'];
|
|
89
509
|
*/
|
|
90
510
|
values(): IterableIterator<V | undefined>;
|
|
91
511
|
/**
|
|
92
512
|
* Iterate over `[key, value]` entries in ascending key order.
|
|
93
513
|
*
|
|
94
514
|
* Note: values may be `undefined`.
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
* @example
|
|
554
|
+
* // Iterate key-value pairs
|
|
555
|
+
* const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);
|
|
556
|
+
* console.log([...tm.entries()]); // [[1, 'a'], [2, 'b'], [3, 'c']];
|
|
95
557
|
*/
|
|
96
558
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
97
559
|
[Symbol.iterator](): IterableIterator<[K, V | undefined]>;
|
|
@@ -99,6 +561,50 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
99
561
|
* Visit each entry in ascending key order.
|
|
100
562
|
*
|
|
101
563
|
* Note: callback value may be `undefined`.
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
* @example
|
|
603
|
+
* // Execute for each entry
|
|
604
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
605
|
+
* const pairs: string[] = [];
|
|
606
|
+
* tm.forEach((v, k) => pairs.push(`${k}:${v}`));
|
|
607
|
+
* console.log(pairs); // ['1:a', '2:b'];
|
|
102
608
|
*/
|
|
103
609
|
forEach(cb: (value: V | undefined, key: K, map: TreeMap<K, V>) => void, thisArg?: any): void;
|
|
104
610
|
/**
|
|
@@ -106,6 +612,49 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
106
612
|
*
|
|
107
613
|
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
108
614
|
* @remarks Time O(n log n) expected, Space O(n)
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
* @example
|
|
654
|
+
* // Transform entries
|
|
655
|
+
* const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
|
|
656
|
+
* const doubled = tm.map((v, k) => [k, (v ?? 0) * 2] as [number, number]);
|
|
657
|
+
* console.log([...doubled.values()]); // [20, 40];
|
|
109
658
|
*/
|
|
110
659
|
map<MK, MV>(callbackfn: TreeMapEntryCallback<K, V, [MK, MV], TreeMap<K, V>>, options?: Omit<TreeMapOptions<MK, MV>, 'toEntryFn'> & {
|
|
111
660
|
comparator?: (a: MK, b: MK) => number;
|
|
@@ -113,69 +662,688 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
113
662
|
/**
|
|
114
663
|
* Create a new TreeMap containing only entries that satisfy the predicate.
|
|
115
664
|
* @remarks Time O(n log n) expected, Space O(n)
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
* @example
|
|
704
|
+
* // Filter entries
|
|
705
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
706
|
+
* const filtered = tm.filter((v, k) => k > 1);
|
|
707
|
+
* console.log([...filtered.keys()]); // [2, 3];
|
|
116
708
|
*/
|
|
117
709
|
filter(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): TreeMap<K, V>;
|
|
118
710
|
/**
|
|
119
711
|
* Reduce entries into a single accumulator.
|
|
120
712
|
* @remarks Time O(n), Space O(1)
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
* @example
|
|
752
|
+
* // Aggregate values
|
|
753
|
+
* const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
|
|
754
|
+
* console.log(tm.reduce((acc, v) => acc + (v ?? 0), 0)); // 30;
|
|
121
755
|
*/
|
|
122
756
|
reduce<A>(callbackfn: TreeMapReduceCallback<K, V, A, TreeMap<K, V>>, initialValue: A): A;
|
|
123
757
|
/**
|
|
124
758
|
* Test whether all entries satisfy a predicate.
|
|
125
759
|
* @remarks Time O(n), Space O(1)
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
* @example
|
|
797
|
+
* // Test all entries
|
|
798
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
799
|
+
* console.log(tm.every((v, k) => k > 0)); // true;
|
|
126
800
|
*/
|
|
127
801
|
every(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): boolean;
|
|
128
802
|
/**
|
|
129
803
|
* Test whether any entry satisfies a predicate.
|
|
130
804
|
* @remarks Time O(n), Space O(1)
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
* @example
|
|
842
|
+
* // Test any entry
|
|
843
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
844
|
+
* console.log(tm.some((v, k) => k === 2)); // true;
|
|
131
845
|
*/
|
|
132
846
|
some(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): boolean;
|
|
133
847
|
/**
|
|
134
848
|
* Find the first entry that satisfies a predicate.
|
|
135
849
|
* @returns The first matching `[key, value]` tuple, or `undefined`.
|
|
136
850
|
* @remarks Time O(n), Space O(1)
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
* @example
|
|
888
|
+
* // Find matching entry
|
|
889
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
890
|
+
* console.log(tm.find(v => v === 'b')?.[0]); // 2;
|
|
137
891
|
*/
|
|
138
892
|
find(callbackfn: TreeMapEntryCallback<K, V, boolean, TreeMap<K, V>>, thisArg?: unknown): [K, V | undefined] | undefined;
|
|
139
893
|
/**
|
|
140
894
|
* Materialize the map into an array of `[key, value]` tuples.
|
|
141
895
|
* @remarks Time O(n), Space O(n)
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
* @example
|
|
935
|
+
* // Convert to array
|
|
936
|
+
* const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
|
|
937
|
+
* console.log(tm.toArray()); // [[1, 'a'], [2, 'b']];
|
|
142
938
|
*/
|
|
143
939
|
toArray(): Array<[K, V | undefined]>;
|
|
144
940
|
/**
|
|
145
941
|
* Print a human-friendly representation.
|
|
146
942
|
* @remarks Time O(n), Space O(n)
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
* @example
|
|
982
|
+
* // Display tree
|
|
983
|
+
* const tm = new TreeMap<number, string>([[1, 'a']]);
|
|
984
|
+
* expect(() => tm.print()).not.toThrow();
|
|
147
985
|
*/
|
|
148
986
|
print(): void;
|
|
149
987
|
/**
|
|
150
988
|
* Smallest entry by key.
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
* @example
|
|
1001
|
+
* // Leaderboard with ranked scores
|
|
1002
|
+
* // Use score as key (descending), player name as value
|
|
1003
|
+
* const leaderboard = new TreeMap<number, string>([], {
|
|
1004
|
+
* comparator: (a, b) => b - a // descending
|
|
1005
|
+
* });
|
|
1006
|
+
*
|
|
1007
|
+
* leaderboard.set(1500, 'Alice');
|
|
1008
|
+
* leaderboard.set(2200, 'Bob');
|
|
1009
|
+
* leaderboard.set(1800, 'Charlie');
|
|
1010
|
+
* leaderboard.set(2500, 'Diana');
|
|
1011
|
+
*
|
|
1012
|
+
* // Top 3 players (first 3 in descending order)
|
|
1013
|
+
* const top3 = [...leaderboard.entries()].slice(0, 3);
|
|
1014
|
+
* console.log(top3); // [
|
|
1015
|
+
* // [2500, 'Diana'],
|
|
1016
|
+
* // [2200, 'Bob'],
|
|
1017
|
+
* // [1800, 'Charlie']
|
|
1018
|
+
* // ];
|
|
1019
|
+
*
|
|
1020
|
+
* // Highest scorer
|
|
1021
|
+
* console.log(leaderboard.first()); // [2500, 'Diana'];
|
|
1022
|
+
*
|
|
1023
|
+
* // Remove lowest scorer
|
|
1024
|
+
* console.log(leaderboard.pollLast()); // [1500, 'Alice'];
|
|
1025
|
+
* console.log(leaderboard.size); // 3;
|
|
151
1026
|
*/
|
|
152
1027
|
first(): [K, V | undefined] | undefined;
|
|
153
1028
|
/**
|
|
154
1029
|
* Largest entry by key.
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
* @example
|
|
1042
|
+
* // Access the maximum entry
|
|
1043
|
+
* const scores = new TreeMap<number, string>([
|
|
1044
|
+
* [85, 'Bob'],
|
|
1045
|
+
* [92, 'Alice'],
|
|
1046
|
+
* [78, 'Charlie']
|
|
1047
|
+
* ]);
|
|
1048
|
+
*
|
|
1049
|
+
* console.log(scores.last()); // [92, 'Alice'];
|
|
1050
|
+
* console.log(scores.first()); // [78, 'Charlie'];
|
|
155
1051
|
*/
|
|
156
1052
|
last(): [K, V | undefined] | undefined;
|
|
157
1053
|
/**
|
|
158
1054
|
* Remove and return the smallest entry.
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
* @example
|
|
1067
|
+
* // Process items from lowest priority
|
|
1068
|
+
* const tasks = new TreeMap<number, string>([
|
|
1069
|
+
* [3, 'Low'],
|
|
1070
|
+
* [1, 'Critical'],
|
|
1071
|
+
* [2, 'Medium']
|
|
1072
|
+
* ]);
|
|
1073
|
+
*
|
|
1074
|
+
* // Process lowest priority first
|
|
1075
|
+
* console.log(tasks.pollFirst()); // [1, 'Critical'];
|
|
1076
|
+
* console.log(tasks.pollFirst()); // [2, 'Medium'];
|
|
1077
|
+
* console.log(tasks.size); // 1;
|
|
159
1078
|
*/
|
|
160
1079
|
pollFirst(): [K, V | undefined] | undefined;
|
|
161
1080
|
/**
|
|
162
1081
|
* Remove and return the largest entry.
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
* @example
|
|
1094
|
+
* // Remove the maximum entry
|
|
1095
|
+
* const bids = new TreeMap<number, string>([
|
|
1096
|
+
* [100, 'Alice'],
|
|
1097
|
+
* [150, 'Bob'],
|
|
1098
|
+
* [120, 'Charlie']
|
|
1099
|
+
* ]);
|
|
1100
|
+
*
|
|
1101
|
+
* // Remove highest bid
|
|
1102
|
+
* console.log(bids.pollLast()); // [150, 'Bob'];
|
|
1103
|
+
* console.log(bids.size); // 2;
|
|
1104
|
+
* console.log(bids.last()); // [120, 'Charlie'];
|
|
163
1105
|
*/
|
|
164
1106
|
pollLast(): [K, V | undefined] | undefined;
|
|
165
1107
|
/**
|
|
166
1108
|
* Smallest entry whose key is >= the given key.
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
* @example
|
|
1148
|
+
* // Event scheduler with time-based lookup
|
|
1149
|
+
* const events = new TreeMap<Date, string>();
|
|
1150
|
+
*
|
|
1151
|
+
* const meeting = new Date('2024-01-15T10:00:00Z');
|
|
1152
|
+
* const lunch = new Date('2024-01-15T12:00:00Z');
|
|
1153
|
+
* const review = new Date('2024-01-15T15:00:00Z');
|
|
1154
|
+
* const standup = new Date('2024-01-15T09:00:00Z');
|
|
1155
|
+
*
|
|
1156
|
+
* events.set(meeting, 'Team Meeting');
|
|
1157
|
+
* events.set(lunch, 'Lunch Break');
|
|
1158
|
+
* events.set(review, 'Code Review');
|
|
1159
|
+
* events.set(standup, 'Daily Standup');
|
|
1160
|
+
*
|
|
1161
|
+
* // Events are sorted chronologically
|
|
1162
|
+
* console.log([...events.values()]); // [
|
|
1163
|
+
* // 'Daily Standup',
|
|
1164
|
+
* // 'Team Meeting',
|
|
1165
|
+
* // 'Lunch Break',
|
|
1166
|
+
* // 'Code Review'
|
|
1167
|
+
* // ];
|
|
1168
|
+
*
|
|
1169
|
+
* // Next event after 11:00
|
|
1170
|
+
* const after11 = new Date('2024-01-15T11:00:00Z');
|
|
1171
|
+
* console.log(events.ceiling(after11)?.[1]); // 'Lunch Break';
|
|
1172
|
+
*
|
|
1173
|
+
* // Events between 9:30 and 13:00
|
|
1174
|
+
* const from = new Date('2024-01-15T09:30:00Z');
|
|
1175
|
+
* const to = new Date('2024-01-15T13:00:00Z');
|
|
1176
|
+
* const window = events.rangeSearch([from, to]);
|
|
1177
|
+
* console.log(window.map(([, v]) => v)); // ['Team Meeting', 'Lunch Break'];
|
|
167
1178
|
*/
|
|
168
1179
|
ceiling(key: K): [K, V | undefined] | undefined;
|
|
169
1180
|
/**
|
|
170
1181
|
* Largest entry whose key is <= the given key.
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
|
|
1220
|
+
* @example
|
|
1221
|
+
* // Find the largest key ≤ target
|
|
1222
|
+
* const versions = new TreeMap<number, string>([
|
|
1223
|
+
* [1, 'v1.0'],
|
|
1224
|
+
* [3, 'v3.0'],
|
|
1225
|
+
* [5, 'v5.0'],
|
|
1226
|
+
* [7, 'v7.0']
|
|
1227
|
+
* ]);
|
|
1228
|
+
*
|
|
1229
|
+
* // Largest version ≤ 4
|
|
1230
|
+
* console.log(versions.floor(4)); // [3, 'v3.0'];
|
|
1231
|
+
* // Largest version ≤ 5 (exact match)
|
|
1232
|
+
* console.log(versions.floor(5)); // [5, 'v5.0'];
|
|
1233
|
+
* // No version ≤ 0
|
|
1234
|
+
* console.log(versions.floor(0)); // undefined;
|
|
171
1235
|
*/
|
|
172
1236
|
floor(key: K): [K, V | undefined] | undefined;
|
|
173
1237
|
/**
|
|
174
1238
|
* Smallest entry whose key is > the given key.
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
* @example
|
|
1278
|
+
* // Find the smallest key strictly > target
|
|
1279
|
+
* const prices = new TreeMap<number, string>([
|
|
1280
|
+
* [10, 'Basic'],
|
|
1281
|
+
* [25, 'Standard'],
|
|
1282
|
+
* [50, 'Premium'],
|
|
1283
|
+
* [100, 'Enterprise']
|
|
1284
|
+
* ]);
|
|
1285
|
+
*
|
|
1286
|
+
* // Next tier above $25
|
|
1287
|
+
* console.log(prices.higher(25)); // [50, 'Premium'];
|
|
1288
|
+
* // Next tier above $99
|
|
1289
|
+
* console.log(prices.higher(99)); // [100, 'Enterprise'];
|
|
1290
|
+
* // Nothing above $100
|
|
1291
|
+
* console.log(prices.higher(100)); // undefined;
|
|
175
1292
|
*/
|
|
176
1293
|
higher(key: K): [K, V | undefined] | undefined;
|
|
177
1294
|
/**
|
|
178
1295
|
* Largest entry whose key is < the given key.
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
* @example
|
|
1335
|
+
* // Find the largest key strictly < target
|
|
1336
|
+
* const temps = new TreeMap<number, string>([
|
|
1337
|
+
* [0, 'Freezing'],
|
|
1338
|
+
* [20, 'Cool'],
|
|
1339
|
+
* [30, 'Warm'],
|
|
1340
|
+
* [40, 'Hot']
|
|
1341
|
+
* ]);
|
|
1342
|
+
*
|
|
1343
|
+
* // Largest reading below 30
|
|
1344
|
+
* console.log(temps.lower(30)); // [20, 'Cool'];
|
|
1345
|
+
* // Nothing below 0
|
|
1346
|
+
* console.log(temps.lower(0)); // undefined;
|
|
179
1347
|
*/
|
|
180
1348
|
lower(key: K): [K, V | undefined] | undefined;
|
|
181
1349
|
/**
|
|
@@ -183,16 +1351,124 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
183
1351
|
*
|
|
184
1352
|
* @param range `[low, high]`
|
|
185
1353
|
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
|
|
1392
|
+
* @example
|
|
1393
|
+
* // Inventory system with price-sorted products
|
|
1394
|
+
* interface Product {
|
|
1395
|
+
* name: string;
|
|
1396
|
+
* price: number;
|
|
1397
|
+
* stock: number;
|
|
1398
|
+
* }
|
|
1399
|
+
*
|
|
1400
|
+
* const inventory = new TreeMap<string, Product, Product>(
|
|
1401
|
+
* [
|
|
1402
|
+
* { name: 'Widget', price: 9.99, stock: 100 },
|
|
1403
|
+
* { name: 'Gadget', price: 24.99, stock: 50 },
|
|
1404
|
+
* { name: 'Doohickey', price: 4.99, stock: 200 }
|
|
1405
|
+
* ],
|
|
1406
|
+
* { toEntryFn: p => [p.name, p] }
|
|
1407
|
+
* );
|
|
1408
|
+
*
|
|
1409
|
+
* // Sorted alphabetically by product name
|
|
1410
|
+
* console.log([...inventory.keys()]); // ['Doohickey', 'Gadget', 'Widget'];
|
|
1411
|
+
*
|
|
1412
|
+
* // Filter high-stock items
|
|
1413
|
+
* const highStock = inventory.filter(p => (p?.stock ?? 0) > 75);
|
|
1414
|
+
* console.log([...highStock.keys()]); // ['Doohickey', 'Widget'];
|
|
1415
|
+
*
|
|
1416
|
+
* // Calculate total inventory value
|
|
1417
|
+
* const totalValue = inventory.reduce(
|
|
1418
|
+
* (sum, p) => sum + (p ? p.price * p.stock : 0),
|
|
1419
|
+
* 0
|
|
1420
|
+
* );
|
|
1421
|
+
* console.log(totalValue); // toBeCloseTo;
|
|
186
1422
|
*/
|
|
187
1423
|
rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
|
|
188
1424
|
/**
|
|
189
1425
|
* Creates a shallow clone of this map.
|
|
190
1426
|
* @remarks Time O(n log n), Space O(n)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
* @example
|
|
1467
|
+
* // Deep clone
|
|
1468
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
1469
|
+
* const copy = tm.clone();
|
|
1470
|
+
* copy.delete(1);
|
|
1471
|
+
* console.log(tm.has(1)); // true;
|
|
196
1472
|
*/
|
|
197
1473
|
clone(): TreeMap<K, V>;
|
|
198
1474
|
}
|