data-structure-typed 1.34.8 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/custom.md +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +0 -0
- package/README.md +8 -8
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +280 -423
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +63 -89
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +11 -30
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +127 -214
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +19 -43
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.js +80 -122
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +147 -218
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +338 -572
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +145 -275
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +46 -87
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +90 -179
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +85 -247
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +87 -128
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/pair.js.map +1 -1
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-map.js.map +1 -1
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/hash/tree-set.js.map +1 -1
- package/dist/data-structures/heap/heap.js +56 -80
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +57 -70
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.js +63 -84
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/queue.js +57 -157
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/tree.js +32 -45
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/utils/utils.js +22 -107
- package/dist/utils/utils.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +79 -78
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +61 -141
- package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -0
- package/lib/data-structures/binary-tree/avl-tree.js +22 -0
- package/lib/data-structures/binary-tree/bst.d.ts +3 -3
- package/lib/data-structures/binary-tree/bst.js +12 -15
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +16 -18
- package/lib/data-structures/binary-tree/tree-multiset.js +26 -36
- package/lib/data-structures/graph/abstract-graph.d.ts +2 -2
- package/lib/data-structures/graph/abstract-graph.js +5 -5
- package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
- package/lib/data-structures/priority-queue/priority-queue.js +3 -3
- package/lib/interfaces/abstract-binary-tree.d.ts +1 -83
- package/lib/interfaces/abstract-graph.d.ts +2 -14
- package/lib/interfaces/avl-tree.d.ts +3 -4
- package/lib/interfaces/binary-tree.d.ts +4 -2
- package/lib/interfaces/bst.d.ts +2 -12
- package/lib/interfaces/directed-graph.d.ts +0 -9
- package/lib/interfaces/rb-tree.d.ts +2 -3
- package/lib/interfaces/tree-multiset.d.ts +5 -4
- package/lib/interfaces/undirected-graph.d.ts +0 -2
- package/lib/types/data-structures/abstract-binary-tree.js +0 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +151 -203
- package/src/data-structures/binary-tree/avl-tree.ts +29 -0
- package/src/data-structures/binary-tree/bst.ts +12 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +27 -39
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/interfaces/abstract-binary-tree.ts +2 -183
- package/src/interfaces/abstract-graph.ts +2 -26
- package/src/interfaces/avl-tree.ts +4 -21
- package/src/interfaces/binary-tree.ts +3 -2
- package/src/interfaces/bst.ts +2 -27
- package/src/interfaces/directed-graph.ts +1 -18
- package/src/interfaces/rb-tree.ts +2 -5
- package/src/interfaces/tree-multiset.ts +4 -4
- package/src/interfaces/undirected-graph.ts +1 -4
- package/src/types/data-structures/abstract-binary-tree.ts +0 -1
- package/test/integration/avl-tree.test.ts +24 -24
- package/test/integration/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -9
- package/test/unit/data-structures/binary-tree/bst.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +9 -9
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -118,22 +118,22 @@ export class BST extends BinaryTree {
|
|
|
118
118
|
/**
|
|
119
119
|
* The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
|
|
120
120
|
* manner.
|
|
121
|
-
* @param {[BinaryTreeNodeKey | N , N['val']][]}
|
|
121
|
+
* @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
|
|
122
122
|
* `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
|
|
123
123
|
* to the binary search tree.
|
|
124
124
|
* @param {N['val'][]} data - The values of tree nodes
|
|
125
125
|
* @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
|
|
126
126
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
127
127
|
*/
|
|
128
|
-
addMany(
|
|
128
|
+
addMany(keysOrNodes, data, isBalanceAdd = false) {
|
|
129
129
|
function hasNoNull(arr) {
|
|
130
130
|
return arr.indexOf(null) === -1;
|
|
131
131
|
}
|
|
132
|
-
if (!isBalanceAdd || !hasNoNull(
|
|
133
|
-
return super.addMany(
|
|
132
|
+
if (!isBalanceAdd || !hasNoNull(keysOrNodes)) {
|
|
133
|
+
return super.addMany(keysOrNodes, data);
|
|
134
134
|
}
|
|
135
135
|
const inserted = [];
|
|
136
|
-
const combinedArr =
|
|
136
|
+
const combinedArr = keysOrNodes.map((value, index) => [value, data === null || data === void 0 ? void 0 : data[index]]);
|
|
137
137
|
let sorted = [];
|
|
138
138
|
function isNodeOrNullTuple(arr) {
|
|
139
139
|
for (const [keyOrNode] of arr)
|
|
@@ -155,7 +155,7 @@ export class BST extends BinaryTree {
|
|
|
155
155
|
sorted = combinedArr.sort((a, b) => a[0] - b[0]);
|
|
156
156
|
}
|
|
157
157
|
else {
|
|
158
|
-
throw new Error('Invalid input
|
|
158
|
+
throw new Error('Invalid input keysOrNodes');
|
|
159
159
|
}
|
|
160
160
|
sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
|
|
161
161
|
sortedData = sorted.map(([, val]) => val);
|
|
@@ -201,9 +201,8 @@ export class BST extends BinaryTree {
|
|
|
201
201
|
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
|
|
202
202
|
* @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
|
|
203
203
|
*/
|
|
204
|
-
get(nodeProperty, propertyName) {
|
|
204
|
+
get(nodeProperty, propertyName = 'key') {
|
|
205
205
|
var _a;
|
|
206
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
207
206
|
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
|
|
208
207
|
}
|
|
209
208
|
/**
|
|
@@ -233,7 +232,7 @@ export class BST extends BinaryTree {
|
|
|
233
232
|
* is set to `true`, the function will return an array with only one node (if
|
|
234
233
|
* @returns an array of nodes (type N).
|
|
235
234
|
*/
|
|
236
|
-
getNodes(nodeProperty, propertyName = 'key', onlyOne) {
|
|
235
|
+
getNodes(nodeProperty, propertyName = 'key', onlyOne = false) {
|
|
237
236
|
if (!this.root)
|
|
238
237
|
return [];
|
|
239
238
|
const result = [];
|
|
@@ -288,8 +287,7 @@ export class BST extends BinaryTree {
|
|
|
288
287
|
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
|
|
289
288
|
* binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
|
|
290
289
|
*/
|
|
291
|
-
lesserSum(beginNode, propertyName) {
|
|
292
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
290
|
+
lesserSum(beginNode, propertyName = 'key') {
|
|
293
291
|
if (typeof beginNode === 'number')
|
|
294
292
|
beginNode = this.get(beginNode, 'key');
|
|
295
293
|
if (!beginNode)
|
|
@@ -380,8 +378,7 @@ export class BST extends BinaryTree {
|
|
|
380
378
|
* 'key'.
|
|
381
379
|
* @returns a boolean value.
|
|
382
380
|
*/
|
|
383
|
-
allGreaterNodesAdd(node, delta, propertyName) {
|
|
384
|
-
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
|
|
381
|
+
allGreaterNodesAdd(node, delta, propertyName = 'key') {
|
|
385
382
|
if (typeof node === 'number')
|
|
386
383
|
node = this.get(node, 'key');
|
|
387
384
|
if (!node)
|
|
@@ -446,7 +443,7 @@ export class BST extends BinaryTree {
|
|
|
446
443
|
* @returns The function `perfectlyBalance()` returns a boolean value.
|
|
447
444
|
*/
|
|
448
445
|
perfectlyBalance() {
|
|
449
|
-
const sorted = this.
|
|
446
|
+
const sorted = this.dfs('in', 'node'), n = sorted.length;
|
|
450
447
|
this.clear();
|
|
451
448
|
if (sorted.length < 1)
|
|
452
449
|
return false;
|
|
@@ -534,7 +531,7 @@ export class BST extends BinaryTree {
|
|
|
534
531
|
/**
|
|
535
532
|
* The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
|
|
536
533
|
* greater than, less than, or equal to the second ID.
|
|
537
|
-
* @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
|
|
534
|
+
* @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
|
|
538
535
|
* @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
|
|
539
536
|
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
|
|
540
537
|
* than), or CP.eq (equal).
|
|
@@ -11,19 +11,17 @@ import { ITreeMultiset, ITreeMultisetNode } from '../../interfaces';
|
|
|
11
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
12
|
export declare class TreeMultisetNode<V = any, NEIGHBOR extends TreeMultisetNode<V, NEIGHBOR> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, NEIGHBOR> implements ITreeMultisetNode<V, NEIGHBOR> {
|
|
13
13
|
/**
|
|
14
|
-
* The constructor function initializes a BinaryTreeNode object with
|
|
14
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
15
15
|
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
|
|
16
16
|
* of the binary tree node.
|
|
17
17
|
* @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
18
18
|
* tree node. If no value is provided, it will be `undefined`.
|
|
19
19
|
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
20
20
|
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
21
|
-
* parameter when creating a new instance of the `BinaryTreeNode` class
|
|
21
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
22
22
|
*/
|
|
23
23
|
constructor(key: BinaryTreeNodeKey, val?: V, count?: number);
|
|
24
|
-
|
|
25
|
-
get count(): number;
|
|
26
|
-
set count(v: number);
|
|
24
|
+
count: number;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
@@ -80,14 +78,14 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
|
|
|
80
78
|
/**
|
|
81
79
|
* The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
|
|
82
80
|
* the inserted nodes.
|
|
83
|
-
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]}
|
|
81
|
+
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
|
|
84
82
|
* objects, or null values.
|
|
85
83
|
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
|
|
86
84
|
* the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
|
|
87
85
|
* method. If provided, the `data` array should
|
|
88
86
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
89
87
|
*/
|
|
90
|
-
addMany(
|
|
88
|
+
addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
|
|
91
89
|
/**
|
|
92
90
|
* The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
|
|
93
91
|
* constructs a balanced binary search tree using either a recursive or iterative approach.
|
|
@@ -146,7 +144,7 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
|
|
|
146
144
|
/**
|
|
147
145
|
* The BFSCount function returns an array of counts from a breadth-first search of nodes.
|
|
148
146
|
* @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
|
|
149
|
-
*
|
|
147
|
+
* bfs traversal.
|
|
150
148
|
*/
|
|
151
149
|
BFSCount(): number[];
|
|
152
150
|
/**
|
|
@@ -165,24 +163,24 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
|
|
|
165
163
|
* traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
|
|
166
164
|
* @returns The function `morrisCount` returns an array of numbers.
|
|
167
165
|
*/
|
|
168
|
-
morrisCount(pattern?:
|
|
166
|
+
morrisCount(pattern?: DFSOrderPattern): number[];
|
|
169
167
|
/**
|
|
170
|
-
* The function
|
|
168
|
+
* The function dfsCountIterative performs an iterative depth-first search and returns an array of node counts based on
|
|
171
169
|
* the specified traversal pattern.
|
|
172
170
|
* @param {'in' | 'pre' | 'post'} [pattern] - The pattern parameter is a string that specifies the traversal order for
|
|
173
|
-
* the Depth-First Search (
|
|
174
|
-
* @returns The
|
|
175
|
-
* in the
|
|
171
|
+
* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
|
|
172
|
+
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
|
|
173
|
+
* in the dfs traversal.
|
|
176
174
|
*/
|
|
177
|
-
|
|
175
|
+
dfsCountIterative(pattern?: DFSOrderPattern): number[];
|
|
178
176
|
/**
|
|
179
|
-
* The
|
|
177
|
+
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
|
|
180
178
|
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
|
|
181
|
-
* the Depth-First Search (
|
|
182
|
-
* @returns The
|
|
179
|
+
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
|
|
180
|
+
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
|
|
183
181
|
* traversal.
|
|
184
182
|
*/
|
|
185
|
-
|
|
183
|
+
dfsCount(pattern?: DFSOrderPattern): number[];
|
|
186
184
|
/**
|
|
187
185
|
* The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser
|
|
188
186
|
* value than a given node.
|
|
@@ -2,24 +2,18 @@ import { CP, FamilyPosition, LoopType } from '../../types';
|
|
|
2
2
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
3
3
|
export class TreeMultisetNode extends AVLTreeNode {
|
|
4
4
|
/**
|
|
5
|
-
* The constructor function initializes a BinaryTreeNode object with
|
|
5
|
+
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
6
6
|
* @param {BinaryTreeNodeKey} key - The `key` parameter is of type `BinaryTreeNodeKey` and represents the unique identifier
|
|
7
7
|
* of the binary tree node.
|
|
8
8
|
* @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
|
|
9
9
|
* tree node. If no value is provided, it will be `undefined`.
|
|
10
10
|
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
|
|
11
11
|
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
|
|
12
|
-
* parameter when creating a new instance of the `BinaryTreeNode` class
|
|
12
|
+
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
13
13
|
*/
|
|
14
14
|
constructor(key, val, count = 1) {
|
|
15
15
|
super(key, val);
|
|
16
|
-
this.
|
|
17
|
-
}
|
|
18
|
-
get count() {
|
|
19
|
-
return this._count;
|
|
20
|
-
}
|
|
21
|
-
set count(v) {
|
|
22
|
-
this._count = v;
|
|
16
|
+
this.count = count;
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
19
|
/**
|
|
@@ -33,7 +27,7 @@ export class TreeMultiset extends AVLTree {
|
|
|
33
27
|
* TreeMultiset.
|
|
34
28
|
*/
|
|
35
29
|
constructor(options) {
|
|
36
|
-
super(
|
|
30
|
+
super(options);
|
|
37
31
|
this._count = 0;
|
|
38
32
|
}
|
|
39
33
|
get count() {
|
|
@@ -84,8 +78,7 @@ export class TreeMultiset extends AVLTree {
|
|
|
84
78
|
* value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
|
|
85
79
|
* @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
|
|
86
80
|
*/
|
|
87
|
-
add(keyOrNode, val, count) {
|
|
88
|
-
count = count !== null && count !== void 0 ? count : 1;
|
|
81
|
+
add(keyOrNode, val, count = 1) {
|
|
89
82
|
let inserted = undefined, newNode;
|
|
90
83
|
if (keyOrNode instanceof TreeMultisetNode) {
|
|
91
84
|
newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count);
|
|
@@ -199,17 +192,17 @@ export class TreeMultiset extends AVLTree {
|
|
|
199
192
|
/**
|
|
200
193
|
* The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
|
|
201
194
|
* the inserted nodes.
|
|
202
|
-
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]}
|
|
195
|
+
* @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
|
|
203
196
|
* objects, or null values.
|
|
204
197
|
* @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
|
|
205
198
|
* the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
|
|
206
199
|
* method. If provided, the `data` array should
|
|
207
200
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
208
201
|
*/
|
|
209
|
-
addMany(
|
|
202
|
+
addMany(keysOrNodes, data) {
|
|
210
203
|
const inserted = [];
|
|
211
|
-
for (let i = 0; i <
|
|
212
|
-
const keyOrNode =
|
|
204
|
+
for (let i = 0; i < keysOrNodes.length; i++) {
|
|
205
|
+
const keyOrNode = keysOrNodes[i];
|
|
213
206
|
if (keyOrNode instanceof TreeMultisetNode) {
|
|
214
207
|
inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count));
|
|
215
208
|
continue;
|
|
@@ -228,7 +221,7 @@ export class TreeMultiset extends AVLTree {
|
|
|
228
221
|
* @returns The function `perfectlyBalance()` returns a boolean value.
|
|
229
222
|
*/
|
|
230
223
|
perfectlyBalance() {
|
|
231
|
-
const sorted = this.
|
|
224
|
+
const sorted = this.dfs('in', 'node'), n = sorted.length;
|
|
232
225
|
if (sorted.length < 1)
|
|
233
226
|
return false;
|
|
234
227
|
this.clear();
|
|
@@ -272,7 +265,7 @@ export class TreeMultiset extends AVLTree {
|
|
|
272
265
|
* not be taken into account when removing it. If `ignoreCount` is set to `false
|
|
273
266
|
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
274
267
|
*/
|
|
275
|
-
remove(nodeOrKey, ignoreCount) {
|
|
268
|
+
remove(nodeOrKey, ignoreCount = false) {
|
|
276
269
|
const bstDeletedResult = [];
|
|
277
270
|
if (!this.root)
|
|
278
271
|
return bstDeletedResult;
|
|
@@ -442,7 +435,7 @@ export class TreeMultiset extends AVLTree {
|
|
|
442
435
|
* to `true`, the function will return only one node. If `onlyOne`
|
|
443
436
|
* @returns an array of nodes that match the given nodeProperty.
|
|
444
437
|
*/
|
|
445
|
-
getNodesByCount(nodeProperty, onlyOne) {
|
|
438
|
+
getNodesByCount(nodeProperty, onlyOne = false) {
|
|
446
439
|
if (!this.root)
|
|
447
440
|
return [];
|
|
448
441
|
const result = [];
|
|
@@ -480,10 +473,10 @@ export class TreeMultiset extends AVLTree {
|
|
|
480
473
|
/**
|
|
481
474
|
* The BFSCount function returns an array of counts from a breadth-first search of nodes.
|
|
482
475
|
* @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
|
|
483
|
-
*
|
|
476
|
+
* bfs traversal.
|
|
484
477
|
*/
|
|
485
478
|
BFSCount() {
|
|
486
|
-
const nodes = super.
|
|
479
|
+
const nodes = super.bfs('node');
|
|
487
480
|
return nodes.map(node => node.count);
|
|
488
481
|
}
|
|
489
482
|
/**
|
|
@@ -505,34 +498,31 @@ export class TreeMultiset extends AVLTree {
|
|
|
505
498
|
* traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
|
|
506
499
|
* @returns The function `morrisCount` returns an array of numbers.
|
|
507
500
|
*/
|
|
508
|
-
morrisCount(pattern) {
|
|
509
|
-
pattern = pattern || 'in';
|
|
501
|
+
morrisCount(pattern = 'in') {
|
|
510
502
|
const nodes = super.morris(pattern, 'node');
|
|
511
503
|
return nodes.map(node => node.count);
|
|
512
504
|
}
|
|
513
505
|
/**
|
|
514
|
-
* The function
|
|
506
|
+
* The function dfsCountIterative performs an iterative depth-first search and returns an array of node counts based on
|
|
515
507
|
* the specified traversal pattern.
|
|
516
508
|
* @param {'in' | 'pre' | 'post'} [pattern] - The pattern parameter is a string that specifies the traversal order for
|
|
517
|
-
* the Depth-First Search (
|
|
518
|
-
* @returns The
|
|
519
|
-
* in the
|
|
509
|
+
* the Depth-First Search (dfs) algorithm. It can have three possible values: 'in', 'pre', or 'post'.
|
|
510
|
+
* @returns The dfsCountIterative function returns an array of numbers, which represents the count property of each node
|
|
511
|
+
* in the dfs traversal.
|
|
520
512
|
*/
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
const nodes = super.DFSIterative(pattern, 'node');
|
|
513
|
+
dfsCountIterative(pattern = 'in') {
|
|
514
|
+
const nodes = super.dfsIterative(pattern, 'node');
|
|
524
515
|
return nodes.map(node => node.count);
|
|
525
516
|
}
|
|
526
517
|
/**
|
|
527
|
-
* The
|
|
518
|
+
* The dfsCount function returns an array of counts for each node in a depth-first search traversal.
|
|
528
519
|
* @param {DFSOrderPattern} [pattern] - The pattern parameter is an optional parameter that specifies the order in which
|
|
529
|
-
* the Depth-First Search (
|
|
530
|
-
* @returns The
|
|
520
|
+
* the Depth-First Search (dfs) algorithm should traverse the nodes. It can have one of the following values:
|
|
521
|
+
* @returns The dfsCount function returns an array of numbers, specifically the count property of each node in the dfs
|
|
531
522
|
* traversal.
|
|
532
523
|
*/
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
const nodes = super.DFS(pattern, 'node');
|
|
524
|
+
dfsCount(pattern = 'in') {
|
|
525
|
+
const nodes = super.dfs(pattern, 'node');
|
|
536
526
|
return nodes.map(node => node.count);
|
|
537
527
|
}
|
|
538
528
|
/**
|
|
@@ -288,7 +288,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
288
288
|
predecessor: (V | null)[][];
|
|
289
289
|
};
|
|
290
290
|
/**
|
|
291
|
-
* Tarjan is an algorithm based on
|
|
291
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
292
292
|
* Tarjan can find cycles in directed or undirected graph
|
|
293
293
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
294
294
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -296,7 +296,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
296
296
|
* /
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
|
-
* Tarjan is an algorithm based on
|
|
299
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
300
300
|
* Tarjan can find cycles in directed or undirected graph
|
|
301
301
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
302
302
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -775,7 +775,7 @@ export class AbstractGraph {
|
|
|
775
775
|
return { costs, predecessor };
|
|
776
776
|
}
|
|
777
777
|
/**
|
|
778
|
-
* Tarjan is an algorithm based on
|
|
778
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
779
779
|
* Tarjan can find cycles in directed or undirected graph
|
|
780
780
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
781
781
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -783,7 +783,7 @@ export class AbstractGraph {
|
|
|
783
783
|
* /
|
|
784
784
|
|
|
785
785
|
/**
|
|
786
|
-
* Tarjan is an algorithm based on
|
|
786
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
787
787
|
* Tarjan can find cycles in directed or undirected graph
|
|
788
788
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
789
789
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -804,8 +804,8 @@ export class AbstractGraph {
|
|
|
804
804
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
805
805
|
*/
|
|
806
806
|
tarjan(needArticulationPoints, needBridges, needSCCs, needCycles) {
|
|
807
|
-
// !! in undirected graph we will not let child visit parent when
|
|
808
|
-
// !! articulation point(in
|
|
807
|
+
// !! in undirected graph we will not let child visit parent when dfs
|
|
808
|
+
// !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
|
|
809
809
|
// !! bridge: low(child) > dfn(cur)
|
|
810
810
|
const defaultConfig = false;
|
|
811
811
|
if (needArticulationPoints === undefined)
|
|
@@ -832,7 +832,7 @@ export class AbstractGraph {
|
|
|
832
832
|
dfnMap.set(cur, dfn);
|
|
833
833
|
lowMap.set(cur, dfn);
|
|
834
834
|
const neighbors = this.getNeighbors(cur);
|
|
835
|
-
let childCount = 0; // child in
|
|
835
|
+
let childCount = 0; // child in dfs tree not child in graph
|
|
836
836
|
for (const neighbor of neighbors) {
|
|
837
837
|
if (neighbor !== parent) {
|
|
838
838
|
if (dfnMap.get(neighbor) === -1) {
|
|
@@ -104,13 +104,13 @@ export declare class PriorityQueue<E = any> {
|
|
|
104
104
|
*/
|
|
105
105
|
sort(): E[];
|
|
106
106
|
/**
|
|
107
|
-
* The
|
|
107
|
+
* The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
|
|
108
108
|
* based on the specified traversal order.
|
|
109
109
|
* @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
|
|
110
|
-
* the nodes should be visited during the Depth-First Search (
|
|
110
|
+
* the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
|
|
111
111
|
* @returns an array of type `(E | null)[]`.
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
dfs(dfsMode: PriorityQueueDFSOrderPattern): (E | null)[];
|
|
114
114
|
protected _setNodes(value: E[]): void;
|
|
115
115
|
protected readonly _comparator: PriorityQueueComparator<E>;
|
|
116
116
|
/**
|
|
@@ -174,13 +174,13 @@ export class PriorityQueue {
|
|
|
174
174
|
return visitedNode;
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
|
-
* The
|
|
177
|
+
* The dfs function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
|
|
178
178
|
* based on the specified traversal order.
|
|
179
179
|
* @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
|
|
180
|
-
* the nodes should be visited during the Depth-First Search (
|
|
180
|
+
* the nodes should be visited during the Depth-First Search (dfs) traversal. It can have one of the following values:
|
|
181
181
|
* @returns an array of type `(E | null)[]`.
|
|
182
182
|
*/
|
|
183
|
-
|
|
183
|
+
dfs(dfsMode) {
|
|
184
184
|
const visitedNode = [];
|
|
185
185
|
const traverse = (cur) => {
|
|
186
186
|
var _a, _b, _c;
|
|
@@ -1,89 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BinaryTreeNodeKey } from '../types';
|
|
2
2
|
import { AbstractBinaryTreeNode } from '../data-structures';
|
|
3
3
|
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
|
4
|
-
get key(): BinaryTreeNodeKey;
|
|
5
|
-
set key(v: BinaryTreeNodeKey);
|
|
6
|
-
get val(): T | undefined;
|
|
7
|
-
set val(v: T | undefined);
|
|
8
|
-
get left(): NEIGHBOR | null | undefined;
|
|
9
|
-
set left(v: NEIGHBOR | null | undefined);
|
|
10
|
-
get right(): NEIGHBOR | null | undefined;
|
|
11
|
-
set right(v: NEIGHBOR | null | undefined);
|
|
12
|
-
get parent(): NEIGHBOR | null | undefined;
|
|
13
|
-
set parent(v: NEIGHBOR | null | undefined);
|
|
14
|
-
get familyPosition(): FamilyPosition;
|
|
15
|
-
get height(): number;
|
|
16
|
-
set height(v: number);
|
|
17
4
|
}
|
|
18
5
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
19
6
|
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N | null;
|
|
20
|
-
get loopType(): LoopType;
|
|
21
|
-
get visitedKey(): BinaryTreeNodeKey[];
|
|
22
|
-
get visitedVal(): Array<N['val']>;
|
|
23
|
-
get visitedNode(): N[];
|
|
24
|
-
get root(): N | null;
|
|
25
|
-
get size(): number;
|
|
26
|
-
swapLocation(srcNode: N, destNode: N): N;
|
|
27
|
-
clear(): void;
|
|
28
|
-
isEmpty(): boolean;
|
|
29
|
-
add(key: BinaryTreeNodeKey | N, val?: N['val']): N | null | undefined;
|
|
30
|
-
addMany(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N['val'][]): (N | null | undefined)[];
|
|
31
|
-
fill(idsOrNodes: (BinaryTreeNodeKey | N | null)[], data?: N[] | Array<N['val']>): boolean;
|
|
32
|
-
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
33
|
-
getDepth(node: N): number;
|
|
34
|
-
getHeight(beginRoot?: N | null): number;
|
|
35
|
-
getMinHeight(beginRoot?: N | null): number;
|
|
36
|
-
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
37
|
-
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
38
|
-
has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
39
|
-
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
40
|
-
getPathToRoot(node: N): N[];
|
|
41
|
-
getLeftMost(): N | null;
|
|
42
|
-
getLeftMost(node: N): N;
|
|
43
|
-
getLeftMost(node?: N | null): N | null;
|
|
44
|
-
getRightMost(): N | null;
|
|
45
|
-
getRightMost(node: N): N;
|
|
46
|
-
getRightMost(node?: N | null): N | null;
|
|
47
|
-
isSubtreeBST(node: N | null): boolean;
|
|
48
|
-
isBST(): boolean;
|
|
49
|
-
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
50
|
-
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
51
|
-
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
52
|
-
BFS(): BinaryTreeNodeKey[];
|
|
53
|
-
BFS(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
|
|
54
|
-
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
55
|
-
BFS(nodeOrPropertyName: 'node'): N[];
|
|
56
|
-
BFS(nodeOrPropertyName: 'count'): number[];
|
|
57
|
-
BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
58
|
-
DFS(): BinaryTreeNodeKey[];
|
|
59
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
|
60
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
61
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
62
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
63
|
-
DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
64
|
-
DFSIterative(): BinaryTreeNodeKey[];
|
|
65
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
|
66
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
67
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
68
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
69
|
-
DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
70
|
-
levelIterative(node: N | null): BinaryTreeNodeKey[];
|
|
71
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
|
72
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
73
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
74
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
75
|
-
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
76
|
-
listLevels(node: N | null): BinaryTreeNodeKey[][];
|
|
77
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[][];
|
|
78
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
79
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
80
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
81
|
-
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
|
|
82
|
-
getPredecessor(node: N): N;
|
|
83
|
-
morris(): BinaryTreeNodeKey[];
|
|
84
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
|
|
85
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
86
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
87
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
88
|
-
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
89
7
|
}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { VertexKey } from '../types';
|
|
2
2
|
export interface IAbstractGraph<V, E> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
removeVertex(vertexOrKey: V | VertexKey): boolean;
|
|
6
|
-
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
|
|
7
|
-
degreeOf(vertexOrKey: V | VertexKey): number;
|
|
8
|
-
edgesOf(vertexOrKey: V | VertexKey): E[];
|
|
9
|
-
hasEdge(src: V | VertexKey, dest: V | VertexKey): boolean;
|
|
10
|
-
getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
11
|
-
edgeSet(): E[];
|
|
12
|
-
addEdge(src: V | VertexKey, dest: V | VertexKey, weight: number, val: E): boolean;
|
|
13
|
-
removeEdge(edge: E): E | null;
|
|
14
|
-
setEdgeWeight(srcOrKey: V | VertexKey, destOrKey: V | VertexKey, weight: number): boolean;
|
|
15
|
-
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
|
|
16
|
-
getNeighbors(vertexOrKey: V | VertexKey): V[];
|
|
3
|
+
createVertex(key: VertexKey, val?: V): V;
|
|
4
|
+
createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
|
|
17
5
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../data-structures';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
5
6
|
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
6
|
-
add(key: BinaryTreeNodeKey, val?: N['val'] | null): N | null | undefined;
|
|
7
|
-
remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
|
|
8
7
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../data-structures';
|
|
2
2
|
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
6
|
+
}
|
package/lib/interfaces/bst.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { BSTNode } from '../data-structures';
|
|
2
2
|
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
5
|
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
6
|
-
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
|
|
7
|
-
add(key: BinaryTreeNodeKey, val?: N['val'] | null, count?: number): N | null | undefined;
|
|
8
|
-
get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
9
|
-
lastKey(): BinaryTreeNodeKey;
|
|
10
|
-
remove(key: BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
11
|
-
getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
12
|
-
lesserSum(key: BinaryTreeNodeKey, propertyName?: BinaryTreeNodePropertyName): number;
|
|
13
|
-
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
14
|
-
perfectlyBalance(): boolean;
|
|
15
|
-
isAVLBalanced(): boolean;
|
|
16
6
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { VertexKey } from '../types';
|
|
2
1
|
import { IAbstractGraph } from './abstract-graph';
|
|
3
2
|
export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {
|
|
4
|
-
incomingEdgesOf(vertex: V): E[];
|
|
5
|
-
outgoingEdgesOf(vertex: V): E[];
|
|
6
|
-
inDegreeOf(vertexOrKey: V | VertexKey): number;
|
|
7
|
-
outDegreeOf(vertexOrKey: V | VertexKey): number;
|
|
8
|
-
getEdgeSrc(e: E): V | null;
|
|
9
|
-
getEdgeDest(e: E): V | null;
|
|
10
|
-
removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
11
|
-
removeEdgesBetween(v1: V | VertexKey, v2: V | VertexKey): E[];
|
|
12
3
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RBTreeNode } from '../data-structures';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
5
|
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
6
|
-
createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
|
|
7
6
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TreeMultisetNode } from '../data-structures';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
2
|
+
import { IAVLTree, IAVLTreeNode } from './avl-tree';
|
|
3
|
+
export interface ITreeMultisetNode<T, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IAVLTreeNode<T, NEIGHBOR> {
|
|
4
|
+
}
|
|
5
|
+
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
|
|
6
|
+
}
|
|
@@ -9,7 +9,6 @@ export var LoopType;
|
|
|
9
9
|
LoopType["ITERATIVE"] = "ITERATIVE";
|
|
10
10
|
LoopType["RECURSIVE"] = "RECURSIVE";
|
|
11
11
|
})(LoopType || (LoopType = {}));
|
|
12
|
-
/* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
|
|
13
12
|
export var FamilyPosition;
|
|
14
13
|
(function (FamilyPosition) {
|
|
15
14
|
FamilyPosition["ROOT"] = "ROOT";
|