binary-tree-typed 2.4.5 → 2.5.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 +0 -84
- package/dist/cjs/index.cjs +1476 -404
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1473 -401
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +1476 -404
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1473 -401
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
- package/dist/types/data-structures/heap/heap.d.ts +581 -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 +646 -47
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +499 -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 +593 -71
- package/dist/types/data-structures/queue/queue.d.ts +463 -42
- package/dist/types/data-structures/stack/stack.d.ts +384 -32
- package/dist/types/data-structures/trie/trie.d.ts +470 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/binary-tree-typed.js +1469 -397
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- 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 +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -77,32 +77,6 @@ export declare class TrieNode {
|
|
|
77
77
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
78
78
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
|
|
79
79
|
* @example
|
|
80
|
-
* // basic Trie creation and add words
|
|
81
|
-
* // Create a simple Trie with initial words
|
|
82
|
-
* const trie = new Trie(['apple', 'app', 'apply']);
|
|
83
|
-
*
|
|
84
|
-
* // Verify size
|
|
85
|
-
* console.log(trie.size); // 3;
|
|
86
|
-
*
|
|
87
|
-
* // Check if words exist
|
|
88
|
-
* console.log(trie.has('apple')); // true;
|
|
89
|
-
* console.log(trie.has('app')); // true;
|
|
90
|
-
*
|
|
91
|
-
* // Add a new word
|
|
92
|
-
* trie.add('application');
|
|
93
|
-
* console.log(trie.size); // 4;
|
|
94
|
-
* @example
|
|
95
|
-
* // Trie getWords and prefix search
|
|
96
|
-
* const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
|
|
97
|
-
*
|
|
98
|
-
* // Get all words with prefix 'app'
|
|
99
|
-
* const appWords = trie.getWords('app');
|
|
100
|
-
* console.log(appWords); // contains 'app';
|
|
101
|
-
* console.log(appWords); // contains 'apple';
|
|
102
|
-
* console.log(appWords); // contains 'apply';
|
|
103
|
-
* console.log(appWords); // contains 'application';
|
|
104
|
-
* expect(appWords).not.toContain('apricot');
|
|
105
|
-
* @example
|
|
106
80
|
* // Trie isPrefix and isAbsolutePrefix checks
|
|
107
81
|
* const trie = new Trie(['tree', 'trial', 'trick', 'trip', 'trie']);
|
|
108
82
|
*
|
|
@@ -118,23 +92,6 @@ export declare class TrieNode {
|
|
|
118
92
|
* // Verify size
|
|
119
93
|
* console.log(trie.size); // 5;
|
|
120
94
|
* @example
|
|
121
|
-
* // Trie delete and iteration
|
|
122
|
-
* const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
|
|
123
|
-
*
|
|
124
|
-
* // Delete a word
|
|
125
|
-
* trie.delete('card');
|
|
126
|
-
* console.log(trie.has('card')); // false;
|
|
127
|
-
*
|
|
128
|
-
* // Word with same prefix still exists
|
|
129
|
-
* console.log(trie.has('care')); // true;
|
|
130
|
-
*
|
|
131
|
-
* // Size decreased
|
|
132
|
-
* console.log(trie.size); // 5;
|
|
133
|
-
*
|
|
134
|
-
* // Iterate through all words
|
|
135
|
-
* const allWords = [...trie];
|
|
136
|
-
* console.log(allWords.length); // 5;
|
|
137
|
-
* @example
|
|
138
95
|
* // Trie for autocomplete search index
|
|
139
96
|
* // Trie is perfect for autocomplete: O(m + k) where m is prefix length, k is results
|
|
140
97
|
* const searchIndex = new Trie(['typescript', 'javascript', 'python', 'java', 'rust', 'ruby', 'golang', 'kotlin']);
|
|
@@ -261,6 +218,53 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
261
218
|
* @remarks Time O(L), Space O(L)
|
|
262
219
|
* @param word - Word to insert.
|
|
263
220
|
* @returns True if the word was newly added.
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
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
|
+
* @example
|
|
254
|
+
* // basic Trie creation and add words
|
|
255
|
+
* // Create a simple Trie with initial words
|
|
256
|
+
* const trie = new Trie(['apple', 'app', 'apply']);
|
|
257
|
+
*
|
|
258
|
+
* // Verify size
|
|
259
|
+
* console.log(trie.size); // 3;
|
|
260
|
+
*
|
|
261
|
+
* // Check if words exist
|
|
262
|
+
* console.log(trie.has('apple')); // true;
|
|
263
|
+
* console.log(trie.has('app')); // true;
|
|
264
|
+
*
|
|
265
|
+
* // Add a new word
|
|
266
|
+
* trie.add('application');
|
|
267
|
+
* console.log(trie.size); // 4;
|
|
264
268
|
*/
|
|
265
269
|
add(word: string): boolean;
|
|
266
270
|
/**
|
|
@@ -268,6 +272,42 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
268
272
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
269
273
|
* @param words - Iterable of strings (or raw records if toElementFn is provided).
|
|
270
274
|
* @returns Array of per-word 'added' flags.
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
* @example
|
|
305
|
+
* // Add multiple words
|
|
306
|
+
* const trie = new Trie();
|
|
307
|
+
* trie.addMany(['cat', 'car', 'card']);
|
|
308
|
+
* console.log(trie.has('cat')); // true;
|
|
309
|
+
* console.log(trie.has('car')); // true;
|
|
310
|
+
* console.log(trie.size); // 3;
|
|
271
311
|
*/
|
|
272
312
|
addMany(words: Iterable<string> | Iterable<R>): boolean[];
|
|
273
313
|
/**
|
|
@@ -275,18 +315,126 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
275
315
|
* @remarks Time O(L), Space O(1)
|
|
276
316
|
* @param word - Word to search for.
|
|
277
317
|
* @returns True if present.
|
|
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
|
+
* @example
|
|
351
|
+
* // Check if a word exists
|
|
352
|
+
* const dict = new Trie(['apple', 'app', 'application']);
|
|
353
|
+
*
|
|
354
|
+
* console.log(dict.has('app')); // true;
|
|
355
|
+
* console.log(dict.has('apple')); // true;
|
|
356
|
+
* console.log(dict.has('ap')); // false;
|
|
278
357
|
*/
|
|
279
358
|
has(word: string): boolean;
|
|
280
359
|
/**
|
|
281
360
|
* Check whether the trie is empty.
|
|
282
361
|
* @remarks Time O(1), Space O(1)
|
|
283
362
|
* @returns True if size is 0.
|
|
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
|
+
* @example
|
|
393
|
+
* // Check if empty
|
|
394
|
+
* const trie = new Trie();
|
|
395
|
+
* console.log(trie.isEmpty()); // true;
|
|
396
|
+
* trie.add('word');
|
|
397
|
+
* console.log(trie.isEmpty()); // false;
|
|
284
398
|
*/
|
|
285
399
|
isEmpty(): boolean;
|
|
286
400
|
/**
|
|
287
401
|
* Remove all words and reset to a fresh root.
|
|
288
402
|
* @remarks Time O(1), Space O(1)
|
|
289
403
|
* @returns void
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
* @example
|
|
434
|
+
* // Remove all words
|
|
435
|
+
* const trie = new Trie(['a', 'b', 'c']);
|
|
436
|
+
* trie.clear();
|
|
437
|
+
* console.log(trie.isEmpty()); // true;
|
|
290
438
|
*/
|
|
291
439
|
clear(): void;
|
|
292
440
|
/**
|
|
@@ -294,6 +442,55 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
294
442
|
* @remarks Time O(L), Space O(1)
|
|
295
443
|
* @param word - Word to delete.
|
|
296
444
|
* @returns True if a word was removed.
|
|
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
|
+
* @example
|
|
478
|
+
* // Trie delete and iteration
|
|
479
|
+
* const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
|
|
480
|
+
*
|
|
481
|
+
* // Delete a word
|
|
482
|
+
* trie.delete('card');
|
|
483
|
+
* console.log(trie.has('card')); // false;
|
|
484
|
+
*
|
|
485
|
+
* // Word with same prefix still exists
|
|
486
|
+
* console.log(trie.has('care')); // true;
|
|
487
|
+
*
|
|
488
|
+
* // Size decreased
|
|
489
|
+
* console.log(trie.size); // 5;
|
|
490
|
+
*
|
|
491
|
+
* // Iterate through all words
|
|
492
|
+
* const allWords = [...trie];
|
|
493
|
+
* console.log(allWords.length); // 5;
|
|
297
494
|
*/
|
|
298
495
|
delete(word: string): boolean;
|
|
299
496
|
/**
|
|
@@ -314,6 +511,45 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
314
511
|
* @remarks Time O(L), Space O(1)
|
|
315
512
|
* @param input - String to test as prefix.
|
|
316
513
|
* @returns True if input matches a path from root.
|
|
514
|
+
|
|
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
|
+
* @example
|
|
547
|
+
* // Check if a prefix exists
|
|
548
|
+
* const trie = new Trie(['hello', 'help', 'world']);
|
|
549
|
+
*
|
|
550
|
+
* console.log(trie.hasPrefix('hel')); // true;
|
|
551
|
+
* console.log(trie.hasPrefix('wor')); // true;
|
|
552
|
+
* console.log(trie.hasPrefix('xyz')); // false;
|
|
317
553
|
*/
|
|
318
554
|
hasPrefix(input: string): boolean;
|
|
319
555
|
/**
|
|
@@ -327,6 +563,43 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
327
563
|
* Return the longest common prefix among all words.
|
|
328
564
|
* @remarks Time O(H), Space O(1)
|
|
329
565
|
* @returns The longest common prefix string.
|
|
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
|
+
* @example
|
|
599
|
+
* // Find shared prefix
|
|
600
|
+
* const trie = new Trie(['flower', 'flow', 'flight']);
|
|
601
|
+
*
|
|
602
|
+
* console.log(trie.getLongestCommonPrefix()); // 'fl';
|
|
330
603
|
*/
|
|
331
604
|
getLongestCommonPrefix(): string;
|
|
332
605
|
/**
|
|
@@ -336,12 +609,90 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
336
609
|
* @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
|
|
337
610
|
* @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
|
|
338
611
|
* @returns Array of collected words (at most max).
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
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
|
+
* @example
|
|
645
|
+
* // Trie getWords and prefix search
|
|
646
|
+
* const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
|
|
647
|
+
*
|
|
648
|
+
* // Get all words with prefix 'app'
|
|
649
|
+
* const appWords = trie.getWords('app');
|
|
650
|
+
* console.log(appWords); // contains 'app';
|
|
651
|
+
* console.log(appWords); // contains 'apple';
|
|
652
|
+
* console.log(appWords); // contains 'apply';
|
|
653
|
+
* console.log(appWords); // contains 'application';
|
|
654
|
+
* expect(appWords).not.toContain('apricot');
|
|
339
655
|
*/
|
|
340
656
|
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
341
657
|
/**
|
|
342
658
|
* Deep clone this trie by iterating and inserting all words.
|
|
343
659
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
344
660
|
* @returns A new trie with the same words and options.
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
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
|
+
* @example
|
|
691
|
+
* // Create independent copy
|
|
692
|
+
* const trie = new Trie(['hello', 'world']);
|
|
693
|
+
* const copy = trie.clone();
|
|
694
|
+
* copy.delete('hello');
|
|
695
|
+
* console.log(trie.has('hello')); // true;
|
|
345
696
|
*/
|
|
346
697
|
clone(): this;
|
|
347
698
|
/**
|
|
@@ -350,9 +701,80 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
350
701
|
* @param predicate - Predicate (word, index, trie) → boolean to keep word.
|
|
351
702
|
* @param [thisArg] - Value for `this` inside the predicate.
|
|
352
703
|
* @returns A new trie containing words that satisfy the predicate.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
* @example
|
|
734
|
+
* // Filter words
|
|
735
|
+
* const trie = new Trie(['cat', 'car', 'dog', 'card']);
|
|
736
|
+
* const result = trie.filter(w => w.startsWith('ca'));
|
|
737
|
+
* console.log(result.size); // 3;
|
|
738
|
+
*/
|
|
739
|
+
filter(predicate: ElementCallback<string, R, boolean>, thisArg?: unknown): this;
|
|
740
|
+
/**
|
|
741
|
+
* Transform words
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
* @example
|
|
772
|
+
* // Transform words
|
|
773
|
+
* const trie = new Trie(['hello', 'world']);
|
|
774
|
+
* const upper = trie.map(w => w.toUpperCase());
|
|
775
|
+
* console.log(upper.has('HELLO')); // true;
|
|
776
|
+
*/
|
|
777
|
+
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: unknown): Trie<RM>;
|
|
356
778
|
/**
|
|
357
779
|
* Map words into a new trie (possibly different record type).
|
|
358
780
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
@@ -363,7 +785,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
363
785
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
364
786
|
* @returns A new Trie constructed from mapped words.
|
|
365
787
|
*/
|
|
366
|
-
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?:
|
|
788
|
+
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: unknown): IterableElementBase<EM, RM>;
|
|
367
789
|
/**
|
|
368
790
|
* Map words into a new trie of the same element type.
|
|
369
791
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
@@ -371,7 +793,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
371
793
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
372
794
|
* @returns A new trie with mapped words.
|
|
373
795
|
*/
|
|
374
|
-
mapSame(callback: ElementCallback<string, R, string>, thisArg?:
|
|
796
|
+
mapSame(callback: ElementCallback<string, R, string>, thisArg?: unknown): this;
|
|
375
797
|
/**
|
|
376
798
|
* (Protected) Create an empty instance of the same concrete class.
|
|
377
799
|
* @remarks Time O(1), Space O(1)
|
|
@@ -5,10 +5,10 @@ export type Comparator<K> = (a: K, b: K) => number;
|
|
|
5
5
|
export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
|
|
6
6
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
7
7
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
8
|
-
size: number | ((...args:
|
|
8
|
+
size: number | ((...args: unknown[]) => number);
|
|
9
9
|
}
|
|
10
10
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
11
|
-
length: number | ((...args:
|
|
11
|
+
length: number | ((...args: unknown[]) => number);
|
|
12
12
|
}
|
|
13
13
|
export type OptValue<V> = V | undefined;
|
|
14
14
|
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export type KeyValueObject = {
|
|
2
|
-
[key: string]:
|
|
2
|
+
[key: string]: unknown;
|
|
3
3
|
};
|
|
4
4
|
export type KeyValueObjectWithKey = {
|
|
5
|
-
[key: string]:
|
|
5
|
+
[key: string]: unknown;
|
|
6
6
|
key: string | number | symbol;
|
|
7
7
|
};
|
|
8
8
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
9
9
|
export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
|
|
10
10
|
export type ObjectWithNonNumberKey = {
|
|
11
|
-
[key: string]:
|
|
11
|
+
[key: string]: unknown;
|
|
12
12
|
key: string | boolean | symbol | null | object | undefined;
|
|
13
13
|
};
|
|
14
14
|
export type ObjectWithNumberKey = {
|
|
15
|
-
[key: string]:
|
|
15
|
+
[key: string]: unknown;
|
|
16
16
|
key: number;
|
|
17
17
|
};
|
|
18
18
|
export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;
|