linked-list-typed 1.38.2 → 1.38.4
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 +15 -3
- package/coverage/clover.xml +11 -7
- package/coverage/coverage-final.json +165 -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 +39 -36
- 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/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/singly-linked-list.ts +1 -1
- 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'>5/5</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'>1/4</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'>1/1</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>
|
|
@@ -71,7 +71,8 @@
|
|
|
71
71
|
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
72
|
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
73
|
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
-
<a name='L9'></a><a href='#L9'>9</a></td><td class="line-coverage quiet"><span
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a></td><td class="line-coverage quiet"><span
|
|
75
|
+
class="cline-any cline-neutral"> </span>
|
|
75
76
|
<span class="cline-any cline-neutral"> </span>
|
|
76
77
|
<span class="cline-any cline-neutral"> </span>
|
|
77
78
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -86,24 +87,26 @@
|
|
|
86
87
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
87
88
|
* @license MIT License
|
|
88
89
|
*/
|
|
89
|
-
export { <span class="fstat-no" title="function not covered"
|
|
90
|
+
export { <span class="fstat-no" title="function not covered">DoublyLinkedListNode,</span> <span class="fstat-no"
|
|
91
|
+
title="function not covered">DoublyLinkedList,</span> <span
|
|
92
|
+
class="fstat-no" title="function not covered">SinglyLinkedListNode,</span> SinglyLinkedList } from 'data-structure-typed';
|
|
90
93
|
</pre></td></tr></table></pre>
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
95
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
96
|
+
</div><!-- /wrapper -->
|
|
97
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
98
|
+
Code coverage generated by
|
|
99
|
+
<a href="https://istanbul.js.org/" rel="noopener noreferrer" target="_blank">istanbul</a>
|
|
100
|
+
at 2023-10-08T10:22:55.211Z
|
|
101
|
+
</div>
|
|
102
|
+
<script src="prettify.js"></script>
|
|
103
|
+
<script>
|
|
104
|
+
window.onload = function () {
|
|
105
|
+
prettyPrint();
|
|
106
|
+
};
|
|
107
|
+
</script>
|
|
108
|
+
<script src="sorter.js"></script>
|
|
109
|
+
<script src="block-navigation.js"></script>
|
|
110
|
+
</body>
|
|
108
111
|
</html>
|
|
109
112
|
|
|
@@ -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.
|
|
@@ -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": "linked-list-typed",
|
|
3
|
-
"version": "1.38.
|
|
3
|
+
"version": "1.38.4",
|
|
4
4
|
"description": "Linked List, Doubly Linked List, Singly Linked List. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -64,5 +64,8 @@
|
|
|
64
64
|
"ts-jest": "^29.1.1",
|
|
65
65
|
"typedoc": "^0.25.1",
|
|
66
66
|
"typescript": "^4.9.5"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"data-structure-typed": "^1.38.4"
|
|
67
70
|
}
|
|
68
71
|
}
|
|
@@ -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};
|
|
@@ -407,7 +407,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
407
407
|
return -1;
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
const stack: {
|
|
410
|
+
const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}];
|
|
411
411
|
let maxHeight = 0;
|
|
412
412
|
|
|
413
413
|
while (stack.length > 0) {
|
|
@@ -512,9 +512,9 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
512
512
|
* traverse the binary tree. It can have two possible values:
|
|
513
513
|
* @returns The function `getNodes` returns an array of nodes (`N[]`).
|
|
514
514
|
*/
|
|
515
|
-
getNodes(
|
|
515
|
+
getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
516
516
|
nodeProperty: BinaryTreeNodeKey | N,
|
|
517
|
-
callback:
|
|
517
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
518
518
|
onlyOne = false,
|
|
519
519
|
beginRoot: N | null = this.root,
|
|
520
520
|
iterationType = this.iterationType
|
|
@@ -570,9 +570,9 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
570
570
|
* performed when searching for nodes in the binary tree. It can have one of the following values:
|
|
571
571
|
* @returns a boolean value.
|
|
572
572
|
*/
|
|
573
|
-
has(
|
|
573
|
+
has<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
574
574
|
nodeProperty: BinaryTreeNodeKey | N,
|
|
575
|
-
callback:
|
|
575
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
576
576
|
beginRoot = this.root,
|
|
577
577
|
iterationType = this.iterationType
|
|
578
578
|
): boolean {
|
|
@@ -595,9 +595,9 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
595
595
|
* performed when searching for a node in the binary tree. It can have one of the following values:
|
|
596
596
|
* @returns either the found node (of type N) or null if no node is found.
|
|
597
597
|
*/
|
|
598
|
-
get(
|
|
598
|
+
get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
599
599
|
nodeProperty: BinaryTreeNodeKey | N,
|
|
600
|
-
callback:
|
|
600
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
601
601
|
beginRoot = this.root,
|
|
602
602
|
iterationType = this.iterationType
|
|
603
603
|
): N | null {
|
|
@@ -761,11 +761,11 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
761
761
|
* performed on the binary tree. It can have two possible values:
|
|
762
762
|
* @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
|
|
763
763
|
*/
|
|
764
|
-
subTreeTraverse(
|
|
765
|
-
callback:
|
|
764
|
+
subTreeTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
765
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
766
766
|
beginRoot: N | BinaryTreeNodeKey | null = this.root,
|
|
767
767
|
iterationType = this.iterationType
|
|
768
|
-
):
|
|
768
|
+
): ReturnType<C>[] {
|
|
769
769
|
if (typeof beginRoot === 'number') beginRoot = this.get(beginRoot);
|
|
770
770
|
|
|
771
771
|
const ans: MapCallbackReturn<N>[] = [];
|
|
@@ -808,12 +808,12 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
808
808
|
* iteration used in the depth-first search algorithm. It can have two possible values:
|
|
809
809
|
* @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
|
|
810
810
|
*/
|
|
811
|
-
dfs(
|
|
812
|
-
callback:
|
|
811
|
+
dfs<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
812
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
813
813
|
pattern: DFSOrderPattern = 'in',
|
|
814
814
|
beginRoot: N | null = this.root,
|
|
815
815
|
iterationType: IterationType = IterationType.ITERATIVE
|
|
816
|
-
):
|
|
816
|
+
): ReturnType<C>[] {
|
|
817
817
|
if (!beginRoot) return [];
|
|
818
818
|
const ans: MapCallbackReturn<N>[] = [];
|
|
819
819
|
if (iterationType === IterationType.RECURSIVE) {
|
|
@@ -842,7 +842,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
842
842
|
_traverse(beginRoot);
|
|
843
843
|
} else {
|
|
844
844
|
// 0: visit, 1: print
|
|
845
|
-
const stack: {
|
|
845
|
+
const stack: {opt: 0 | 1; node: N | null | undefined}[] = [{opt: 0, node: beginRoot}];
|
|
846
846
|
|
|
847
847
|
while (stack.length > 0) {
|
|
848
848
|
const cur = stack.pop();
|
|
@@ -896,12 +896,12 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
896
896
|
* in the breadth-first search (BFS) algorithm. It can have two possible values:
|
|
897
897
|
* @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
|
|
898
898
|
*/
|
|
899
|
-
bfs(
|
|
900
|
-
callback:
|
|
899
|
+
bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(
|
|
900
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
901
901
|
withLevel: boolean = false,
|
|
902
902
|
beginRoot: N | null = this.root,
|
|
903
903
|
iterationType = this.iterationType
|
|
904
|
-
):
|
|
904
|
+
): ReturnType<C>[] {
|
|
905
905
|
if (!beginRoot) return [];
|
|
906
906
|
|
|
907
907
|
const ans: BFSCallbackReturn<N>[] = [];
|
|
@@ -964,11 +964,11 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
964
964
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
965
965
|
* @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
|
|
966
966
|
*/
|
|
967
|
-
morris(
|
|
968
|
-
callback:
|
|
967
|
+
morris<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
968
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
969
969
|
pattern: DFSOrderPattern = 'in',
|
|
970
970
|
beginRoot: N | null = this.root
|
|
971
|
-
):
|
|
971
|
+
): ReturnType<C>[] {
|
|
972
972
|
if (beginRoot === null) return [];
|
|
973
973
|
const ans: MapCallbackReturn<N>[] = [];
|
|
974
974
|
|
|
@@ -1078,7 +1078,7 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
|
|
|
1078
1078
|
* This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
|
|
1079
1079
|
*/
|
|
1080
1080
|
|
|
1081
|
-
protected _defaultCallbackByKey:
|
|
1081
|
+
protected _defaultCallbackByKey: (node: N) => number = node => node.key;
|
|
1082
1082
|
|
|
1083
1083
|
/**
|
|
1084
1084
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
@@ -238,9 +238,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
|
|
|
238
238
|
* @returns either the first node that matches the given nodeProperty and callback, or null if no
|
|
239
239
|
* matching node is found.
|
|
240
240
|
*/
|
|
241
|
-
override get(
|
|
241
|
+
override get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
242
242
|
nodeProperty: BinaryTreeNodeKey | N,
|
|
243
|
-
callback:
|
|
243
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
244
244
|
beginRoot = this.root,
|
|
245
245
|
iterationType = this.iterationType
|
|
246
246
|
): N | null {
|
|
@@ -289,9 +289,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
|
|
|
289
289
|
* traverse the binary tree. It can have one of the following values:
|
|
290
290
|
* @returns an array of nodes (N[]).
|
|
291
291
|
*/
|
|
292
|
-
override getNodes(
|
|
292
|
+
override getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
293
293
|
nodeProperty: BinaryTreeNodeKey | N,
|
|
294
|
-
callback:
|
|
294
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
295
295
|
onlyOne = false,
|
|
296
296
|
beginRoot: N | null = this.root,
|
|
297
297
|
iterationType = this.iterationType
|
|
@@ -363,12 +363,12 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
|
|
|
363
363
|
* done recursively or iteratively. It can have two possible values:
|
|
364
364
|
* @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
|
|
365
365
|
*/
|
|
366
|
-
lesserOrGreaterTraverse(
|
|
367
|
-
callback:
|
|
366
|
+
lesserOrGreaterTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(
|
|
367
|
+
callback: C = this._defaultCallbackByKey as C,
|
|
368
368
|
lesserOrGreater: CP = CP.lt,
|
|
369
369
|
targetNode: N | BinaryTreeNodeKey | null = this.root,
|
|
370
370
|
iterationType = this.iterationType
|
|
371
|
-
):
|
|
371
|
+
): ReturnType<C>[] {
|
|
372
372
|
if (typeof targetNode === 'number') targetNode = this.get(targetNode);
|
|
373
373
|
const ans: MapCallbackReturn<N>[] = [];
|
|
374
374
|
if (!targetNode) return ans;
|
|
@@ -37,7 +37,8 @@ export class TreeMultisetNode<
|
|
|
37
37
|
*/
|
|
38
38
|
export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultisetNode>
|
|
39
39
|
extends AVLTree<N>
|
|
40
|
-
implements IBinaryTree<N>
|
|
40
|
+
implements IBinaryTree<N>
|
|
41
|
+
{
|
|
41
42
|
/**
|
|
42
43
|
* The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
|
|
43
44
|
* merge duplicated values.
|