data-structure-typed 1.52.0 → 1.52.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/CHANGELOG.md +1 -1
- package/README.md +141 -54
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +162 -162
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- 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 +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- 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 +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -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 +97 -97
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/cjs/data-structures/queue/deque.js +16 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/cjs/data-structures/queue/queue.js +32 -7
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +1 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/cjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/cjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/cjs/utils/number.js +1 -2
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/mjs/data-structures/queue/deque.js +16 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/mjs/data-structures/queue/queue.js +32 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +1 -22
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/umd/data-structure-typed.js +137 -95
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +8 -8
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -24
- package/src/data-structures/binary-tree/avl-tree.ts +20 -19
- package/src/data-structures/binary-tree/binary-tree.ts +162 -157
- package/src/data-structures/binary-tree/bst.ts +54 -50
- package/src/data-structures/binary-tree/rb-tree.ts +18 -17
- package/src/data-structures/binary-tree/tree-multi-map.ts +18 -17
- package/src/data-structures/graph/abstract-graph.ts +15 -14
- package/src/data-structures/graph/directed-graph.ts +9 -7
- package/src/data-structures/graph/undirected-graph.ts +7 -6
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/queue/deque.ts +18 -4
- package/src/data-structures/queue/queue.ts +38 -8
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/graph/abstract-graph.ts +8 -8
- package/src/types/data-structures/queue/deque.ts +4 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/utils/utils.ts +4 -4
- package/test/integration/bst.test.ts +4 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +12 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +6 -2
- package/test/performance/reportor.ts +23 -8
- package/test/performance/types/reportor.ts +5 -1
- package/test/types/utils/json2html.ts +5 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +6 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +8 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +36 -11
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +18 -5
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +2 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +27 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +6 -2
- package/test/unit/data-structures/heap/heap.test.ts +64 -12
- package/test/unit/data-structures/heap/max-heap.test.ts +10 -3
- package/test/unit/data-structures/heap/min-heap.test.ts +3 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +3 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +6 -2
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +22 -6
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +12 -4
- package/test/unit/data-structures/queue/deque.test.ts +31 -6
- package/test/unit/data-structures/queue/queue.test.ts +14 -1
- package/test/unit/data-structures/trie/trie.test.ts +3 -1
- package/test/unit/unrestricted-interconversion.test.ts +3 -1
- package/test/utils/big-o.ts +3 -1
- package/test/utils/json2html.ts +2 -6
|
@@ -18,7 +18,7 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* The function sets the left child of a node and updates the parent reference of the child.
|
|
21
|
-
* @param {NODE
|
|
21
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
|
|
22
22
|
* instance of the `NODE` class or `undefined`.
|
|
23
23
|
*/
|
|
24
24
|
set left(v) {
|
|
@@ -38,7 +38,7 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* The function sets the right child of a node and updates the parent reference of the child.
|
|
41
|
-
* @param {NODE
|
|
41
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
|
|
42
42
|
* `NODE` object or `undefined`.
|
|
43
43
|
*/
|
|
44
44
|
set right(v) {
|
|
@@ -111,8 +111,8 @@ export class BST extends BinaryTree {
|
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
114
|
-
* @param {R |
|
|
115
|
-
* type R or
|
|
114
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
115
|
+
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
116
116
|
* element.
|
|
117
117
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
118
118
|
* value associated with a key in a key-value pair.
|
|
@@ -127,7 +127,7 @@ export class BST extends BinaryTree {
|
|
|
127
127
|
*
|
|
128
128
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
129
129
|
* it doesn't exist.
|
|
130
|
-
* @param {R |
|
|
130
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
131
131
|
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
132
132
|
* entry, or raw element that needs to be ensured in the tree.
|
|
133
133
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -141,8 +141,8 @@ export class BST extends BinaryTree {
|
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* The function checks if the input is an instance of the BSTNode class.
|
|
144
|
-
* @param {R |
|
|
145
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
144
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
145
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
146
146
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
147
147
|
* an instance of the `BSTNode` class.
|
|
148
148
|
*/
|
|
@@ -154,8 +154,8 @@ export class BST extends BinaryTree {
|
|
|
154
154
|
* Space Complexity: O(1)
|
|
155
155
|
*
|
|
156
156
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
157
|
-
* @param {R |
|
|
158
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
157
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
158
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
159
159
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
160
160
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
161
161
|
* @returns a boolean value.
|
|
@@ -319,7 +319,7 @@ export class BST extends BinaryTree {
|
|
|
319
319
|
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
320
320
|
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
321
321
|
* false, all matching nodes will be returned. The default value is false.
|
|
322
|
-
* @param {R |
|
|
322
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
323
323
|
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
324
324
|
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
325
325
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -451,7 +451,7 @@ export class BST extends BinaryTree {
|
|
|
451
451
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
452
452
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
453
453
|
* take one of the following values:
|
|
454
|
-
* @param {R |
|
|
454
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
455
455
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
456
456
|
* node entry. If not specified, the default value is the root of the tree.
|
|
457
457
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -475,7 +475,7 @@ export class BST extends BinaryTree {
|
|
|
475
475
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
476
476
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
477
477
|
* node being visited, and it can return a value of any type.
|
|
478
|
-
* @param {R |
|
|
478
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
479
479
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
480
480
|
* object. If no value is provided, the default value is the root of the tree.
|
|
481
481
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -499,7 +499,7 @@ export class BST extends BinaryTree {
|
|
|
499
499
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
500
500
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
501
501
|
* tree during the iteration process.
|
|
502
|
-
* @param {R |
|
|
502
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
503
503
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
504
504
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
505
505
|
* value is provided, the root of
|
|
@@ -527,7 +527,7 @@ export class BST extends BinaryTree {
|
|
|
527
527
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
528
528
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
529
529
|
* 0, or 1, where:
|
|
530
|
-
* @param {R |
|
|
530
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
531
531
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
532
532
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
533
533
|
* `targetNode` is provided,
|
|
@@ -671,8 +671,8 @@ export class BST extends BinaryTree {
|
|
|
671
671
|
if (!node.right || last === node.right) {
|
|
672
672
|
node = stack.pop();
|
|
673
673
|
if (node) {
|
|
674
|
-
const left = node.left ? depths.get(node.left) ?? -1 : -1;
|
|
675
|
-
const right = node.right ? depths.get(node.right) ?? -1 : -1;
|
|
674
|
+
const left = node.left ? (depths.get(node.left) ?? -1) : -1;
|
|
675
|
+
const right = node.right ? (depths.get(node.right) ?? -1) : -1;
|
|
676
676
|
if (Math.abs(left - right) > 1)
|
|
677
677
|
return false;
|
|
678
678
|
depths.set(node, 1 + Math.max(left, right));
|
|
@@ -712,7 +712,7 @@ export class BST extends BinaryTree {
|
|
|
712
712
|
/**
|
|
713
713
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
714
714
|
* root.
|
|
715
|
-
* @param {NODE
|
|
715
|
+
* @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
|
|
716
716
|
*/
|
|
717
717
|
_setRoot(v) {
|
|
718
718
|
if (v) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult, BTNCallback,
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNCallback, BTNKeyOrNodeOrEntry, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
2
|
import { BTNEntry } from '../../types';
|
|
3
3
|
import { BST, BSTNode } from './bst';
|
|
4
4
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -38,7 +38,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
38
38
|
* configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
|
|
39
39
|
* depend on the implementation
|
|
40
40
|
*/
|
|
41
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R |
|
|
41
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
|
|
42
42
|
protected _root: NODE | undefined;
|
|
43
43
|
/**
|
|
44
44
|
* The function returns the root node of a tree or undefined if there is no root.
|
|
@@ -76,12 +76,12 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
76
76
|
* Space Complexity: O(1)
|
|
77
77
|
*
|
|
78
78
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
79
|
-
* @param {R |
|
|
80
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
79
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
80
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
81
81
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
82
82
|
* an instance of the `RedBlackTreeNode` class.
|
|
83
83
|
*/
|
|
84
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
84
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
85
85
|
/**
|
|
86
86
|
* Time Complexity: O(1)
|
|
87
87
|
* Space Complexity: O(1)
|
|
@@ -104,8 +104,8 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
104
104
|
*
|
|
105
105
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
106
106
|
* added.
|
|
107
|
-
* @param {R |
|
|
108
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
107
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
109
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
110
110
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
111
111
|
* structure.
|
|
@@ -113,7 +113,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
113
113
|
* the method returns true. If the node already exists and its value is updated, the method also
|
|
114
114
|
* returns true. If the node cannot be added or updated, the method returns false.
|
|
115
115
|
*/
|
|
116
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
116
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
117
117
|
/**
|
|
118
118
|
* Time Complexity: O(log n)
|
|
119
119
|
* Space Complexity: O(1)
|
|
@@ -95,8 +95,8 @@ export class RedBlackTree extends BST {
|
|
|
95
95
|
* Space Complexity: O(1)
|
|
96
96
|
*
|
|
97
97
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
98
|
-
* @param {R |
|
|
99
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
98
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
99
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
100
100
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
101
101
|
* an instance of the `RedBlackTreeNode` class.
|
|
102
102
|
*/
|
|
@@ -114,11 +114,11 @@ export class RedBlackTree extends BST {
|
|
|
114
114
|
// *
|
|
115
115
|
// * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
|
|
116
116
|
// * valid, otherwise it returns undefined.
|
|
117
|
-
// * @param {
|
|
117
|
+
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
|
|
118
118
|
// * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
|
|
119
119
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
120
120
|
// */
|
|
121
|
-
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
121
|
+
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
|
|
122
122
|
//
|
|
123
123
|
// if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
|
|
124
124
|
// if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
@@ -163,8 +163,8 @@ export class RedBlackTree extends BST {
|
|
|
163
163
|
*
|
|
164
164
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
165
165
|
* added.
|
|
166
|
-
* @param {R |
|
|
167
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
166
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
167
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
168
168
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
169
169
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
170
170
|
* structure.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { BTNEntry } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
@@ -46,7 +46,7 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
46
46
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
47
47
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
48
48
|
*/
|
|
49
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: TreeMultiMapOptions<K, V, R>);
|
|
50
50
|
protected _count: number;
|
|
51
51
|
/**
|
|
52
52
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -92,8 +92,8 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
92
92
|
/**
|
|
93
93
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
94
94
|
* node based on the input.
|
|
95
|
-
* @param {R |
|
|
96
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
95
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
96
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
97
97
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
98
98
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
99
99
|
* an existing node.
|
|
@@ -101,15 +101,15 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
101
101
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
102
102
|
* @returns either a NODE object or undefined.
|
|
103
103
|
*/
|
|
104
|
-
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
104
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
105
105
|
/**
|
|
106
106
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
107
|
-
* @param {R |
|
|
108
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
107
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
109
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
110
110
|
* an instance of the `TreeMultiMapNode` class.
|
|
111
111
|
*/
|
|
112
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
112
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
113
113
|
/**
|
|
114
114
|
* Time Complexity: O(log n)
|
|
115
115
|
* Space Complexity: O(1)
|
|
@@ -120,7 +120,7 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
120
120
|
*
|
|
121
121
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
122
122
|
* the count and returning a boolean indicating success.
|
|
123
|
-
* @param {R |
|
|
123
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
124
124
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
125
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
126
126
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -130,7 +130,7 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
|
|
|
130
130
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
131
131
|
* was successful, and false otherwise.
|
|
132
132
|
*/
|
|
133
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
133
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
134
134
|
/**
|
|
135
135
|
* Time Complexity: O(log n)
|
|
136
136
|
* Space Complexity: O(1)
|
|
@@ -107,8 +107,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
107
107
|
/**
|
|
108
108
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
109
109
|
* node based on the input.
|
|
110
|
-
* @param {R |
|
|
111
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
110
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
111
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
112
112
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
113
113
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
114
114
|
* an existing node.
|
|
@@ -139,8 +139,8 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
142
|
-
* @param {R |
|
|
143
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
142
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
143
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
144
144
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
145
145
|
* an instance of the `TreeMultiMapNode` class.
|
|
146
146
|
*/
|
|
@@ -157,7 +157,7 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
157
157
|
*
|
|
158
158
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
159
159
|
* the count and returning a boolean indicating success.
|
|
160
|
-
* @param {R |
|
|
160
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
161
161
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
162
162
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
163
163
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -217,7 +217,8 @@ export class DirectedGraph extends AbstractGraph {
|
|
|
217
217
|
if (vertex) {
|
|
218
218
|
const neighbors = this.getNeighbors(vertex);
|
|
219
219
|
for (const neighbor of neighbors) {
|
|
220
|
-
this._inEdgeMap.delete(neighbor);
|
|
220
|
+
// this._inEdgeMap.delete(neighbor);
|
|
221
|
+
this.deleteEdgeSrcToDest(vertex, neighbor);
|
|
221
222
|
}
|
|
222
223
|
this._outEdgeMap.delete(vertex);
|
|
223
224
|
this._inEdgeMap.delete(vertex);
|
|
@@ -34,6 +34,13 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
|
|
|
34
34
|
* @return The size of the bucket
|
|
35
35
|
*/
|
|
36
36
|
get bucketSize(): number;
|
|
37
|
+
protected _maxLen: number;
|
|
38
|
+
/**
|
|
39
|
+
* The maxLen function returns the max length of the deque.
|
|
40
|
+
*
|
|
41
|
+
* @return The max length of the deque
|
|
42
|
+
*/
|
|
43
|
+
get maxLen(): number;
|
|
37
44
|
protected _bucketFirst: number;
|
|
38
45
|
/**
|
|
39
46
|
* The function returns the value of the protected variable `_bucketFirst`.
|
|
@@ -22,9 +22,11 @@ export class Deque extends IterableElementBase {
|
|
|
22
22
|
constructor(elements = [], options) {
|
|
23
23
|
super(options);
|
|
24
24
|
if (options) {
|
|
25
|
-
const { bucketSize } = options;
|
|
25
|
+
const { bucketSize, maxLen } = options;
|
|
26
26
|
if (typeof bucketSize === 'number')
|
|
27
27
|
this._bucketSize = bucketSize;
|
|
28
|
+
if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
|
|
29
|
+
this._maxLen = maxLen;
|
|
28
30
|
}
|
|
29
31
|
let _size;
|
|
30
32
|
if ('length' in elements) {
|
|
@@ -64,6 +66,15 @@ export class Deque extends IterableElementBase {
|
|
|
64
66
|
get bucketSize() {
|
|
65
67
|
return this._bucketSize;
|
|
66
68
|
}
|
|
69
|
+
_maxLen = -1;
|
|
70
|
+
/**
|
|
71
|
+
* The maxLen function returns the max length of the deque.
|
|
72
|
+
*
|
|
73
|
+
* @return The max length of the deque
|
|
74
|
+
*/
|
|
75
|
+
get maxLen() {
|
|
76
|
+
return this._maxLen;
|
|
77
|
+
}
|
|
67
78
|
_bucketFirst = 0;
|
|
68
79
|
/**
|
|
69
80
|
* The function returns the value of the protected variable `_bucketFirst`.
|
|
@@ -172,6 +183,8 @@ export class Deque extends IterableElementBase {
|
|
|
172
183
|
}
|
|
173
184
|
this._size += 1;
|
|
174
185
|
this._buckets[this._bucketLast][this._lastInBucket] = element;
|
|
186
|
+
if (this._maxLen > 0 && this._size > this._maxLen)
|
|
187
|
+
this.shift();
|
|
175
188
|
return true;
|
|
176
189
|
}
|
|
177
190
|
/**
|
|
@@ -238,6 +251,8 @@ export class Deque extends IterableElementBase {
|
|
|
238
251
|
}
|
|
239
252
|
this._size += 1;
|
|
240
253
|
this._buckets[this._bucketFirst][this._firstInBucket] = element;
|
|
254
|
+
if (this._maxLen > 0 && this._size > this._maxLen)
|
|
255
|
+
this.pop();
|
|
241
256
|
return true;
|
|
242
257
|
}
|
|
243
258
|
/**
|
|
@@ -60,6 +60,18 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
|
|
|
60
60
|
* array is empty, it returns `undefined`.
|
|
61
61
|
*/
|
|
62
62
|
get last(): E | undefined;
|
|
63
|
+
_autoCompactRatio: number;
|
|
64
|
+
/**
|
|
65
|
+
* This function returns the value of the autoCompactRatio property.
|
|
66
|
+
* @returns The `autoCompactRatio` property of the object, which is a number.
|
|
67
|
+
*/
|
|
68
|
+
get autoCompactRatio(): number;
|
|
69
|
+
/**
|
|
70
|
+
* The above function sets the autoCompactRatio property to a specified number in TypeScript.
|
|
71
|
+
* @param {number} v - The parameter `v` represents the value that will be assigned to the
|
|
72
|
+
* `_autoCompactRatio` property.
|
|
73
|
+
*/
|
|
74
|
+
set autoCompactRatio(v: number);
|
|
63
75
|
/**
|
|
64
76
|
* Time Complexity: O(n)
|
|
65
77
|
* Space Complexity: O(n)
|
|
@@ -70,7 +82,6 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
|
|
|
70
82
|
*
|
|
71
83
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
72
84
|
* @public
|
|
73
|
-
* @static
|
|
74
85
|
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
75
86
|
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
76
87
|
* array.
|
|
@@ -160,6 +171,12 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
|
|
|
160
171
|
* The clear function resets the elements array and offset to their initial values.
|
|
161
172
|
*/
|
|
162
173
|
clear(): void;
|
|
174
|
+
/**
|
|
175
|
+
* The `compact` function in TypeScript slices the elements array based on the offset and resets the
|
|
176
|
+
* offset to zero.
|
|
177
|
+
* @returns The `compact()` method is returning a boolean value of `true`.
|
|
178
|
+
*/
|
|
179
|
+
compact(): boolean;
|
|
163
180
|
/**
|
|
164
181
|
* Time Complexity: O(n)
|
|
165
182
|
* Space Complexity: O(n)
|
|
@@ -12,6 +12,10 @@ import { SinglyLinkedList } from '../linked-list';
|
|
|
12
12
|
export class Queue extends IterableElementBase {
|
|
13
13
|
constructor(elements = [], options) {
|
|
14
14
|
super(options);
|
|
15
|
+
if (options) {
|
|
16
|
+
const { autoCompactRatio = 0.5 } = options;
|
|
17
|
+
this._autoCompactRatio = autoCompactRatio;
|
|
18
|
+
}
|
|
15
19
|
if (elements) {
|
|
16
20
|
for (const el of elements) {
|
|
17
21
|
if (this.toElementFn)
|
|
@@ -74,6 +78,22 @@ export class Queue extends IterableElementBase {
|
|
|
74
78
|
get last() {
|
|
75
79
|
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
76
80
|
}
|
|
81
|
+
_autoCompactRatio = 0.5;
|
|
82
|
+
/**
|
|
83
|
+
* This function returns the value of the autoCompactRatio property.
|
|
84
|
+
* @returns The `autoCompactRatio` property of the object, which is a number.
|
|
85
|
+
*/
|
|
86
|
+
get autoCompactRatio() {
|
|
87
|
+
return this._autoCompactRatio;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The above function sets the autoCompactRatio property to a specified number in TypeScript.
|
|
91
|
+
* @param {number} v - The parameter `v` represents the value that will be assigned to the
|
|
92
|
+
* `_autoCompactRatio` property.
|
|
93
|
+
*/
|
|
94
|
+
set autoCompactRatio(v) {
|
|
95
|
+
this._autoCompactRatio = v;
|
|
96
|
+
}
|
|
77
97
|
/**
|
|
78
98
|
* Time Complexity: O(n)
|
|
79
99
|
* Space Complexity: O(n)
|
|
@@ -84,7 +104,6 @@ export class Queue extends IterableElementBase {
|
|
|
84
104
|
*
|
|
85
105
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
86
106
|
* @public
|
|
87
|
-
* @static
|
|
88
107
|
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
89
108
|
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
90
109
|
* array.
|
|
@@ -125,12 +144,8 @@ export class Queue extends IterableElementBase {
|
|
|
125
144
|
return undefined;
|
|
126
145
|
const first = this.first;
|
|
127
146
|
this._offset += 1;
|
|
128
|
-
if (this.offset
|
|
129
|
-
|
|
130
|
-
// only delete dequeued elements when reaching half size
|
|
131
|
-
// to decrease latency of shifting elements.
|
|
132
|
-
this._elements = this.elements.slice(this.offset);
|
|
133
|
-
this._offset = 0;
|
|
147
|
+
if (this.offset / this.elements.length > this.autoCompactRatio)
|
|
148
|
+
this.compact();
|
|
134
149
|
return first;
|
|
135
150
|
}
|
|
136
151
|
/**
|
|
@@ -206,6 +221,16 @@ export class Queue extends IterableElementBase {
|
|
|
206
221
|
this._elements = [];
|
|
207
222
|
this._offset = 0;
|
|
208
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* The `compact` function in TypeScript slices the elements array based on the offset and resets the
|
|
226
|
+
* offset to zero.
|
|
227
|
+
* @returns The `compact()` method is returning a boolean value of `true`.
|
|
228
|
+
*/
|
|
229
|
+
compact() {
|
|
230
|
+
this._elements = this.elements.slice(this.offset);
|
|
231
|
+
this._offset = 0;
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
209
234
|
/**
|
|
210
235
|
* Time Complexity: O(n)
|
|
211
236
|
* Space Complexity: O(n)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKeyOrNodeOrEntry } from '../types';
|
|
3
3
|
export interface IBinaryTree<K = any, V = any, R = [K, V], NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
|
|
4
4
|
createNode(key: K, value?: NODE['value']): NODE;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
6
|
-
add(keyOrNodeOrEntryOrRawElement:
|
|
7
|
-
addMany(nodes: Iterable<
|
|
6
|
+
add(keyOrNodeOrEntryOrRawElement: BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
8
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
9
9
|
}
|
|
@@ -1,36 +1,15 @@
|
|
|
1
1
|
export type CP = 1 | -1 | 0;
|
|
2
|
-
/**
|
|
3
|
-
* Enum representing different loop types.
|
|
4
|
-
*
|
|
5
|
-
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
6
|
-
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
7
|
-
*/
|
|
8
2
|
export type IterationType = 'ITERATIVE' | 'RECURSIVE';
|
|
9
3
|
export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
|
|
10
4
|
export type Comparator<K> = (a: K, b: K) => number;
|
|
11
5
|
export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
|
|
12
6
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
13
|
-
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
14
7
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
15
8
|
size: number | ((...args: any[]) => number);
|
|
16
9
|
}
|
|
17
10
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
18
11
|
length: number | ((...args: any[]) => number);
|
|
19
12
|
}
|
|
13
|
+
export type OptValue<V> = V | undefined;
|
|
20
14
|
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
|
|
21
|
-
export type BinaryTreePrintOptions = {
|
|
22
|
-
isShowUndefined?: boolean;
|
|
23
|
-
isShowNull?: boolean;
|
|
24
|
-
isShowRedBlackNIL?: boolean;
|
|
25
|
-
};
|
|
26
|
-
export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
27
|
-
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
28
|
-
export type KeyOrNodeOrEntry<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
29
|
-
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
30
|
-
export type BTNPureKeyOrNodeOrEntry<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
31
|
-
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
|
32
|
-
export type BinaryTreeDeleteResult<N> = {
|
|
33
|
-
deleted: N | null | undefined;
|
|
34
|
-
needBalanced: N | null | undefined;
|
|
35
|
-
};
|
|
36
15
|
export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
|
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
|
-
import {
|
|
2
|
+
import { IterationType, OptValue } from '../../common';
|
|
3
3
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeOptions<K, V, R> = {
|
|
6
6
|
iterationType?: IterationType;
|
|
7
7
|
toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
8
8
|
};
|
|
9
|
+
export type BinaryTreePrintOptions = {
|
|
10
|
+
isShowUndefined?: boolean;
|
|
11
|
+
isShowNull?: boolean;
|
|
12
|
+
isShowRedBlackNIL?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type OptBTNOrNull<NODE> = NODE | null | undefined;
|
|
15
|
+
export type OptBTNKeyOrNull<K> = K | null | undefined;
|
|
16
|
+
export type BTNEntry<K, V> = [OptBTNKeyOrNull<K>, OptValue<V>];
|
|
17
|
+
export type BTNKeyOrNode<K, NODE> = OptBTNKeyOrNull<K> | NODE;
|
|
18
|
+
export type BTNKeyOrNodeOrEntry<K, V, NODE> = BTNEntry<K, V> | BTNKeyOrNode<K, NODE>;
|
|
19
|
+
export type BTNPureKeyOrNode<K, NODE> = K | NODE;
|
|
20
|
+
export type BTNPureKeyOrNodeOrEntry<K, V, NODE> = [K, OptValue<V>] | BTNPureKeyOrNode<K, NODE>;
|
|
21
|
+
export type BinaryTreeDeleteResult<NODE> = {
|
|
22
|
+
deleted: OptBTNOrNull<NODE>;
|
|
23
|
+
needBalanced: OptBTNOrNull<NODE>;
|
|
24
|
+
};
|
|
25
|
+
export type BTNCallback<NODE, D = any> = (node: NODE) => D;
|
|
@@ -6,3 +6,6 @@ export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R,
|
|
|
6
6
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
7
7
|
comparator?: Comparator<K>;
|
|
8
8
|
};
|
|
9
|
+
export type OptBSTNKey<K> = K | undefined;
|
|
10
|
+
export type OptBSTN<NODE> = NODE | undefined;
|
|
11
|
+
export type BSTNKeyOrNode<K, NODE> = OptBSTNKey<K> | NODE;
|