binary-tree-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 +0 -84
- package/dist/cjs/index.cjs +965 -420
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +962 -417
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +965 -421
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +962 -418
- 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/binary-tree-typed.js +959 -414
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +3 -3
- package/dist/umd/binary-tree-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
|
@@ -43,55 +43,311 @@ export declare class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
43
43
|
/**
|
|
44
44
|
* Number of distinct keys.
|
|
45
45
|
* @remarks Time O(1), Space O(1)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
* @example
|
|
49
|
+
* // Unique key count
|
|
50
|
+
* const ms = new TreeMultiSet<number>();
|
|
51
|
+
* ms.add(1, 3);
|
|
52
|
+
* ms.add(2, 2);
|
|
53
|
+
* console.log(ms.distinctSize); // 2;
|
|
46
54
|
*/
|
|
47
55
|
get distinctSize(): number;
|
|
48
56
|
/**
|
|
49
57
|
* Whether the multiset is empty.
|
|
50
58
|
* @remarks Time O(1), Space O(1)
|
|
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
|
+
|
|
97
|
+
* @example
|
|
98
|
+
* // Check empty
|
|
99
|
+
* console.log(new TreeMultiSet().isEmpty()); // true;
|
|
51
100
|
*/
|
|
52
101
|
isEmpty(): boolean;
|
|
53
102
|
/**
|
|
54
103
|
* Whether the multiset contains the given key.
|
|
55
104
|
* @remarks Time O(log n), Space O(1)
|
|
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
|
+
* @example
|
|
147
|
+
* // Check existence
|
|
148
|
+
* const ms = new TreeMultiSet<number>();
|
|
149
|
+
* ms.add(1);
|
|
150
|
+
* console.log(ms.has(1)); // true;
|
|
151
|
+
* console.log(ms.has(2)); // false;
|
|
56
152
|
*/
|
|
57
153
|
has(key: K): boolean;
|
|
58
154
|
/**
|
|
59
155
|
* Returns the count of occurrences for the given key.
|
|
60
156
|
* @remarks Time O(log n), Space O(1)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
* @example
|
|
160
|
+
* // Get occurrence count
|
|
161
|
+
* const ms = new TreeMultiSet<number>();
|
|
162
|
+
* ms.add(1, 5);
|
|
163
|
+
* console.log(ms.count(1)); // 5;
|
|
61
164
|
*/
|
|
62
165
|
count(key: K): number;
|
|
63
166
|
/**
|
|
64
167
|
* Add `n` occurrences of `key`.
|
|
65
168
|
* @returns True if the multiset changed.
|
|
66
169
|
* @remarks Time O(log n), Space O(1)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
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
|
+
* @example
|
|
203
|
+
* // Add elements
|
|
204
|
+
* const ms = new TreeMultiSet<number>();
|
|
205
|
+
* ms.add(1);
|
|
206
|
+
* ms.add(1);
|
|
207
|
+
* ms.add(2);
|
|
208
|
+
* console.log(ms.count(1)); // 2;
|
|
209
|
+
* console.log(ms.size); // 3;
|
|
67
210
|
*/
|
|
68
211
|
add(key: K, n?: number): boolean;
|
|
69
212
|
/**
|
|
70
213
|
* Set count for `key` to exactly `n`.
|
|
71
214
|
* @returns True if changed.
|
|
72
215
|
* @remarks Time O(log n), Space O(1)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
* @example
|
|
219
|
+
* // Set occurrence count
|
|
220
|
+
* const ms = new TreeMultiSet<number>();
|
|
221
|
+
* ms.setCount(1, 3);
|
|
222
|
+
* console.log(ms.count(1)); // 3;
|
|
73
223
|
*/
|
|
74
224
|
setCount(key: K, n: number): boolean;
|
|
75
225
|
/**
|
|
76
226
|
* Delete `n` occurrences of `key` (default 1).
|
|
77
227
|
* @returns True if any occurrence was removed.
|
|
78
228
|
* @remarks Time O(log n), Space O(1)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
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
|
+
* @example
|
|
271
|
+
* // Remove one occurrence
|
|
272
|
+
* const ms = new TreeMultiSet<number>();
|
|
273
|
+
* ms.add(1, 3);
|
|
274
|
+
* ms.delete(1);
|
|
275
|
+
* console.log(ms.count(1)); // 2;
|
|
79
276
|
*/
|
|
80
277
|
delete(key: K, n?: number): boolean;
|
|
81
278
|
/**
|
|
82
279
|
* Delete all occurrences of the given key.
|
|
83
280
|
* @returns True if any occurrence was removed.
|
|
84
281
|
* @remarks Time O(log n), Space O(1)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
* @example
|
|
285
|
+
* // Remove all occurrences
|
|
286
|
+
* const ms = new TreeMultiSet<number>();
|
|
287
|
+
* ms.add(1, 3);
|
|
288
|
+
* ms.deleteAll(1);
|
|
289
|
+
* console.log(ms.has(1)); // false;
|
|
85
290
|
*/
|
|
86
291
|
deleteAll(key: K): boolean;
|
|
87
292
|
/**
|
|
88
293
|
* Iterates over distinct keys (each key yielded once).
|
|
89
294
|
* @remarks Time O(n), Space O(1)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
* @example
|
|
298
|
+
* // Iterate unique keys
|
|
299
|
+
* const ms = new TreeMultiSet<number>();
|
|
300
|
+
* ms.add(1, 2);
|
|
301
|
+
* ms.add(2);
|
|
302
|
+
* console.log([...ms.keysDistinct()]); // [1, 2];
|
|
90
303
|
*/
|
|
91
304
|
keysDistinct(): IterableIterator<K>;
|
|
92
305
|
/**
|
|
93
306
|
* Iterates over entries as [key, count] pairs.
|
|
94
307
|
* @remarks Time O(n), Space O(1)
|
|
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
|
+
* @example
|
|
347
|
+
* // Iterate entries
|
|
348
|
+
* const ms = new TreeMultiSet<number>();
|
|
349
|
+
* ms.add(1, 2);
|
|
350
|
+
* console.log([...ms.entries()].length); // > 0;
|
|
95
351
|
*/
|
|
96
352
|
entries(): IterableIterator<[K, number]>;
|
|
97
353
|
/**
|
|
@@ -102,16 +358,76 @@ export declare class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
102
358
|
/**
|
|
103
359
|
* Returns an array with all elements (expanded).
|
|
104
360
|
* @remarks Time O(size), Space O(size)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
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
|
+
* @example
|
|
400
|
+
* // All elements (with duplicates)
|
|
401
|
+
* const ms = new TreeMultiSet<number>();
|
|
402
|
+
* ms.add(1, 2);
|
|
403
|
+
* ms.add(2);
|
|
404
|
+
* console.log(ms.toArray()); // [1, 1, 2];
|
|
105
405
|
*/
|
|
106
406
|
toArray(): K[];
|
|
107
407
|
/**
|
|
108
408
|
* Returns an array with distinct keys only.
|
|
109
409
|
* @remarks Time O(n), Space O(n)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
* @example
|
|
413
|
+
* // Unique keys only
|
|
414
|
+
* const ms = new TreeMultiSet<number>();
|
|
415
|
+
* ms.add(1, 3);
|
|
416
|
+
* ms.add(2);
|
|
417
|
+
* console.log(ms.toDistinctArray()); // [1, 2];
|
|
110
418
|
*/
|
|
111
419
|
toDistinctArray(): K[];
|
|
112
420
|
/**
|
|
113
421
|
* Returns an array of [key, count] entries.
|
|
114
422
|
* @remarks Time O(n), Space O(n)
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
* @example
|
|
426
|
+
* // Key-count pairs
|
|
427
|
+
* const ms = new TreeMultiSet<number>();
|
|
428
|
+
* ms.add(1, 2);
|
|
429
|
+
* ms.add(3);
|
|
430
|
+
* console.log(ms.toEntries()); // [[1, 2], [3, 1]];
|
|
115
431
|
*/
|
|
116
432
|
toEntries(): Array<[K, number]>;
|
|
117
433
|
/**
|
|
@@ -122,121 +438,481 @@ export declare class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
122
438
|
/**
|
|
123
439
|
* Remove all elements from the multiset.
|
|
124
440
|
* @remarks Time O(1), Space O(1)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
* @example
|
|
481
|
+
* // Remove all
|
|
482
|
+
* const ms = new TreeMultiSet<number>();
|
|
483
|
+
* ms.add(1);
|
|
484
|
+
* ms.clear();
|
|
485
|
+
* console.log(ms.isEmpty()); // true;
|
|
129
486
|
*/
|
|
130
487
|
clear(): void;
|
|
131
488
|
/**
|
|
132
489
|
* Returns the smallest key, or undefined if empty.
|
|
133
490
|
* @remarks Time O(log n), Space O(1)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
* @example
|
|
495
|
+
* // Smallest element
|
|
496
|
+
* const ms = new TreeMultiSet<number>();
|
|
497
|
+
* ms.add(3);
|
|
498
|
+
* ms.add(1);
|
|
499
|
+
* console.log(ms.first()); // 1;
|
|
137
500
|
*/
|
|
138
501
|
first(): K | undefined;
|
|
139
502
|
/**
|
|
140
503
|
* Returns the largest key, or undefined if empty.
|
|
141
504
|
* @remarks Time O(log n), Space O(1)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
* @example
|
|
509
|
+
* // Largest element
|
|
510
|
+
* const ms = new TreeMultiSet<number>();
|
|
511
|
+
* ms.add(1);
|
|
512
|
+
* ms.add(3);
|
|
513
|
+
* console.log(ms.last()); // 3;
|
|
145
514
|
*/
|
|
146
515
|
last(): K | undefined;
|
|
147
516
|
/**
|
|
148
517
|
* Removes all occurrences of the smallest key and returns it.
|
|
149
518
|
* @remarks Time O(log n), Space O(1)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
* @example
|
|
523
|
+
* // Remove and return smallest
|
|
524
|
+
* const ms = new TreeMultiSet<number>();
|
|
525
|
+
* ms.add(2);
|
|
526
|
+
* ms.add(1);
|
|
527
|
+
* console.log(ms.pollFirst()); // 1;
|
|
528
|
+
* console.log(ms.has(1)); // false;
|
|
154
529
|
*/
|
|
155
530
|
pollFirst(): K | undefined;
|
|
156
531
|
/**
|
|
157
532
|
* Removes all occurrences of the largest key and returns it.
|
|
158
533
|
* @remarks Time O(log n), Space O(1)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
* @example
|
|
538
|
+
* // Remove and return largest
|
|
539
|
+
* const ms = new TreeMultiSet<number>();
|
|
540
|
+
* ms.add(1);
|
|
541
|
+
* ms.add(3);
|
|
542
|
+
* console.log(ms.pollLast()); // 3;
|
|
163
543
|
*/
|
|
164
544
|
pollLast(): K | undefined;
|
|
165
545
|
/**
|
|
166
546
|
* Returns the smallest key >= given key, or undefined.
|
|
167
547
|
* @remarks Time O(log n), Space O(1)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
* @example
|
|
579
|
+
* // Least key ≥ target
|
|
580
|
+
* const ms = new TreeMultiSet<number>();
|
|
581
|
+
* ms.add(10);
|
|
582
|
+
* ms.add(20);
|
|
583
|
+
* ms.add(30);
|
|
584
|
+
* console.log(ms.ceiling(15)); // 20;
|
|
172
585
|
*/
|
|
173
586
|
ceiling(key: K): K | undefined;
|
|
174
587
|
/**
|
|
175
588
|
* Returns the largest key <= given key, or undefined.
|
|
176
589
|
* @remarks Time O(log n), Space O(1)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
* @example
|
|
621
|
+
* // Greatest key ≤ target
|
|
622
|
+
* const ms = new TreeMultiSet<number>();
|
|
623
|
+
* ms.add(10);
|
|
624
|
+
* ms.add(20);
|
|
625
|
+
* ms.add(30);
|
|
626
|
+
* console.log(ms.floor(25)); // 20;
|
|
181
627
|
*/
|
|
182
628
|
floor(key: K): K | undefined;
|
|
183
629
|
/**
|
|
184
630
|
* Returns the smallest key > given key, or undefined.
|
|
185
631
|
* @remarks Time O(log n), Space O(1)
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
* @example
|
|
663
|
+
* // Least key > target
|
|
664
|
+
* const ms = new TreeMultiSet<number>();
|
|
665
|
+
* ms.add(10);
|
|
666
|
+
* ms.add(20);
|
|
667
|
+
* console.log(ms.higher(10)); // 20;
|
|
190
668
|
*/
|
|
191
669
|
higher(key: K): K | undefined;
|
|
192
670
|
/**
|
|
193
671
|
* Returns the largest key < given key, or undefined.
|
|
194
672
|
* @remarks Time O(log n), Space O(1)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
+
* // Greatest key < target
|
|
705
|
+
* const ms = new TreeMultiSet<number>();
|
|
706
|
+
* ms.add(10);
|
|
707
|
+
* ms.add(20);
|
|
708
|
+
* console.log(ms.lower(20)); // 10;
|
|
199
709
|
*/
|
|
200
710
|
lower(key: K): K | undefined;
|
|
201
711
|
/**
|
|
202
712
|
* Iterates over distinct keys with their counts.
|
|
203
713
|
* @remarks Time O(n), Space O(1)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
|
|
752
|
+
|
|
753
|
+
* @example
|
|
754
|
+
* // Iterate
|
|
755
|
+
* const ms = new TreeMultiSet<number>();
|
|
756
|
+
* ms.add(1, 2);
|
|
757
|
+
* ms.add(2);
|
|
758
|
+
* const pairs: [number, number][] = [];
|
|
759
|
+
* ms.forEach((k, c) => pairs.push([k, c]));
|
|
760
|
+
* console.log(pairs); // [[1, 2], [2, 1]];
|
|
208
761
|
*/
|
|
209
762
|
forEach(callback: (key: K, count: number) => void): void;
|
|
210
763
|
/**
|
|
211
764
|
* Creates a new TreeMultiSet with entries that match the predicate.
|
|
212
765
|
* @remarks Time O(n log n), Space O(n)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
* @example
|
|
806
|
+
* // Filter
|
|
807
|
+
* const ms = new TreeMultiSet<number>();
|
|
808
|
+
* ms.add(1, 3);
|
|
809
|
+
* ms.add(2, 1);
|
|
810
|
+
* ms.add(3, 2);
|
|
811
|
+
* const filtered = ms.filter((k, c) => c > 1);
|
|
812
|
+
* console.log([...filtered.keysDistinct()]); // [1, 3];
|
|
217
813
|
*/
|
|
218
814
|
filter(predicate: (key: K, count: number) => boolean): TreeMultiSet<K>;
|
|
219
815
|
/**
|
|
220
816
|
* Reduces the multiset to a single value.
|
|
221
817
|
* @remarks Time O(n), Space O(1)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
* @example
|
|
858
|
+
* // Aggregate
|
|
859
|
+
* const ms = new TreeMultiSet<number>();
|
|
860
|
+
* ms.add(1, 2);
|
|
861
|
+
* ms.add(2, 3);
|
|
862
|
+
* const sum = ms.reduce((acc, k, c) => acc + k * c, 0);
|
|
863
|
+
* console.log(sum); // 8;
|
|
225
864
|
*/
|
|
226
865
|
reduce<U>(callback: (accumulator: U, key: K, count: number) => U, initialValue: U): U;
|
|
227
866
|
/**
|
|
228
867
|
* Maps keys and counts to a new TreeMultiSet.
|
|
229
868
|
* When multiple keys map to the same new key, counts are merged (added).
|
|
230
869
|
* @remarks Time O(n log n), Space O(n)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
* @example
|
|
910
|
+
* // Transform
|
|
911
|
+
* const ms = new TreeMultiSet<number>();
|
|
912
|
+
* ms.add(1, 2);
|
|
913
|
+
* ms.add(2, 3);
|
|
914
|
+
* const doubled = ms.map((k, c) => [k * 10, c] as [number, number]);
|
|
915
|
+
* console.log([...doubled.keysDistinct()]); // [10, 20];
|
|
240
916
|
*/
|
|
241
917
|
map<K2>(mapper: (key: K, count: number) => [K2, number], options?: {
|
|
242
918
|
comparator?: Comparator<K2>;
|
|
@@ -244,27 +920,144 @@ export declare class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
244
920
|
/**
|
|
245
921
|
* Creates an independent copy of this multiset.
|
|
246
922
|
* @remarks Time O(n log n), Space O(n)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
* @example
|
|
963
|
+
* // Deep clone
|
|
964
|
+
* const ms = new TreeMultiSet<number>();
|
|
965
|
+
* ms.add(1, 3);
|
|
966
|
+
* const copy = ms.clone();
|
|
967
|
+
* copy.deleteAll(1);
|
|
968
|
+
* console.log(ms.has(1)); // true;
|
|
252
969
|
*/
|
|
253
970
|
clone(): TreeMultiSet<K>;
|
|
254
971
|
/**
|
|
255
972
|
* Returns keys within the given range.
|
|
256
973
|
* @remarks Time O(log n + k), Space O(k) where k is result size
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
* @example
|
|
1005
|
+
* // Find in range
|
|
1006
|
+
* const ms = new TreeMultiSet<number>();
|
|
1007
|
+
* ms.add(10);
|
|
1008
|
+
* ms.add(20);
|
|
1009
|
+
* ms.add(30);
|
|
1010
|
+
* const result = ms.rangeSearch([15, 25]);
|
|
1011
|
+
* console.log(result.length); // 1;
|
|
260
1012
|
*/
|
|
261
1013
|
rangeSearch<C extends (key: K) => any>(range: [K, K], callback?: C): (C extends undefined ? K : ReturnType<C>)[];
|
|
262
1014
|
/**
|
|
263
1015
|
* Prints the internal tree structure (for debugging).
|
|
264
1016
|
* @remarks Time O(n), Space O(n)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
* @example
|
|
1057
|
+
* // Display
|
|
1058
|
+
* const ms = new TreeMultiSet<number>();
|
|
1059
|
+
* ms.add(1);
|
|
1060
|
+
* expect(() => ms.print()).not.toThrow();
|
|
268
1061
|
*/
|
|
269
1062
|
print(): void;
|
|
270
1063
|
}
|