data-structure-typed 1.53.7 → 1.53.9
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/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +1 -1
- package/dist/cjs/common/index.js +5 -0
- package/dist/cjs/common/index.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +12 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +19 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +76 -72
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +87 -52
- package/dist/cjs/data-structures/binary-tree/bst.js +111 -63
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js +1 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
- package/dist/cjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +92 -45
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +66 -40
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -1
- package/dist/cjs/data-structures/hash/hash-map.js +35 -5
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +20 -3
- package/dist/cjs/data-structures/heap/heap.js +31 -11
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +68 -21
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +44 -11
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +70 -26
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/cjs/data-structures/queue/deque.js +73 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/cjs/data-structures/queue/queue.js +51 -9
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/cjs/data-structures/stack/stack.js +39 -20
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +12 -13
- package/dist/cjs/data-structures/trie/trie.js +12 -13
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
- package/dist/mjs/common/index.js +5 -0
- package/dist/mjs/common/index.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/mjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +12 -8
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +19 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +76 -72
- package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +87 -52
- package/dist/mjs/data-structures/binary-tree/bst.js +127 -79
- package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js +1 -1
- package/dist/mjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
- package/dist/mjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +92 -45
- package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +64 -38
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.js +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -1
- package/dist/mjs/data-structures/hash/hash-map.js +35 -5
- package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/mjs/data-structures/heap/heap.d.ts +20 -3
- package/dist/mjs/data-structures/heap/heap.js +31 -11
- package/dist/mjs/data-structures/heap/heap.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +68 -21
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +44 -11
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +70 -26
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +37 -8
- package/dist/mjs/data-structures/queue/deque.js +73 -29
- package/dist/mjs/data-structures/queue/deque.js.map +1 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +41 -1
- package/dist/mjs/data-structures/queue/queue.js +51 -9
- package/dist/mjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +27 -10
- package/dist/mjs/data-structures/stack/stack.js +39 -20
- package/dist/mjs/data-structures/stack/stack.js.map +1 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +12 -13
- package/dist/mjs/data-structures/trie/trie.js +12 -13
- package/dist/mjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
- package/dist/umd/data-structure-typed.js +722 -356
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/common/index.ts +7 -1
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +82 -55
- package/src/data-structures/binary-tree/avl-tree.ts +32 -15
- package/src/data-structures/binary-tree/binary-tree.ts +89 -84
- package/src/data-structures/binary-tree/bst.ts +149 -97
- package/src/data-structures/binary-tree/index.ts +1 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +105 -55
- package/src/data-structures/binary-tree/tree-multi-map.ts +81 -51
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +37 -7
- package/src/data-structures/heap/heap.ts +33 -10
- package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
- package/src/data-structures/linked-list/singly-linked-list.ts +77 -27
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +8 -3
- package/src/interfaces/binary-tree.ts +3 -13
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/bst.ts +3 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
- package/test/integration/index.html +3 -3
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +45 -45
- package/test/unit/data-structures/binary-tree/bst.test.ts +90 -96
- package/test/unit/data-structures/binary-tree/data/cost-of-living-by-country.ts +259 -0
- package/test/unit/data-structures/binary-tree/overall.test.ts +2 -0
- package/test/unit/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +67 -92
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +10 -10
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/hash/hash-map.test.ts +12 -12
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +0 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js.map +0 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type {
|
|
9
|
+
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, EntryCallback } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
12
12
|
/**
|
|
@@ -40,7 +40,7 @@ export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V
|
|
|
40
40
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
41
41
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
42
42
|
*/
|
|
43
|
-
export declare class AVLTree<K = any, V = any, R = object, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V
|
|
43
|
+
export declare class AVLTree<K = any, V = any, R = object, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>> extends BST<K, V, R, NODE> implements IBinaryTree<K, V, R, NODE> {
|
|
44
44
|
/**
|
|
45
45
|
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
|
|
46
46
|
* entries, or raw elements.
|
|
@@ -64,13 +64,16 @@ export declare class AVLTree<K = any, V = any, R = object, NODE extends AVLTreeN
|
|
|
64
64
|
*/
|
|
65
65
|
createNode(key: K, value?: V): NODE;
|
|
66
66
|
/**
|
|
67
|
-
* The function
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
67
|
+
* The function `createTree` in TypeScript overrides the default AVLTree creation with the provided
|
|
68
|
+
* options.
|
|
69
|
+
* @param [options] - The `options` parameter in the `createTree` function is an object that contains
|
|
70
|
+
* configuration options for creating an AVL tree. These options can include properties such as
|
|
71
|
+
* `iterationType`, `isMapMode`, `specifyComparable`, `toEntryFn`, and `isReverse`. The function
|
|
72
|
+
* creates a
|
|
73
|
+
* @returns An AVLTree object is being returned with the specified options and properties inherited
|
|
74
|
+
* from the current object.
|
|
72
75
|
*/
|
|
73
|
-
createTree(options?: AVLTreeOptions<K, V, R>):
|
|
76
|
+
createTree(options?: AVLTreeOptions<K, V, R>): AVLTree<K, V, R, NODE>;
|
|
74
77
|
/**
|
|
75
78
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
76
79
|
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
@@ -107,6 +110,7 @@ export declare class AVLTree<K = any, V = any, R = object, NODE extends AVLTreeN
|
|
|
107
110
|
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
|
|
108
111
|
*/
|
|
109
112
|
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
|
|
113
|
+
map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: AVLTreeOptions<MK, MV, MR>, thisArg?: any): AVLTree<MK, MV, MR, AVLTreeNode<MK, MV, AVLTreeNodeNested<MK, MV>>>;
|
|
110
114
|
/**
|
|
111
115
|
* Time Complexity: O(1)
|
|
112
116
|
* Space Complexity: O(1)
|
|
@@ -75,17 +75,21 @@ export class AVLTree extends BST {
|
|
|
75
75
|
return new AVLTreeNode(key, this._isMapMode ? undefined : value);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* The function
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
78
|
+
* The function `createTree` in TypeScript overrides the default AVLTree creation with the provided
|
|
79
|
+
* options.
|
|
80
|
+
* @param [options] - The `options` parameter in the `createTree` function is an object that contains
|
|
81
|
+
* configuration options for creating an AVL tree. These options can include properties such as
|
|
82
|
+
* `iterationType`, `isMapMode`, `specifyComparable`, `toEntryFn`, and `isReverse`. The function
|
|
83
|
+
* creates a
|
|
84
|
+
* @returns An AVLTree object is being returned with the specified options and properties inherited
|
|
85
|
+
* from the current object.
|
|
83
86
|
*/
|
|
87
|
+
// @ts-ignore
|
|
84
88
|
createTree(options) {
|
|
85
89
|
return new AVLTree([], {
|
|
86
90
|
iterationType: this.iterationType,
|
|
87
91
|
isMapMode: this._isMapMode,
|
|
88
|
-
|
|
92
|
+
specifyComparable: this._specifyComparable,
|
|
89
93
|
toEntryFn: this._toEntryFn,
|
|
90
94
|
isReverse: this._isReverse,
|
|
91
95
|
...options
|
|
@@ -144,6 +148,15 @@ export class AVLTree extends BST {
|
|
|
144
148
|
}
|
|
145
149
|
return deletedResults;
|
|
146
150
|
}
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
map(callback, options, thisArg) {
|
|
153
|
+
const newTree = new AVLTree([], options);
|
|
154
|
+
let index = 0;
|
|
155
|
+
for (const [key, value] of this) {
|
|
156
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
157
|
+
}
|
|
158
|
+
return newTree;
|
|
159
|
+
}
|
|
147
160
|
/**
|
|
148
161
|
* Time Complexity: O(1)
|
|
149
162
|
* Space Complexity: O(1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAWrC,MAAM,OAAO,WAIX,SAAQ,OAAmB;IAC3B;;;;;;;OAOG;IACH,YAAY,GAAM,EAAE,KAAS;QAC3B,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAES,OAAO,CAAS;IAE1B;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM,CAAC,KAAa;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"avl-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/avl-tree.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAWrC,MAAM,OAAO,WAIX,SAAQ,OAAmB;IAC3B;;;;;;;OAOG;IACH,YAAY,GAAM,EAAE,KAAS;QAC3B,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAES,OAAO,CAAS;IAE1B;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM,CAAC,KAAa;QACtB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,M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CAAC,KAAK,EAAE,CAAC;4BACjB,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gCACtC,2HAA2H;gCAC3H,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;4BACrB,CAAC;iCAAM,CAAC;gCACN,+HAA+H;gCAC/H,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;4BACrB,CAAC;wBACH,CAAC;gBACL,CAAC;gBACD,oRAAoR;YACtR,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;OAYG;IACgB,YAAY,CAAC,OAAa,EAAE,OAAa;QAC1D,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAEhC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { BinaryTreeDeleteResult,
|
|
8
|
+
import { BinaryTreeDeleteResult, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, BTNRep, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate, OptNodeOrNull, ToEntryFn } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
11
|
import { Range } from '../../common';
|
|
@@ -34,7 +34,7 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
34
34
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
35
35
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
36
36
|
*/
|
|
37
|
-
export declare class BinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V
|
|
37
|
+
export declare class BinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE> {
|
|
38
38
|
iterationType: IterationType;
|
|
39
39
|
/**
|
|
40
40
|
* The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
|
|
@@ -59,6 +59,9 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
59
59
|
protected _toEntryFn?: ToEntryFn<K, V, R>;
|
|
60
60
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
61
61
|
/**
|
|
62
|
+
* Time Complexity: O(1)
|
|
63
|
+
* Space Complexity: O(1)
|
|
64
|
+
*
|
|
62
65
|
* The function creates a new binary tree node with a specified key and optional value.
|
|
63
66
|
* @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
|
|
64
67
|
* @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
|
|
@@ -69,30 +72,20 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
69
72
|
*/
|
|
70
73
|
createNode(key: K, value?: V): NODE;
|
|
71
74
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* `
|
|
76
|
-
* of
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
85
|
-
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
86
|
-
* node, an entry
|
|
87
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
88
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
89
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
90
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
91
|
-
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
92
|
-
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
93
|
-
* value.
|
|
75
|
+
* Time Complexity: O(1)
|
|
76
|
+
* Space Complexity: O(1)
|
|
77
|
+
*
|
|
78
|
+
* The `createTree` function creates a new binary tree based on the provided options.
|
|
79
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
80
|
+
* `BinaryTreeOptions<K, V, R>`. This type likely contains configuration options for creating a
|
|
81
|
+
* binary tree, such as the iteration type, whether the tree is in map mode, and functions for
|
|
82
|
+
* converting entries.
|
|
83
|
+
* @returns The `createTree` method is returning an instance of the `BinaryTree` class with the
|
|
84
|
+
* provided options. The method is creating a new `BinaryTree` object with an empty array as the
|
|
85
|
+
* initial data, and then setting various options such as `iterationType`, `isMapMode`, and
|
|
86
|
+
* `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
|
|
94
87
|
*/
|
|
95
|
-
|
|
88
|
+
createTree(options?: BinaryTreeOptions<K, V, R>): typeof this;
|
|
96
89
|
/**
|
|
97
90
|
* Time Complexity: O(n)
|
|
98
91
|
* Space Complexity: O(log n)
|
|
@@ -238,7 +231,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
238
231
|
* elements from the other tree.
|
|
239
232
|
* @param anotherTree - `BinaryTree<K, V, R, NODE, TREE>`
|
|
240
233
|
*/
|
|
241
|
-
merge(anotherTree:
|
|
234
|
+
merge(anotherTree: this): void;
|
|
242
235
|
/**
|
|
243
236
|
* Time Complexity: O(k * n)
|
|
244
237
|
* Space Complexity: O(1)
|
|
@@ -638,7 +631,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
638
631
|
* original tree using breadth-first search (bfs), and adds the nodes to the new tree. If a node in
|
|
639
632
|
* the original tree is null, a null node is added to the cloned tree. If a node
|
|
640
633
|
*/
|
|
641
|
-
clone():
|
|
634
|
+
clone(): this;
|
|
642
635
|
/**
|
|
643
636
|
* Time Complexity: O(n)
|
|
644
637
|
* Space Complexity: O(n)
|
|
@@ -655,23 +648,27 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
655
648
|
* @returns The `filter` method is returning a new tree that contains entries that pass the provided
|
|
656
649
|
* predicate function.
|
|
657
650
|
*/
|
|
658
|
-
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any):
|
|
651
|
+
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): this;
|
|
659
652
|
/**
|
|
660
653
|
* Time Complexity: O(n)
|
|
661
654
|
* Space Complexity: O(n)
|
|
662
655
|
*
|
|
663
|
-
* The `map` function
|
|
664
|
-
*
|
|
665
|
-
* @param callback -
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
|
|
674
|
-
|
|
656
|
+
* The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
|
|
657
|
+
* entry in the original BinaryTree.
|
|
658
|
+
* @param callback - A function that will be called for each entry in the current binary tree. It
|
|
659
|
+
* takes the key, value (which can be undefined), and an array containing the mapped key and value as
|
|
660
|
+
* arguments.
|
|
661
|
+
* @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
|
|
662
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
|
|
663
|
+
* tree being created during the mapping process. These options could include things like custom
|
|
664
|
+
* comparators, initial
|
|
665
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
|
|
666
|
+
* of `this` when executing the `callback` function. It allows you to set the context (value of
|
|
667
|
+
* `this`) within the callback function. If `thisArg` is provided, it will be passed
|
|
668
|
+
* @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
|
|
669
|
+
* the result of applying the provided `callback` function to each entry in the original tree.
|
|
670
|
+
*/
|
|
671
|
+
map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BinaryTreeOptions<MK, MV, MR>, thisArg?: any): BinaryTree<MK, MV, MR, BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>>;
|
|
675
672
|
/**
|
|
676
673
|
* Time Complexity: O(n)
|
|
677
674
|
* Space Complexity: O(n)
|
|
@@ -707,6 +704,22 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
707
704
|
* provided, the default value is set to
|
|
708
705
|
*/
|
|
709
706
|
print(options?: BinaryTreePrintOptions, startNode?: BTNRep<K, V, NODE> | R): void;
|
|
707
|
+
/**
|
|
708
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
709
|
+
* or returns null.
|
|
710
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
711
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
712
|
+
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
713
|
+
* node, an entry
|
|
714
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
715
|
+
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
716
|
+
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
717
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
718
|
+
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
719
|
+
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
720
|
+
* value.
|
|
721
|
+
*/
|
|
722
|
+
protected _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNodeOrNull<NODE>, V | undefined];
|
|
710
723
|
/**
|
|
711
724
|
* Time complexity: O(n)
|
|
712
725
|
* Space complexity: O(n)
|
|
@@ -115,6 +115,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
115
115
|
return this._toEntryFn;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
+
* Time Complexity: O(1)
|
|
119
|
+
* Space Complexity: O(1)
|
|
120
|
+
*
|
|
118
121
|
* The function creates a new binary tree node with a specified key and optional value.
|
|
119
122
|
* @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
|
|
120
123
|
* @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
|
|
@@ -127,12 +130,18 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
127
130
|
return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
|
|
128
131
|
}
|
|
129
132
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* `
|
|
134
|
-
* of
|
|
135
|
-
*
|
|
133
|
+
* Time Complexity: O(1)
|
|
134
|
+
* Space Complexity: O(1)
|
|
135
|
+
*
|
|
136
|
+
* The `createTree` function creates a new binary tree based on the provided options.
|
|
137
|
+
* @param [options] - The `options` parameter in the `createTree` method is of type
|
|
138
|
+
* `BinaryTreeOptions<K, V, R>`. This type likely contains configuration options for creating a
|
|
139
|
+
* binary tree, such as the iteration type, whether the tree is in map mode, and functions for
|
|
140
|
+
* converting entries.
|
|
141
|
+
* @returns The `createTree` method is returning an instance of the `BinaryTree` class with the
|
|
142
|
+
* provided options. The method is creating a new `BinaryTree` object with an empty array as the
|
|
143
|
+
* initial data, and then setting various options such as `iterationType`, `isMapMode`, and
|
|
144
|
+
* `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
|
|
136
145
|
*/
|
|
137
146
|
createTree(options) {
|
|
138
147
|
return new BinaryTree([], {
|
|
@@ -142,47 +151,6 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
142
151
|
...options
|
|
143
152
|
});
|
|
144
153
|
}
|
|
145
|
-
/**
|
|
146
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
147
|
-
* or returns null.
|
|
148
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
149
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
150
|
-
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
151
|
-
* node, an entry
|
|
152
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
153
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
154
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
155
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
156
|
-
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
157
|
-
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
158
|
-
* value.
|
|
159
|
-
*/
|
|
160
|
-
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
161
|
-
if (keyNodeEntryOrRaw === undefined)
|
|
162
|
-
return [undefined, undefined];
|
|
163
|
-
if (keyNodeEntryOrRaw === null)
|
|
164
|
-
return [null, undefined];
|
|
165
|
-
if (this.isNode(keyNodeEntryOrRaw))
|
|
166
|
-
return [keyNodeEntryOrRaw, value];
|
|
167
|
-
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
168
|
-
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
169
|
-
if (key === undefined)
|
|
170
|
-
return [undefined, undefined];
|
|
171
|
-
else if (key === null)
|
|
172
|
-
return [null, undefined];
|
|
173
|
-
const finalValue = value ?? entryValue;
|
|
174
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
175
|
-
}
|
|
176
|
-
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
177
|
-
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
178
|
-
const finalValue = value ?? entryValue;
|
|
179
|
-
if (this.isKey(key))
|
|
180
|
-
return [this.createNode(key, finalValue), finalValue];
|
|
181
|
-
}
|
|
182
|
-
if (this.isKey(keyNodeEntryOrRaw))
|
|
183
|
-
return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
184
|
-
return [undefined, undefined];
|
|
185
|
-
}
|
|
186
154
|
/**
|
|
187
155
|
* Time Complexity: O(n)
|
|
188
156
|
* Space Complexity: O(log n)
|
|
@@ -353,7 +321,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
353
321
|
* key was found and the node was replaced instead of inserted.
|
|
354
322
|
*/
|
|
355
323
|
add(keyNodeEntryOrRaw, value) {
|
|
356
|
-
const [newNode, newValue] = this.
|
|
324
|
+
const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
|
|
357
325
|
if (newNode === undefined)
|
|
358
326
|
return false;
|
|
359
327
|
// If the tree is empty, directly set the new node as the root node
|
|
@@ -1504,7 +1472,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1504
1472
|
const newTree = this.createTree();
|
|
1505
1473
|
let index = 0;
|
|
1506
1474
|
for (const [key, value] of this) {
|
|
1507
|
-
if (predicate.call(thisArg,
|
|
1475
|
+
if (predicate.call(thisArg, key, value, index++, this)) {
|
|
1508
1476
|
newTree.add([key, value]);
|
|
1509
1477
|
}
|
|
1510
1478
|
}
|
|
@@ -1514,34 +1482,29 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1514
1482
|
* Time Complexity: O(n)
|
|
1515
1483
|
* Space Complexity: O(n)
|
|
1516
1484
|
*
|
|
1517
|
-
* The `map` function
|
|
1518
|
-
*
|
|
1519
|
-
* @param callback -
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1485
|
+
* The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
|
|
1486
|
+
* entry in the original BinaryTree.
|
|
1487
|
+
* @param callback - A function that will be called for each entry in the current binary tree. It
|
|
1488
|
+
* takes the key, value (which can be undefined), and an array containing the mapped key and value as
|
|
1489
|
+
* arguments.
|
|
1490
|
+
* @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
|
|
1491
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
|
|
1492
|
+
* tree being created during the mapping process. These options could include things like custom
|
|
1493
|
+
* comparators, initial
|
|
1494
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
|
|
1495
|
+
* of `this` when executing the `callback` function. It allows you to set the context (value of
|
|
1496
|
+
* `this`) within the callback function. If `thisArg` is provided, it will be passed
|
|
1497
|
+
* @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
|
|
1498
|
+
* the result of applying the provided `callback` function to each entry in the original tree.
|
|
1527
1499
|
*/
|
|
1528
|
-
map(callback, thisArg) {
|
|
1529
|
-
const newTree =
|
|
1500
|
+
map(callback, options, thisArg) {
|
|
1501
|
+
const newTree = new BinaryTree([], options);
|
|
1530
1502
|
let index = 0;
|
|
1531
1503
|
for (const [key, value] of this) {
|
|
1532
|
-
newTree.add(
|
|
1504
|
+
newTree.add(callback.call(thisArg, key, value, index++, this));
|
|
1533
1505
|
}
|
|
1534
1506
|
return newTree;
|
|
1535
1507
|
}
|
|
1536
|
-
// // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
|
|
1537
|
-
// // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
|
|
1538
|
-
// // const newTree = this.createTree();
|
|
1539
|
-
// // for (const [key, value] of this) {
|
|
1540
|
-
// // newTree.add(key, callback([key, value], this));
|
|
1541
|
-
// // }
|
|
1542
|
-
// // return newTree;
|
|
1543
|
-
// // }
|
|
1544
|
-
//
|
|
1545
1508
|
/**
|
|
1546
1509
|
* Time Complexity: O(n)
|
|
1547
1510
|
* Space Complexity: O(n)
|
|
@@ -1573,7 +1536,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1573
1536
|
if (opts.isShowRedBlackNIL)
|
|
1574
1537
|
output += `S for Sentinel Node(NIL)\n`;
|
|
1575
1538
|
const display = (root) => {
|
|
1576
|
-
const [lines, ,
|
|
1539
|
+
const [lines, ,] = this._displayAux(root, opts);
|
|
1577
1540
|
let paragraph = '';
|
|
1578
1541
|
for (const line of lines) {
|
|
1579
1542
|
paragraph += line + '\n';
|
|
@@ -1601,6 +1564,47 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1601
1564
|
print(options, startNode = this._root) {
|
|
1602
1565
|
console.log(this.toVisual(startNode, options));
|
|
1603
1566
|
}
|
|
1567
|
+
/**
|
|
1568
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
1569
|
+
* or returns null.
|
|
1570
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
1571
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
1572
|
+
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
1573
|
+
* node, an entry
|
|
1574
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
1575
|
+
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
1576
|
+
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
1577
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
1578
|
+
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
1579
|
+
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
1580
|
+
* value.
|
|
1581
|
+
*/
|
|
1582
|
+
_keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
|
|
1583
|
+
if (keyNodeEntryOrRaw === undefined)
|
|
1584
|
+
return [undefined, undefined];
|
|
1585
|
+
if (keyNodeEntryOrRaw === null)
|
|
1586
|
+
return [null, undefined];
|
|
1587
|
+
if (this.isNode(keyNodeEntryOrRaw))
|
|
1588
|
+
return [keyNodeEntryOrRaw, value];
|
|
1589
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
1590
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
1591
|
+
if (key === undefined)
|
|
1592
|
+
return [undefined, undefined];
|
|
1593
|
+
else if (key === null)
|
|
1594
|
+
return [null, undefined];
|
|
1595
|
+
const finalValue = value ?? entryValue;
|
|
1596
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
1597
|
+
}
|
|
1598
|
+
if (this.isRaw(keyNodeEntryOrRaw)) {
|
|
1599
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1600
|
+
const finalValue = value ?? entryValue;
|
|
1601
|
+
if (this.isKey(key))
|
|
1602
|
+
return [this.createNode(key, finalValue), finalValue];
|
|
1603
|
+
}
|
|
1604
|
+
if (this.isKey(keyNodeEntryOrRaw))
|
|
1605
|
+
return [this.createNode(keyNodeEntryOrRaw, value), value];
|
|
1606
|
+
return [undefined, undefined];
|
|
1607
|
+
}
|
|
1604
1608
|
/**
|
|
1605
1609
|
* Time complexity: O(n)
|
|
1606
1610
|
* Space complexity: O(n)
|