graph-typed 1.38.2 → 1.38.5
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/.dependency-cruiser.js +422 -422
- package/.eslintrc.js +59 -59
- package/.prettierrc.js +14 -14
- package/README.md +21 -3
- package/coverage/clover.xml +22 -19
- package/coverage/coverage-final.json +445 -1
- package/coverage/coverage-summary.json +59 -2
- package/coverage/lcov-report/base.css +278 -99
- package/coverage/lcov-report/index.html +69 -65
- package/coverage/lcov-report/index.ts.html +45 -44
- package/coverage/lcov-report/sorter.js +15 -5
- package/dist/data-structures/binary-tree/binary-tree.d.ts +9 -9
- package/dist/data-structures/binary-tree/bst.d.ts +4 -4
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +12 -3
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +17 -4
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/helpers.d.ts +1 -1
- package/jest.config.js +6 -6
- package/package.json +4 -1
- package/src/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +21 -21
- package/src/data-structures/binary-tree/bst.ts +7 -7
- package/src/data-structures/binary-tree/tree-multiset.ts +2 -1
- package/src/data-structures/graph/abstract-graph.ts +11 -10
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/graph/undirected-graph.ts +5 -4
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +1 -2
- package/src/data-structures/hash/tree-set.ts +1 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +2 -4
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -8
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/vector2d.ts +1 -2
- package/src/data-structures/queue/deque.ts +4 -5
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/helpers.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
- package/tsconfig.json +1 -2
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
|
|
2
1
|
<!doctype html>
|
|
3
2
|
<html lang="en">
|
|
4
3
|
|
|
5
4
|
<head>
|
|
6
5
|
<title>Code coverage report for index.ts</title>
|
|
7
|
-
<meta charset="utf-8"
|
|
8
|
-
<link
|
|
9
|
-
<link
|
|
10
|
-
<link rel="shortcut icon" type="image/x-icon"
|
|
11
|
-
<meta
|
|
6
|
+
<meta charset="utf-8"/>
|
|
7
|
+
<link href="prettify.css" rel="stylesheet"/>
|
|
8
|
+
<link href="base.css" rel="stylesheet"/>
|
|
9
|
+
<link href="favicon.png" rel="shortcut icon" type="image/x-icon"/>
|
|
10
|
+
<meta content="width=device-width, initial-scale=1" name="viewport"/>
|
|
12
11
|
<style type='text/css'>
|
|
13
12
|
.coverage-summary .sorter {
|
|
14
13
|
background-image: url(sort-arrow-sprite.png);
|
|
15
14
|
}
|
|
16
15
|
</style>
|
|
17
16
|
</head>
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
<body>
|
|
20
19
|
<div class='wrapper'>
|
|
21
20
|
<div class='pad1'>
|
|
22
21
|
<h1><a href="index.html">All files</a> index.ts</h1>
|
|
23
22
|
<div class='clearfix'>
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
<div class='fl pad1y space-right2'>
|
|
26
25
|
<span class="strong">100% </span>
|
|
27
26
|
<span class="quiet">Statements</span>
|
|
28
27
|
<span class='fraction'>13/13</span>
|
|
29
28
|
</div>
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
|
|
30
|
+
|
|
32
31
|
<div class='fl pad1y space-right2'>
|
|
33
32
|
<span class="strong">100% </span>
|
|
34
33
|
<span class="quiet">Branches</span>
|
|
35
34
|
<span class='fraction'>0/0</span>
|
|
36
35
|
</div>
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
|
|
37
|
+
|
|
39
38
|
<div class='fl pad1y space-right2'>
|
|
40
39
|
<span class="strong">25% </span>
|
|
41
40
|
<span class="quiet">Functions</span>
|
|
42
41
|
<span class='fraction'>3/12</span>
|
|
43
42
|
</div>
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
|
|
46
45
|
<div class='fl pad1y space-right2'>
|
|
47
46
|
<span class="strong">100% </span>
|
|
48
47
|
<span class="quiet">Lines</span>
|
|
49
48
|
<span class='fraction'>13/13</span>
|
|
50
49
|
</div>
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
|
|
51
|
+
|
|
53
52
|
</div>
|
|
54
53
|
<p class="quiet">
|
|
55
|
-
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for
|
|
54
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for
|
|
55
|
+
the previous block.
|
|
56
56
|
</p>
|
|
57
57
|
<template id="filterTemplate">
|
|
58
58
|
<div class="quiet">
|
|
59
59
|
Filter:
|
|
60
|
-
<input oninput="onInput()" type="search"
|
|
60
|
+
<input id="fileSearch" oninput="onInput()" type="search">
|
|
61
61
|
</div>
|
|
62
62
|
</template>
|
|
63
63
|
</div>
|
|
@@ -85,7 +85,8 @@
|
|
|
85
85
|
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
86
|
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
87
|
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
-
<a name='L23'></a><a href='#L23'>23</a></td><td class="line-coverage quiet"><span
|
|
88
|
+
<a name='L23'></a><a href='#L23'>23</a></td><td class="line-coverage quiet"><span
|
|
89
|
+
class="cline-any cline-neutral"> </span>
|
|
89
90
|
<span class="cline-any cline-neutral"> </span>
|
|
90
91
|
<span class="cline-any cline-neutral"> </span>
|
|
91
92
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -115,37 +116,37 @@
|
|
|
115
116
|
* @license MIT License
|
|
116
117
|
*/
|
|
117
118
|
export {
|
|
118
|
-
<span class="fstat-no" title="function not covered"
|
|
119
|
-
<span class="fstat-no" title="function not covered"
|
|
120
|
-
<span class="fstat-no" title="function not covered"
|
|
119
|
+
<span class="fstat-no" title="function not covered"> AbstractVertex,</span>
|
|
120
|
+
<span class="fstat-no" title="function not covered"> AbstractEdge,</span>
|
|
121
|
+
<span class="fstat-no" title="function not covered"> AbstractGraph,</span>
|
|
121
122
|
DirectedVertex,
|
|
122
123
|
DirectedEdge,
|
|
123
124
|
DirectedGraph,
|
|
124
|
-
<span class="fstat-no" title="function not covered"
|
|
125
|
-
<span class="fstat-no" title="function not covered"
|
|
126
|
-
<span class="fstat-no" title="function not covered"
|
|
127
|
-
<span class="fstat-no" title="function not covered"
|
|
128
|
-
<span class="fstat-no" title="function not covered"
|
|
129
|
-
<span class="fstat-no" title="function not covered"
|
|
125
|
+
<span class="fstat-no" title="function not covered"> UndirectedVertex,</span>
|
|
126
|
+
<span class="fstat-no" title="function not covered"> UndirectedEdge,</span>
|
|
127
|
+
<span class="fstat-no" title="function not covered"> UndirectedGraph,</span>
|
|
128
|
+
<span class="fstat-no" title="function not covered"> MapGraph,</span>
|
|
129
|
+
<span class="fstat-no" title="function not covered"> MapVertex,</span>
|
|
130
|
+
<span class="fstat-no" title="function not covered"> MapEdge,</span>
|
|
130
131
|
VertexId
|
|
131
132
|
} from 'data-structure-typed';
|
|
132
133
|
</pre></td></tr></table></pre>
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
136
|
+
</div><!-- /wrapper -->
|
|
137
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
138
|
+
Code coverage generated by
|
|
139
|
+
<a href="https://istanbul.js.org/" rel="noopener noreferrer" target="_blank">istanbul</a>
|
|
140
|
+
at 2023-10-08T10:22:41.687Z
|
|
141
|
+
</div>
|
|
142
|
+
<script src="prettify.js"></script>
|
|
143
|
+
<script>
|
|
144
|
+
window.onload = function () {
|
|
145
|
+
prettyPrint();
|
|
146
|
+
};
|
|
147
|
+
</script>
|
|
148
|
+
<script src="sorter.js"></script>
|
|
149
|
+
<script src="block-navigation.js"></script>
|
|
150
|
+
</body>
|
|
150
151
|
</html>
|
|
151
152
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
|
-
var addSorting = (function() {
|
|
2
|
+
var addSorting = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
var cols,
|
|
5
5
|
currentSort = {
|
|
@@ -11,14 +11,17 @@ var addSorting = (function() {
|
|
|
11
11
|
function getTable() {
|
|
12
12
|
return document.querySelector('.coverage-summary');
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
// returns the thead element of the summary table
|
|
15
16
|
function getTableHeader() {
|
|
16
17
|
return getTable().querySelector('thead tr');
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
// returns the tbody element of the summary table
|
|
19
21
|
function getTableBody() {
|
|
20
22
|
return getTable().querySelector('tbody');
|
|
21
23
|
}
|
|
24
|
+
|
|
22
25
|
// returns the th element for nth column
|
|
23
26
|
function getNthColumn(n) {
|
|
24
27
|
return getTableHeader().querySelectorAll('th')[n];
|
|
@@ -73,6 +76,7 @@ var addSorting = (function() {
|
|
|
73
76
|
}
|
|
74
77
|
return cols;
|
|
75
78
|
}
|
|
79
|
+
|
|
76
80
|
// attaches a data attribute to every tr element with an object
|
|
77
81
|
// of data values keyed by column name
|
|
78
82
|
function loadRowData(tableRow) {
|
|
@@ -93,6 +97,7 @@ var addSorting = (function() {
|
|
|
93
97
|
}
|
|
94
98
|
return data;
|
|
95
99
|
}
|
|
100
|
+
|
|
96
101
|
// loads all row data
|
|
97
102
|
function loadData() {
|
|
98
103
|
var rows = getTableBody().querySelectorAll('tr'),
|
|
@@ -102,10 +107,11 @@ var addSorting = (function() {
|
|
|
102
107
|
rows[i].data = loadRowData(rows[i]);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
110
|
+
|
|
105
111
|
// sorts the table using the data for the ith column
|
|
106
112
|
function sortByIndex(index, desc) {
|
|
107
113
|
var key = cols[index].key,
|
|
108
|
-
sorter = function(a, b) {
|
|
114
|
+
sorter = function (a, b) {
|
|
109
115
|
a = a.data[key];
|
|
110
116
|
b = b.data[key];
|
|
111
117
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -117,7 +123,7 @@ var addSorting = (function() {
|
|
|
117
123
|
i;
|
|
118
124
|
|
|
119
125
|
if (desc) {
|
|
120
|
-
finalSorter = function(a, b) {
|
|
126
|
+
finalSorter = function (a, b) {
|
|
121
127
|
return -1 * sorter(a, b);
|
|
122
128
|
};
|
|
123
129
|
}
|
|
@@ -133,6 +139,7 @@ var addSorting = (function() {
|
|
|
133
139
|
tableBody.appendChild(rows[i]);
|
|
134
140
|
}
|
|
135
141
|
}
|
|
142
|
+
|
|
136
143
|
// removes sort indicators for current column being sorted
|
|
137
144
|
function removeSortIndicators() {
|
|
138
145
|
var col = getNthColumn(currentSort.index),
|
|
@@ -141,12 +148,14 @@ var addSorting = (function() {
|
|
|
141
148
|
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
142
149
|
col.className = cls;
|
|
143
150
|
}
|
|
151
|
+
|
|
144
152
|
// adds sort indicators for current column being sorted
|
|
145
153
|
function addSortIndicators() {
|
|
146
154
|
getNthColumn(currentSort.index).className += currentSort.desc
|
|
147
155
|
? ' sorted-desc'
|
|
148
156
|
: ' sorted';
|
|
149
157
|
}
|
|
158
|
+
|
|
150
159
|
// adds event listeners for all sorter widgets
|
|
151
160
|
function enableUI() {
|
|
152
161
|
var i,
|
|
@@ -154,7 +163,7 @@ var addSorting = (function() {
|
|
|
154
163
|
ithSorter = function ithSorter(i) {
|
|
155
164
|
var col = cols[i];
|
|
156
165
|
|
|
157
|
-
return function() {
|
|
166
|
+
return function () {
|
|
158
167
|
var desc = col.defaultDescSort;
|
|
159
168
|
|
|
160
169
|
if (currentSort.index === i) {
|
|
@@ -180,8 +189,9 @@ var addSorting = (function() {
|
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
}
|
|
192
|
+
|
|
183
193
|
// adds sorting functionality to the UI
|
|
184
|
-
return function() {
|
|
194
|
+
return function () {
|
|
185
195
|
if (!getTable()) {
|
|
186
196
|
return;
|
|
187
197
|
}
|
|
@@ -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 { BFSCallback,
|
|
8
|
+
import type { BFSCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback } from '../../types';
|
|
9
9
|
import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
@@ -207,7 +207,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
207
207
|
* traverse the binary tree. It can have two possible values:
|
|
208
208
|
* @returns The function `getNodes` returns an array of nodes (`N[]`).
|
|
209
209
|
*/
|
|
210
|
-
getNodes(nodeProperty: BinaryTreeNodeKey | N, callback?:
|
|
210
|
+
getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
211
211
|
/**
|
|
212
212
|
* The function checks if a binary tree has a node with a given property or key.
|
|
213
213
|
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
|
|
@@ -225,7 +225,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
225
225
|
* performed when searching for nodes in the binary tree. It can have one of the following values:
|
|
226
226
|
* @returns a boolean value.
|
|
227
227
|
*/
|
|
228
|
-
has(nodeProperty: BinaryTreeNodeKey | N, callback?:
|
|
228
|
+
has<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): boolean;
|
|
229
229
|
/**
|
|
230
230
|
* The function `get` returns the first node in a binary tree that matches the given property or key.
|
|
231
231
|
* @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
|
|
@@ -241,7 +241,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
241
241
|
* performed when searching for a node in the binary tree. It can have one of the following values:
|
|
242
242
|
* @returns either the found node (of type N) or null if no node is found.
|
|
243
243
|
*/
|
|
244
|
-
get(nodeProperty: BinaryTreeNodeKey | N, callback?:
|
|
244
|
+
get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
|
|
245
245
|
/**
|
|
246
246
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
247
247
|
* up to the root node, with the option to reverse the order of the nodes.
|
|
@@ -310,7 +310,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
310
310
|
* performed on the binary tree. It can have two possible values:
|
|
311
311
|
* @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
|
|
312
312
|
*/
|
|
313
|
-
subTreeTraverse
|
|
313
|
+
subTreeTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): ReturnType<C>[];
|
|
314
314
|
/**
|
|
315
315
|
* The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
|
|
316
316
|
* function on each node according to a specified order pattern.
|
|
@@ -326,7 +326,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
326
326
|
* iteration used in the depth-first search algorithm. It can have two possible values:
|
|
327
327
|
* @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
|
|
328
328
|
*/
|
|
329
|
-
dfs
|
|
329
|
+
dfs<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
330
330
|
/**
|
|
331
331
|
* The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
|
|
332
332
|
* function on each node.
|
|
@@ -344,7 +344,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
344
344
|
* in the breadth-first search (BFS) algorithm. It can have two possible values:
|
|
345
345
|
* @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
|
|
346
346
|
*/
|
|
347
|
-
bfs
|
|
347
|
+
bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, withLevel?: boolean, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
348
348
|
/**
|
|
349
349
|
* The function returns the predecessor node of a given node in a binary tree.
|
|
350
350
|
* @param {N} node - The parameter "node" represents a node in a binary tree.
|
|
@@ -365,7 +365,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
365
365
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
366
366
|
* @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
|
|
367
367
|
*/
|
|
368
|
-
morris
|
|
368
|
+
morris<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
|
|
369
369
|
/**
|
|
370
370
|
* Swap the data of two nodes in the binary tree.
|
|
371
371
|
* @param {N} srcNode - The source node to swap.
|
|
@@ -380,7 +380,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
380
380
|
* the tree's structure should be restored to its original state to maintain the tree's integrity.
|
|
381
381
|
* This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
|
|
382
382
|
*/
|
|
383
|
-
protected _defaultCallbackByKey:
|
|
383
|
+
protected _defaultCallbackByKey: (node: N) => number;
|
|
384
384
|
/**
|
|
385
385
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
386
386
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
|
|
@@ -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 { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, MapCallback
|
|
8
|
+
import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, MapCallback } from '../../types';
|
|
9
9
|
import { CP, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -72,7 +72,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends Binar
|
|
|
72
72
|
* @returns either the first node that matches the given nodeProperty and callback, or null if no
|
|
73
73
|
* matching node is found.
|
|
74
74
|
*/
|
|
75
|
-
get(nodeProperty: BinaryTreeNodeKey | N, callback?:
|
|
75
|
+
get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
|
|
76
76
|
/**
|
|
77
77
|
* The function `lastKey` returns the key of the rightmost node if the comparison result is less
|
|
78
78
|
* than, the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
@@ -110,7 +110,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends Binar
|
|
|
110
110
|
* traverse the binary tree. It can have one of the following values:
|
|
111
111
|
* @returns an array of nodes (N[]).
|
|
112
112
|
*/
|
|
113
|
-
getNodes(nodeProperty: BinaryTreeNodeKey | N, callback?:
|
|
113
|
+
getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
114
114
|
/**
|
|
115
115
|
* The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
|
|
116
116
|
* nodes that have a key value lesser or greater than a target key value.
|
|
@@ -128,7 +128,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends Binar
|
|
|
128
128
|
* done recursively or iteratively. It can have two possible values:
|
|
129
129
|
* @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
|
|
130
130
|
*/
|
|
131
|
-
lesserOrGreaterTraverse
|
|
131
|
+
lesserOrGreaterTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, lesserOrGreater?: CP, targetNode?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): ReturnType<C>[];
|
|
132
132
|
/**
|
|
133
133
|
* Balancing Adjustment:
|
|
134
134
|
* Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
|
|
@@ -123,7 +123,7 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
123
123
|
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
|
|
124
124
|
* is found in the linked list. If no such node is found, it returns `null`.
|
|
125
125
|
*/
|
|
126
|
-
findNode(val: E): DoublyLinkedListNode<E> | null;
|
|
126
|
+
findNode(val: E | null): DoublyLinkedListNode<E> | null;
|
|
127
127
|
/**
|
|
128
128
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
129
129
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
@@ -229,6 +229,15 @@ export declare class DoublyLinkedList<E = any> {
|
|
|
229
229
|
reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
|
|
230
230
|
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
231
231
|
insertAfter(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
/**
|
|
233
|
+
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
234
|
+
* @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
|
|
235
|
+
* before which the new value will be inserted. It can be either the value of the existing node or the existing node
|
|
236
|
+
* itself.
|
|
237
|
+
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
|
|
238
|
+
* list.
|
|
239
|
+
* @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
240
|
+
* insertion fails.
|
|
241
|
+
*/
|
|
242
|
+
insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
234
243
|
}
|
|
@@ -88,8 +88,14 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
88
88
|
* bounds.
|
|
89
89
|
*/
|
|
90
90
|
deleteAt(index: number): E | undefined;
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
/**
|
|
92
|
+
* The delete function removes a node with a specific value from a singly linked list.
|
|
93
|
+
* @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
|
|
94
|
+
* or a `SinglyLinkedListNode<E>` object.
|
|
95
|
+
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
96
|
+
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
97
|
+
*/
|
|
98
|
+
delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean;
|
|
93
99
|
/**
|
|
94
100
|
* The `insertAt` function inserts a value at a specified index in a singly linked list.
|
|
95
101
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
@@ -143,8 +149,15 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
143
149
|
* the specified value is found, the function returns `null`.
|
|
144
150
|
*/
|
|
145
151
|
findNode(value: E): SinglyLinkedListNode<E> | null;
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
|
|
154
|
+
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
155
|
+
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
156
|
+
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
157
|
+
* @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
158
|
+
* inserted before the existing value, and `false` otherwise.
|
|
159
|
+
*/
|
|
160
|
+
insertBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
148
161
|
insertAfter(existingValueOrNode: E, newValue: E): boolean;
|
|
149
162
|
insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
150
163
|
/**
|
|
@@ -202,6 +202,8 @@ class SinglyLinkedList {
|
|
|
202
202
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
203
203
|
*/
|
|
204
204
|
delete(valueOrNode) {
|
|
205
|
+
if (!valueOrNode)
|
|
206
|
+
return false;
|
|
205
207
|
let value;
|
|
206
208
|
if (valueOrNode instanceof SinglyLinkedListNode) {
|
|
207
209
|
value = valueOrNode.val;
|
|
@@ -19,7 +19,7 @@ export declare enum FamilyPosition {
|
|
|
19
19
|
MAL_NODE = "MAL_NODE"
|
|
20
20
|
}
|
|
21
21
|
export type BinaryTreeNodeKey = number;
|
|
22
|
-
export type BFSCallback<N> = (node: N, level?: number) =>
|
|
22
|
+
export type BFSCallback<N, D = any> = (node: N, level?: number) => D;
|
|
23
23
|
export type BFSCallbackReturn<N> = ReturnType<BFSCallback<N>>;
|
|
24
24
|
export type BinaryTreeDeletedResult<N> = {
|
|
25
25
|
deleted: N | null | undefined;
|
package/dist/types/helpers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type Comparator<T> = (a: T, b: T) => number;
|
|
2
2
|
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
3
|
-
export type MapCallback<N> = (node: N) =>
|
|
3
|
+
export type MapCallback<N, D = any> = (node: N) => D;
|
|
4
4
|
export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
|
|
5
5
|
export declare enum CP {
|
|
6
6
|
lt = "lt",
|
package/jest.config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
testMatch: ['<rootDir>/test/**/*.test.ts', '<rootDir>/test/**/*.test.js'],
|
|
5
|
+
collectCoverage: true,
|
|
6
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', {skipFull: true}], "json-summary"],
|
|
7
|
+
coverageDirectory: 'coverage'
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graph-typed",
|
|
3
|
-
"version": "1.38.
|
|
3
|
+
"version": "1.38.5",
|
|
4
4
|
"description": "Graph. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -133,5 +133,8 @@
|
|
|
133
133
|
"ts-jest": "^29.1.1",
|
|
134
134
|
"typedoc": "^0.25.1",
|
|
135
135
|
"typescript": "^4.9.5"
|
|
136
|
+
},
|
|
137
|
+
"dependencies": {
|
|
138
|
+
"data-structure-typed": "^1.38.4"
|
|
136
139
|
}
|
|
137
140
|
}
|
|
@@ -152,7 +152,7 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|
|
152
152
|
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
153
153
|
switch (
|
|
154
154
|
this._balanceFactor(A) // second O(1)
|
|
155
|
-
|
|
155
|
+
) {
|
|
156
156
|
case -2:
|
|
157
157
|
if (A && A.left) {
|
|
158
158
|
if (this._balanceFactor(A.left) <= 0) {
|
|
@@ -17,7 +17,7 @@ export class BinaryIndexedTree {
|
|
|
17
17
|
* @param - - `frequency`: The default frequency value. It is optional and has a default
|
|
18
18
|
* value of 0.
|
|
19
19
|
*/
|
|
20
|
-
constructor({frequency = 0, max}: {
|
|
20
|
+
constructor({frequency = 0, max}: {frequency?: number; max: number}) {
|
|
21
21
|
this._freq = frequency;
|
|
22
22
|
this._max = max;
|
|
23
23
|
this._freqMap = {0: 0};
|