data-structure-typed 2.6.0 → 2.6.2
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
- package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +45 -46
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +0 -3
- package/src/data-structures/base/linear-base.ts +2 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -529
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
- package/src/data-structures/binary-tree/bst.ts +158 -1082
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
- package/src/data-structures/binary-tree/segment-tree.ts +73 -351
- package/src/data-structures/binary-tree/tree-map.ts +462 -5124
- package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
- package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
- package/src/data-structures/binary-tree/tree-set.ts +338 -4836
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -562
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -511
- package/src/data-structures/hash/hash-map.ts +154 -582
- package/src/data-structures/heap/heap.ts +200 -795
- package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
- package/src/data-structures/matrix/matrix.ts +179 -518
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +214 -882
- package/src/data-structures/queue/queue.ts +102 -625
- package/src/data-structures/stack/stack.ts +76 -505
- package/src/data-structures/trie/trie.ts +98 -628
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
|
@@ -189,6 +189,10 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
189
189
|
*/
|
|
190
190
|
export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R> {
|
|
191
191
|
iterationType: IterationType;
|
|
192
|
+
protected readonly _isMapMode: boolean;
|
|
193
|
+
protected readonly _isDuplicate: boolean;
|
|
194
|
+
protected readonly _NIL: BinaryTreeNode<K, V>;
|
|
195
|
+
protected readonly _toEntryFn?: ToEntryFn<K, V, R>;
|
|
192
196
|
/**
|
|
193
197
|
* Creates an instance of BinaryTree.
|
|
194
198
|
* @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `set` operation). Space O(N) for storing the nodes.
|
|
@@ -197,7 +201,6 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
197
201
|
* @param [options] - Configuration options for the tree.
|
|
198
202
|
*/
|
|
199
203
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
200
|
-
protected readonly _isMapMode: boolean;
|
|
201
204
|
/**
|
|
202
205
|
* Gets whether the tree is in Map mode.
|
|
203
206
|
* @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
|
|
@@ -205,7 +208,6 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
205
208
|
* @returns True if in Map mode, false otherwise.
|
|
206
209
|
*/
|
|
207
210
|
get isMapMode(): boolean;
|
|
208
|
-
protected readonly _isDuplicate: boolean;
|
|
209
211
|
/**
|
|
210
212
|
* Gets whether the tree allows duplicate keys.
|
|
211
213
|
* @remarks Time O(1)
|
|
@@ -237,7 +239,6 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
237
239
|
* @returns The size of the tree.
|
|
238
240
|
*/
|
|
239
241
|
get size(): number;
|
|
240
|
-
protected readonly _NIL: BinaryTreeNode<K, V>;
|
|
241
242
|
/**
|
|
242
243
|
* Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
243
244
|
* @remarks Time O(1)
|
|
@@ -245,7 +246,6 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
245
246
|
* @returns The NIL node.
|
|
246
247
|
*/
|
|
247
248
|
get NIL(): BinaryTreeNode<K, V>;
|
|
248
|
-
protected readonly _toEntryFn?: ToEntryFn<K, V, R>;
|
|
249
249
|
/**
|
|
250
250
|
* Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
251
251
|
* @remarks Time O(1)
|
|
@@ -253,6 +253,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
253
253
|
* @returns The conversion function.
|
|
254
254
|
*/
|
|
255
255
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
256
|
+
protected static _buildNodeDisplay(line: string, width: number, left: NodeDisplayLayout, right: NodeDisplayLayout): NodeDisplayLayout;
|
|
256
257
|
/**
|
|
257
258
|
* (Protected) Creates a new node.
|
|
258
259
|
* @remarks Time O(1), Space O(1)
|
|
@@ -357,51 +358,14 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
357
358
|
*
|
|
358
359
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
359
360
|
* @returns True if the addition was successful, false otherwise.
|
|
360
|
-
|
|
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
|
-
* @example
|
|
398
|
-
* // Add a single node
|
|
399
|
-
* const tree = new BinaryTree<number>();
|
|
400
|
-
* tree.add(1);
|
|
401
|
-
* tree.add(2);
|
|
402
|
-
* tree.add(3);
|
|
403
|
-
* console.log(tree.size); // 3;
|
|
404
|
-
* console.log(tree.has(1)); // true;
|
|
361
|
+
* @example
|
|
362
|
+
* // Add a single node
|
|
363
|
+
* const tree = new BinaryTree<number>();
|
|
364
|
+
* tree.add(1);
|
|
365
|
+
* tree.add(2);
|
|
366
|
+
* tree.add(3);
|
|
367
|
+
* console.log(tree.size); // 3;
|
|
368
|
+
* console.log(tree.has(1)); // true;
|
|
405
369
|
*/
|
|
406
370
|
add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
407
371
|
/**
|
|
@@ -411,71 +375,29 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
411
375
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
412
376
|
* @param [value] - The value, if providing just a key.
|
|
413
377
|
* @returns True if the addition was successful, false otherwise.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
* // basic BinaryTree creation and insertion
|
|
458
|
-
* // Create a BinaryTree with entries
|
|
459
|
-
* const entries: [number, string][] = [
|
|
460
|
-
* [6, 'six'],
|
|
461
|
-
* [1, 'one'],
|
|
462
|
-
* [2, 'two'],
|
|
463
|
-
* [7, 'seven'],
|
|
464
|
-
* [5, 'five'],
|
|
465
|
-
* [3, 'three'],
|
|
466
|
-
* [4, 'four'],
|
|
467
|
-
* [9, 'nine'],
|
|
468
|
-
* [8, 'eight']
|
|
469
|
-
* ];
|
|
470
|
-
*
|
|
471
|
-
* const tree = new BinaryTree(entries);
|
|
472
|
-
*
|
|
473
|
-
* // Verify size
|
|
474
|
-
* console.log(tree.size); // 9;
|
|
475
|
-
*
|
|
476
|
-
* // Add new element
|
|
477
|
-
* tree.set(10, 'ten');
|
|
478
|
-
* console.log(tree.size); // 10;
|
|
378
|
+
* @example
|
|
379
|
+
* // basic BinaryTree creation and insertion
|
|
380
|
+
* // Create a BinaryTree with entries
|
|
381
|
+
* const entries: [number, string][] = [
|
|
382
|
+
* [6, 'six'],
|
|
383
|
+
* [1, 'one'],
|
|
384
|
+
* [2, 'two'],
|
|
385
|
+
* [7, 'seven'],
|
|
386
|
+
* [5, 'five'],
|
|
387
|
+
* [3, 'three'],
|
|
388
|
+
* [4, 'four'],
|
|
389
|
+
* [9, 'nine'],
|
|
390
|
+
* [8, 'eight']
|
|
391
|
+
* ];
|
|
392
|
+
*
|
|
393
|
+
* const tree = new BinaryTree(entries);
|
|
394
|
+
*
|
|
395
|
+
* // Verify size
|
|
396
|
+
* console.log(tree.size); // 9;
|
|
397
|
+
*
|
|
398
|
+
* // Add new element
|
|
399
|
+
* tree.set(10, 'ten');
|
|
400
|
+
* console.log(tree.size); // 10;
|
|
479
401
|
*/
|
|
480
402
|
set(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
481
403
|
/**
|
|
@@ -484,51 +406,11 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
484
406
|
*
|
|
485
407
|
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
486
408
|
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
* @example
|
|
528
|
-
* // Bulk add
|
|
529
|
-
* const tree = new BinaryTree<number>();
|
|
530
|
-
* tree.addMany([1, 2, 3, 4, 5]);
|
|
531
|
-
* console.log(tree.size); // 5;
|
|
409
|
+
* @example
|
|
410
|
+
* // Bulk add
|
|
411
|
+
* const tree = new BinaryTree<number>();
|
|
412
|
+
* tree.addMany([1, 2, 3, 4, 5]);
|
|
413
|
+
* console.log(tree.size); // 5;
|
|
532
414
|
*/
|
|
533
415
|
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>): boolean[];
|
|
534
416
|
/**
|
|
@@ -538,44 +420,15 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
538
420
|
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
539
421
|
* @param [values] - An optional parallel iterable of values.
|
|
540
422
|
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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
|
-
* @example
|
|
575
|
-
* // Set multiple entries
|
|
576
|
-
* const tree = new BinaryTree<number, string>();
|
|
577
|
-
* tree.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
578
|
-
* console.log(tree.size); // 3;
|
|
423
|
+
* @example
|
|
424
|
+
* // Set multiple entries
|
|
425
|
+
* const tree = new BinaryTree<number, string>();
|
|
426
|
+
* tree.setMany([
|
|
427
|
+
* [1, 'a'],
|
|
428
|
+
* [2, 'b'],
|
|
429
|
+
* [3, 'c']
|
|
430
|
+
* ]);
|
|
431
|
+
* console.log(tree.size); // 3;
|
|
579
432
|
*/
|
|
580
433
|
setMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
|
|
581
434
|
/**
|
|
@@ -583,160 +436,36 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
583
436
|
* @remarks Time O(N * M), same as `setMany`, where N is the size of `anotherTree` and M is the size of this tree. Space O(M) (from `set`).
|
|
584
437
|
*
|
|
585
438
|
* @param anotherTree - The tree to merge.
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
* @example
|
|
627
|
-
* // Combine trees
|
|
628
|
-
* const t1 = new BinaryTree<number>([1, 2]);
|
|
629
|
-
* const t2 = new BinaryTree<number>([3, 4]);
|
|
630
|
-
* t1.merge(t2);
|
|
631
|
-
* console.log(t1.size); // 4;
|
|
439
|
+
* @example
|
|
440
|
+
* // Combine trees
|
|
441
|
+
* const t1 = new BinaryTree<number>([1, 2]);
|
|
442
|
+
* const t2 = new BinaryTree<number>([3, 4]);
|
|
443
|
+
* t1.merge(t2);
|
|
444
|
+
* console.log(t1.size); // 4;
|
|
632
445
|
*/
|
|
633
446
|
merge(anotherTree: BinaryTree<K, V, R>): void;
|
|
634
|
-
/**
|
|
635
|
-
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
636
|
-
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
637
|
-
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
638
|
-
*
|
|
639
|
-
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
640
|
-
* @returns An array containing deletion results with balancing metadata.
|
|
641
|
-
*/
|
|
642
|
-
protected _deleteInternal(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
643
447
|
/**
|
|
644
448
|
* Deletes a node from the tree.
|
|
645
449
|
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
646
450
|
*
|
|
647
451
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
648
452
|
* @returns True if the node was found and deleted, false otherwise.
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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
|
-
|
|
691
|
-
* @example
|
|
692
|
-
* // Remove a node
|
|
693
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
694
|
-
* tree.delete(3);
|
|
695
|
-
* console.log(tree.has(3)); // false;
|
|
696
|
-
* console.log(tree.size); // 4;
|
|
453
|
+
* @example
|
|
454
|
+
* // Remove a node
|
|
455
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
456
|
+
* tree.delete(3);
|
|
457
|
+
* console.log(tree.has(3)); // false;
|
|
458
|
+
* console.log(tree.size); // 4;
|
|
697
459
|
*/
|
|
698
460
|
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): boolean;
|
|
699
461
|
/**
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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
|
-
|
|
734
|
-
* @example
|
|
735
|
-
* // Search by predicate
|
|
736
|
-
* const tree = new BinaryTree<number>([5, 3, 7, 1, 9]);
|
|
737
|
-
* const found = tree.search(n => n!.key > 5, true);
|
|
738
|
-
* console.log(found.length); // >= 1;
|
|
739
|
-
*/
|
|
462
|
+
* Search by predicate
|
|
463
|
+
* @example
|
|
464
|
+
* // Search by predicate
|
|
465
|
+
* const tree = new BinaryTree<number>([5, 3, 7, 1, 9]);
|
|
466
|
+
* const found = tree.search(n => n!.key > 5, true);
|
|
467
|
+
* console.log(found.length); // >= 1;
|
|
468
|
+
*/
|
|
740
469
|
search(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne?: boolean): (K | undefined)[];
|
|
741
470
|
search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne: boolean, callback: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
742
471
|
/**
|
|
@@ -748,50 +477,11 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
748
477
|
* @param [startNode=this._root] - The node to start the search from.
|
|
749
478
|
* @param [iterationType=this.iterationType] - The traversal method.
|
|
750
479
|
* @returns An array of matching nodes.
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
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
|
-
* @example
|
|
791
|
-
* // Get nodes by condition
|
|
792
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
793
|
-
* const nodes = tree.getNodes(node => node.key > 3);
|
|
794
|
-
* console.log(nodes.length); // 2;
|
|
480
|
+
* @example
|
|
481
|
+
* // Get nodes by condition
|
|
482
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
483
|
+
* const nodes = tree.getNodes(node => node.key > 3);
|
|
484
|
+
* console.log(nodes.length); // 2;
|
|
795
485
|
*/
|
|
796
486
|
getNodes(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V>[];
|
|
797
487
|
/**
|
|
@@ -802,50 +492,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
802
492
|
* @param [startNode=this._root] - The node to start the search from.
|
|
803
493
|
* @param [iterationType=this.iterationType] - The traversal method.
|
|
804
494
|
* @returns The first matching node, or undefined if not found.
|
|
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
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
* @example
|
|
846
|
-
* // Get node by key
|
|
847
|
-
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'child']]);
|
|
848
|
-
* console.log(tree.getNode(2)?.value); // 'child';
|
|
495
|
+
* @example
|
|
496
|
+
* // Get node by key
|
|
497
|
+
* const tree = new BinaryTree<number, string>([
|
|
498
|
+
* [1, 'root'],
|
|
499
|
+
* [2, 'child']
|
|
500
|
+
* ]);
|
|
501
|
+
* console.log(tree.getNode(2)?.value); // 'child';
|
|
849
502
|
*/
|
|
850
503
|
getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V> | null | undefined;
|
|
851
504
|
/**
|
|
@@ -856,53 +509,15 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
856
509
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
857
510
|
* @param [iterationType=this.iterationType] - The traversal method (if not in Map mode).
|
|
858
511
|
* @returns The associated value, or undefined.
|
|
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
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
* @example
|
|
902
|
-
* // Retrieve value by key
|
|
903
|
-
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'left'], [3, 'right']]);
|
|
904
|
-
* console.log(tree.get(2)); // 'left';
|
|
905
|
-
* console.log(tree.get(99)); // undefined;
|
|
512
|
+
* @example
|
|
513
|
+
* // Retrieve value by key
|
|
514
|
+
* const tree = new BinaryTree<number, string>([
|
|
515
|
+
* [1, 'root'],
|
|
516
|
+
* [2, 'left'],
|
|
517
|
+
* [3, 'right']
|
|
518
|
+
* ]);
|
|
519
|
+
* console.log(tree.get(2)); // 'left';
|
|
520
|
+
* console.log(tree.get(99)); // undefined;
|
|
906
521
|
*/
|
|
907
522
|
get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
|
|
908
523
|
/**
|
|
@@ -913,126 +528,44 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
913
528
|
* @param [startNode] - The node to start the search from.
|
|
914
529
|
* @param [iterationType] - The traversal method.
|
|
915
530
|
* @returns True if a matching node exists, false otherwise.
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
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
|
-
* @example
|
|
959
|
-
* // BinaryTree get and has operations
|
|
960
|
-
* const tree = new BinaryTree(
|
|
961
|
-
* [
|
|
962
|
-
* [5, 'five'],
|
|
963
|
-
* [3, 'three'],
|
|
964
|
-
* [7, 'seven'],
|
|
965
|
-
* [1, 'one'],
|
|
966
|
-
* [4, 'four'],
|
|
967
|
-
* [6, 'six'],
|
|
968
|
-
* [8, 'eight']
|
|
969
|
-
* ],
|
|
970
|
-
* { isMapMode: false }
|
|
971
|
-
* );
|
|
972
|
-
*
|
|
973
|
-
* // Check if key exists
|
|
974
|
-
* console.log(tree.has(5)); // true;
|
|
975
|
-
* console.log(tree.has(10)); // false;
|
|
976
|
-
*
|
|
977
|
-
* // Get value by key
|
|
978
|
-
* console.log(tree.get(3)); // 'three';
|
|
979
|
-
* console.log(tree.get(7)); // 'seven';
|
|
980
|
-
* console.log(tree.get(100)); // undefined;
|
|
981
|
-
*
|
|
982
|
-
* // Get node structure
|
|
983
|
-
* const node = tree.getNode(5);
|
|
984
|
-
* console.log(node?.key); // 5;
|
|
985
|
-
* console.log(node?.value); // 'five';
|
|
531
|
+
* @example
|
|
532
|
+
* // BinaryTree get and has operations
|
|
533
|
+
* const tree = new BinaryTree(
|
|
534
|
+
* [
|
|
535
|
+
* [5, 'five'],
|
|
536
|
+
* [3, 'three'],
|
|
537
|
+
* [7, 'seven'],
|
|
538
|
+
* [1, 'one'],
|
|
539
|
+
* [4, 'four'],
|
|
540
|
+
* [6, 'six'],
|
|
541
|
+
* [8, 'eight']
|
|
542
|
+
* ],
|
|
543
|
+
* { isMapMode: false }
|
|
544
|
+
* );
|
|
545
|
+
*
|
|
546
|
+
* // Check if key exists
|
|
547
|
+
* console.log(tree.has(5)); // true;
|
|
548
|
+
* console.log(tree.has(10)); // false;
|
|
549
|
+
*
|
|
550
|
+
* // Get value by key
|
|
551
|
+
* console.log(tree.get(3)); // 'three';
|
|
552
|
+
* console.log(tree.get(7)); // 'seven';
|
|
553
|
+
* console.log(tree.get(100)); // undefined;
|
|
554
|
+
*
|
|
555
|
+
* // Get node structure
|
|
556
|
+
* const node = tree.getNode(5);
|
|
557
|
+
* console.log(node?.key); // 5;
|
|
558
|
+
* console.log(node?.value); // 'five';
|
|
986
559
|
*/
|
|
987
560
|
has(keyNodeEntryOrPredicate?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
988
561
|
/**
|
|
989
562
|
* Clears the tree of all nodes and values.
|
|
990
563
|
* @remarks Time O(N) if in Map mode (due to `_store.clear()`), O(1) otherwise. Space O(1)
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
* @example
|
|
1032
|
-
* // Remove all nodes
|
|
1033
|
-
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1034
|
-
* tree.clear();
|
|
1035
|
-
* console.log(tree.isEmpty()); // true;
|
|
564
|
+
* @example
|
|
565
|
+
* // Remove all nodes
|
|
566
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
567
|
+
* tree.clear();
|
|
568
|
+
* console.log(tree.isEmpty()); // true;
|
|
1036
569
|
*/
|
|
1037
570
|
clear(): void;
|
|
1038
571
|
/**
|
|
@@ -1040,49 +573,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1040
573
|
* @remarks Time O(1), Space O(1)
|
|
1041
574
|
*
|
|
1042
575
|
* @returns True if the tree has no nodes, false otherwise.
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
* @example
|
|
1084
|
-
* // Check empty
|
|
1085
|
-
* console.log(new BinaryTree().isEmpty()); // true;
|
|
576
|
+
* @example
|
|
577
|
+
* // Check empty
|
|
578
|
+
* console.log(new BinaryTree().isEmpty()); // true;
|
|
1086
579
|
*/
|
|
1087
580
|
isEmpty(): boolean;
|
|
1088
581
|
/**
|
|
@@ -1100,51 +593,11 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1100
593
|
* @param [startNode=this._root] - The node to start checking from.
|
|
1101
594
|
* @param [iterationType=this.iterationType] - The traversal method.
|
|
1102
595
|
* @returns True if it's a valid BST, false otherwise.
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
-
* @example
|
|
1144
|
-
* // Check BST property
|
|
1145
|
-
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1146
|
-
* // BinaryTree doesn't guarantee BST order
|
|
1147
|
-
* console.log(typeof tree.isBST()); // 'boolean';
|
|
596
|
+
* @example
|
|
597
|
+
* // Check BST property
|
|
598
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
599
|
+
* // BinaryTree doesn't guarantee BST order
|
|
600
|
+
* console.log(typeof tree.isBST()); // 'boolean';
|
|
1148
601
|
*/
|
|
1149
602
|
isBST(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
1150
603
|
/**
|
|
@@ -1154,53 +607,11 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1154
607
|
* @param dist - The node to find the depth of.
|
|
1155
608
|
* @param [startNode=this._root] - The node to measure depth from (defaults to root).
|
|
1156
609
|
* @returns The depth (0 if `dist` is `startNode`).
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
* @example
|
|
1200
|
-
* // Get depth of a node
|
|
1201
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1202
|
-
* const node = tree.getNode(4);
|
|
1203
|
-
* console.log(tree.getDepth(node!)); // 2;
|
|
610
|
+
* @example
|
|
611
|
+
* // Get depth of a node
|
|
612
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
613
|
+
* const node = tree.getNode(4);
|
|
614
|
+
* console.log(tree.getDepth(node!)); // 2;
|
|
1204
615
|
*/
|
|
1205
616
|
getDepth(dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): number;
|
|
1206
617
|
/**
|
|
@@ -1210,52 +621,10 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1210
621
|
* @param [startNode=this._root] - The node to start measuring from.
|
|
1211
622
|
* @param [iterationType=this.iterationType] - The traversal method.
|
|
1212
623
|
* @returns The height ( -1 for an empty tree, 0 for a single-node tree).
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
* @example
|
|
1256
|
-
* // Get tree height
|
|
1257
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1258
|
-
* console.log(tree.getHeight()); // 2;
|
|
624
|
+
* @example
|
|
625
|
+
* // Get tree height
|
|
626
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
627
|
+
* console.log(tree.getHeight()); // 2;
|
|
1259
628
|
*/
|
|
1260
629
|
getHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
|
|
1261
630
|
/**
|
|
@@ -1290,281 +659,79 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1290
659
|
*/
|
|
1291
660
|
getSuccessor(x?: K | BinaryTreeNode<K, V> | null): BinaryTreeNode<K, V> | null | undefined;
|
|
1292
661
|
/**
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
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
|
-
|
|
1335
|
-
|
|
1336
|
-
* @example
|
|
1337
|
-
* // Depth-first search traversal
|
|
1338
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1339
|
-
* const inOrder = tree.dfs(node => node.key, 'IN');
|
|
1340
|
-
* console.log(inOrder); // [4, 2, 5, 1, 3];
|
|
1341
|
-
*/
|
|
662
|
+
* Depth-first search traversal
|
|
663
|
+
* @example
|
|
664
|
+
* // Depth-first search traversal
|
|
665
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
666
|
+
* const inOrder = tree.dfs(node => node.key, 'IN');
|
|
667
|
+
* console.log(inOrder); // [4, 2, 5, 1, 3];
|
|
668
|
+
*/
|
|
1342
669
|
dfs(): (K | undefined)[];
|
|
1343
670
|
dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
1344
671
|
dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
1345
672
|
/**
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
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
|
-
* @example
|
|
1390
|
-
* // BinaryTree level-order traversal
|
|
1391
|
-
* const tree = new BinaryTree([
|
|
1392
|
-
* [1, 'one'],
|
|
1393
|
-
* [2, 'two'],
|
|
1394
|
-
* [3, 'three'],
|
|
1395
|
-
* [4, 'four'],
|
|
1396
|
-
* [5, 'five'],
|
|
1397
|
-
* [6, 'six'],
|
|
1398
|
-
* [7, 'seven']
|
|
1399
|
-
* ]);
|
|
1400
|
-
*
|
|
1401
|
-
* // Binary tree maintains level-order insertion
|
|
1402
|
-
* // Complete binary tree structure
|
|
1403
|
-
* console.log(tree.size); // 7;
|
|
1404
|
-
*
|
|
1405
|
-
* // Verify all keys are present
|
|
1406
|
-
* console.log(tree.has(1)); // true;
|
|
1407
|
-
* console.log(tree.has(4)); // true;
|
|
1408
|
-
* console.log(tree.has(7)); // true;
|
|
1409
|
-
*
|
|
1410
|
-
* // Iterate through tree
|
|
1411
|
-
* const keys: number[] = [];
|
|
1412
|
-
* for (const [key] of tree) {
|
|
1413
|
-
* keys.push(key);
|
|
1414
|
-
* }
|
|
1415
|
-
* console.log(keys.length); // 7;
|
|
1416
|
-
*/
|
|
673
|
+
* BinaryTree level-order traversal
|
|
674
|
+
* @example
|
|
675
|
+
* // BinaryTree level-order traversal
|
|
676
|
+
* const tree = new BinaryTree([
|
|
677
|
+
* [1, 'one'],
|
|
678
|
+
* [2, 'two'],
|
|
679
|
+
* [3, 'three'],
|
|
680
|
+
* [4, 'four'],
|
|
681
|
+
* [5, 'five'],
|
|
682
|
+
* [6, 'six'],
|
|
683
|
+
* [7, 'seven']
|
|
684
|
+
* ]);
|
|
685
|
+
*
|
|
686
|
+
* // Binary tree maintains level-order insertion
|
|
687
|
+
* // Complete binary tree structure
|
|
688
|
+
* console.log(tree.size); // 7;
|
|
689
|
+
*
|
|
690
|
+
* // Verify all keys are present
|
|
691
|
+
* console.log(tree.has(1)); // true;
|
|
692
|
+
* console.log(tree.has(4)); // true;
|
|
693
|
+
* console.log(tree.has(7)); // true;
|
|
694
|
+
*
|
|
695
|
+
* // Iterate through tree
|
|
696
|
+
* const keys: number[] = [];
|
|
697
|
+
* for (const [key] of tree) {
|
|
698
|
+
* keys.push(key);
|
|
699
|
+
* }
|
|
700
|
+
* console.log(keys.length); // 7;
|
|
701
|
+
*/
|
|
1417
702
|
bfs(): (K | undefined)[];
|
|
1418
703
|
bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
1419
704
|
bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
1420
705
|
/**
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
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
|
-
* @example
|
|
1463
|
-
* // Get leaf nodes
|
|
1464
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1465
|
-
* const leafKeys = tree.leaves(node => node.key);
|
|
1466
|
-
* console.log(leafKeys.length); // > 0;
|
|
1467
|
-
*/
|
|
706
|
+
* Get leaf nodes
|
|
707
|
+
* @example
|
|
708
|
+
* // Get leaf nodes
|
|
709
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
710
|
+
* const leafKeys = tree.leaves(node => node.key);
|
|
711
|
+
* console.log(leafKeys.length); // > 0;
|
|
712
|
+
*/
|
|
1468
713
|
leaves(): (K | undefined)[];
|
|
1469
714
|
leaves<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
1470
715
|
/**
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
* @example
|
|
1512
|
-
* // Level-order grouping
|
|
1513
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1514
|
-
* const levels = tree.listLevels(node => node.key);
|
|
1515
|
-
* console.log(levels[0]); // [1];
|
|
1516
|
-
* console.log(levels[1].sort()); // [2, 3];
|
|
1517
|
-
*/
|
|
716
|
+
* Level-order grouping
|
|
717
|
+
* @example
|
|
718
|
+
* // Level-order grouping
|
|
719
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
720
|
+
* const levels = tree.listLevels(node => node.key);
|
|
721
|
+
* console.log(levels[0]); // [1];
|
|
722
|
+
* console.log(levels[1].sort()); // [2, 3];
|
|
723
|
+
*/
|
|
1518
724
|
listLevels(): (K | undefined)[][];
|
|
1519
725
|
listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
1520
726
|
listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
1521
727
|
/**
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
* @example
|
|
1563
|
-
* // Morris traversal (O(1) space)
|
|
1564
|
-
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1565
|
-
* const result = tree.morris(node => node.key, 'IN');
|
|
1566
|
-
* console.log(result.length); // 3;
|
|
1567
|
-
*/
|
|
728
|
+
* Morris traversal (O(1) space)
|
|
729
|
+
* @example
|
|
730
|
+
* // Morris traversal (O(1) space)
|
|
731
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
732
|
+
* const result = tree.morris(node => node.key, 'IN');
|
|
733
|
+
* console.log(result.length); // 3;
|
|
734
|
+
*/
|
|
1568
735
|
morris(): (K | undefined)[];
|
|
1569
736
|
morris<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): ReturnType<C>[];
|
|
1570
737
|
/**
|
|
@@ -1572,52 +739,12 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1572
739
|
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `set`, and `set` is O(M)). Space O(N) for the new tree and the BFS queue.
|
|
1573
740
|
*
|
|
1574
741
|
* @returns A new, cloned instance of the tree.
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
* @example
|
|
1616
|
-
* // Deep copy
|
|
1617
|
-
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1618
|
-
* const copy = tree.clone();
|
|
1619
|
-
* copy.delete(1);
|
|
1620
|
-
* console.log(tree.has(1)); // true;
|
|
742
|
+
* @example
|
|
743
|
+
* // Deep copy
|
|
744
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
745
|
+
* const copy = tree.clone();
|
|
746
|
+
* copy.delete(1);
|
|
747
|
+
* console.log(tree.has(1)); // true;
|
|
1621
748
|
*/
|
|
1622
749
|
clone(): this;
|
|
1623
750
|
/**
|
|
@@ -1627,51 +754,11 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1627
754
|
* @param predicate - A function to test each [key, value] pair.
|
|
1628
755
|
* @param [thisArg] - `this` context for the predicate.
|
|
1629
756
|
* @returns A new, filtered tree.
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
* @example
|
|
1671
|
-
* // Filter nodes by condition
|
|
1672
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4]);
|
|
1673
|
-
* const result = tree.filter((_, key) => key > 2);
|
|
1674
|
-
* console.log(result.size); // 2;
|
|
757
|
+
* @example
|
|
758
|
+
* // Filter nodes by condition
|
|
759
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4]);
|
|
760
|
+
* const result = tree.filter((_, key) => key > 2);
|
|
761
|
+
* console.log(result.size); // 2;
|
|
1675
762
|
*/
|
|
1676
763
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
|
|
1677
764
|
/**
|
|
@@ -1685,51 +772,14 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1685
772
|
* @param [options] - Options for the new tree.
|
|
1686
773
|
* @param [thisArg] - `this` context for the callback.
|
|
1687
774
|
* @returns A new, mapped tree.
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
* @example
|
|
1729
|
-
* // Transform to new tree
|
|
1730
|
-
* const tree = new BinaryTree<number, number>([[1, 10], [2, 20]]);
|
|
1731
|
-
* const mapped = tree.map((v, key) => [key, (v ?? 0) + 1] as [number, number]);
|
|
1732
|
-
* console.log([...mapped.values()]); // contains 11;
|
|
775
|
+
* @example
|
|
776
|
+
* // Transform to new tree
|
|
777
|
+
* const tree = new BinaryTree<number, number>([
|
|
778
|
+
* [1, 10],
|
|
779
|
+
* [2, 20]
|
|
780
|
+
* ]);
|
|
781
|
+
* const mapped = tree.map((v, key) => [key, (v ?? 0) + 1] as [number, number]);
|
|
782
|
+
* console.log([...mapped.values()]); // contains 11;
|
|
1733
783
|
*/
|
|
1734
784
|
map<MK = K, MV = V, MR = any>(cb: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): BinaryTree<MK, MV, MR>;
|
|
1735
785
|
/**
|
|
@@ -1747,52 +797,21 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1747
797
|
*
|
|
1748
798
|
* @param [options] - Options to control the output.
|
|
1749
799
|
* @param [startNode=this._root] - The node to start printing from.
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
* @example
|
|
1791
|
-
* // Display tree
|
|
1792
|
-
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1793
|
-
* expect(() => tree.print()).not.toThrow();
|
|
800
|
+
* @example
|
|
801
|
+
* // Display tree
|
|
802
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
803
|
+
* expect(() => tree.print()).not.toThrow();
|
|
1794
804
|
*/
|
|
1795
805
|
print(options?: BinaryTreePrintOptions, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): void;
|
|
806
|
+
/**
|
|
807
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
808
|
+
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
809
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
810
|
+
*
|
|
811
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
812
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
813
|
+
*/
|
|
814
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
1796
815
|
protected _dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldVisitRight?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldVisitRoot?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldProcessRoot?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean): ReturnType<C>[];
|
|
1797
816
|
/**
|
|
1798
817
|
* (Protected) Gets the iterator for the tree (default in-order).
|
|
@@ -1862,7 +881,6 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1862
881
|
* @returns Layout information for this subtree.
|
|
1863
882
|
*/
|
|
1864
883
|
protected _displayAux(node: BinaryTreeNode<K, V> | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
1865
|
-
protected static _buildNodeDisplay(line: string, width: number, left: NodeDisplayLayout, right: NodeDisplayLayout): NodeDisplayLayout;
|
|
1866
884
|
/**
|
|
1867
885
|
* Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
1868
886
|
*/
|