min-heap-typed 1.49.4 → 1.49.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/dist/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -13
- package/dist/data-structures/binary-tree/binary-tree.js +19 -49
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/data-structures/binary-tree/tree-multimap.js +1 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/data-structures/graph/abstract-graph.js +3 -2
- package/dist/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/data-structures/hash/hash-map.js +2 -2
- package/dist/data-structures/heap/heap.js +2 -3
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/matrix/index.d.ts +0 -2
- package/dist/data-structures/matrix/index.js +0 -2
- package/dist/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/data-structures/matrix/matrix.js +400 -15
- package/dist/data-structures/queue/deque.d.ts +2 -2
- package/dist/data-structures/queue/deque.js +5 -7
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +6 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +15 -8
- package/src/data-structures/binary-tree/binary-tree.ts +57 -74
- package/src/data-structures/binary-tree/bst.ts +16 -13
- package/src/data-structures/binary-tree/rb-tree.ts +16 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
- package/src/data-structures/graph/abstract-graph.ts +13 -11
- package/src/data-structures/graph/directed-graph.ts +1 -3
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +3 -6
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +7 -2
- package/src/types/common.ts +4 -4
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/dist/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/data-structures/matrix/matrix2d.js +0 -199
- package/dist/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/data-structures/matrix/vector2d.js +0 -290
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from
|
|
1
|
+
import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';
|
|
2
2
|
export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
3
3
|
/**
|
|
4
4
|
* Time Complexity: O(n)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNExemplar, BTNKeyOrNode, DFSOrderPattern, EntryCallback, NodeDisplayLayout } from '../../types';
|
|
9
9
|
import { FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
|
-
import { IterableEntryBase } from
|
|
11
|
+
import { IterableEntryBase } from '../base';
|
|
12
12
|
/**
|
|
13
13
|
* Represents a node in a binary tree.
|
|
14
14
|
* @template V - The type of data stored in the node.
|
|
@@ -542,18 +542,6 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
542
542
|
* @returns The method is returning the newNode.
|
|
543
543
|
*/
|
|
544
544
|
protected _replaceNode(oldNode: N, newNode: N): N;
|
|
545
|
-
/**
|
|
546
|
-
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
547
|
-
* @param {N | null | undefined} newNode - The `newNode` parameter represents the node that you want to add to
|
|
548
|
-
* the binary tree. It can be either a node object or `null`.
|
|
549
|
-
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will
|
|
550
|
-
* be added as a child.
|
|
551
|
-
* @returns either the left or right child node of the parent node, depending on which child is
|
|
552
|
-
* available for adding the new node. If a new node is added, the function also updates the size of
|
|
553
|
-
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
554
|
-
* If the parent node is null, the function also returns undefined.
|
|
555
|
-
*/
|
|
556
|
-
protected _addTo(newNode: N | null | undefined, parent: BTNKeyOrNode<K, N>): N | null | undefined;
|
|
557
545
|
/**
|
|
558
546
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
559
547
|
* it also sets the parent property of the value to undefined.
|
|
@@ -80,7 +80,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
80
80
|
super();
|
|
81
81
|
this.iterationType = types_1.IterationType.ITERATIVE;
|
|
82
82
|
this._extractor = (key) => Number(key);
|
|
83
|
-
this._defaultOneParamCallback = (node) => node ? node.key : undefined;
|
|
83
|
+
this._defaultOneParamCallback = (node) => (node ? node.key : undefined);
|
|
84
84
|
if (options) {
|
|
85
85
|
const { iterationType, extractor } = options;
|
|
86
86
|
if (iterationType) {
|
|
@@ -1594,21 +1594,30 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1594
1594
|
function _buildNodeDisplay(line, width, left, right) {
|
|
1595
1595
|
const [leftLines, leftWidth, leftHeight, leftMiddle] = left;
|
|
1596
1596
|
const [rightLines, rightWidth, rightHeight, rightMiddle] = right;
|
|
1597
|
-
const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1))
|
|
1598
|
-
|
|
1599
|
-
+
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
const secondLine = (leftHeight > 0
|
|
1603
|
-
+ ' '.repeat(
|
|
1604
|
-
|
|
1597
|
+
const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1)) +
|
|
1598
|
+
'_'.repeat(Math.max(0, leftWidth - leftMiddle - 1)) +
|
|
1599
|
+
line +
|
|
1600
|
+
'_'.repeat(Math.max(0, rightMiddle)) +
|
|
1601
|
+
' '.repeat(Math.max(0, rightWidth - rightMiddle));
|
|
1602
|
+
const secondLine = (leftHeight > 0
|
|
1603
|
+
? ' '.repeat(leftMiddle) + '/' + ' '.repeat(leftWidth - leftMiddle - 1)
|
|
1604
|
+
: ' '.repeat(leftWidth)) +
|
|
1605
|
+
' '.repeat(width) +
|
|
1606
|
+
(rightHeight > 0
|
|
1607
|
+
? ' '.repeat(rightMiddle) + '\\' + ' '.repeat(rightWidth - rightMiddle - 1)
|
|
1608
|
+
: ' '.repeat(rightWidth));
|
|
1605
1609
|
const mergedLines = [firstLine, secondLine];
|
|
1606
1610
|
for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
|
|
1607
1611
|
const leftLine = i < leftHeight ? leftLines[i] : ' '.repeat(leftWidth);
|
|
1608
1612
|
const rightLine = i < rightHeight ? rightLines[i] : ' '.repeat(rightWidth);
|
|
1609
1613
|
mergedLines.push(leftLine + ' '.repeat(width) + rightLine);
|
|
1610
1614
|
}
|
|
1611
|
-
return [
|
|
1615
|
+
return [
|
|
1616
|
+
mergedLines,
|
|
1617
|
+
leftWidth + width + rightWidth,
|
|
1618
|
+
Math.max(leftHeight, rightHeight) + 2,
|
|
1619
|
+
leftWidth + Math.floor(width / 2)
|
|
1620
|
+
];
|
|
1612
1621
|
}
|
|
1613
1622
|
}
|
|
1614
1623
|
/**
|
|
@@ -1658,45 +1667,6 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1658
1667
|
}
|
|
1659
1668
|
return newNode;
|
|
1660
1669
|
}
|
|
1661
|
-
/**
|
|
1662
|
-
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
1663
|
-
* @param {N | null | undefined} newNode - The `newNode` parameter represents the node that you want to add to
|
|
1664
|
-
* the binary tree. It can be either a node object or `null`.
|
|
1665
|
-
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will
|
|
1666
|
-
* be added as a child.
|
|
1667
|
-
* @returns either the left or right child node of the parent node, depending on which child is
|
|
1668
|
-
* available for adding the new node. If a new node is added, the function also updates the size of
|
|
1669
|
-
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
1670
|
-
* If the parent node is null, the function also returns undefined.
|
|
1671
|
-
*/
|
|
1672
|
-
_addTo(newNode, parent) {
|
|
1673
|
-
if (this.isNotNodeInstance(parent))
|
|
1674
|
-
parent = this.getNode(parent);
|
|
1675
|
-
if (parent) {
|
|
1676
|
-
// When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
|
|
1677
|
-
// In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
|
|
1678
|
-
if (parent.left === undefined) {
|
|
1679
|
-
parent.left = newNode;
|
|
1680
|
-
if (newNode) {
|
|
1681
|
-
this._size = this.size + 1;
|
|
1682
|
-
}
|
|
1683
|
-
return parent.left;
|
|
1684
|
-
}
|
|
1685
|
-
else if (parent.right === undefined) {
|
|
1686
|
-
parent.right = newNode;
|
|
1687
|
-
if (newNode) {
|
|
1688
|
-
this._size = this.size + 1;
|
|
1689
|
-
}
|
|
1690
|
-
return parent.right;
|
|
1691
|
-
}
|
|
1692
|
-
else {
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
else {
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
1670
|
/**
|
|
1701
1671
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
1702
1672
|
* it also sets the parent property of the value to undefined.
|
|
@@ -163,22 +163,6 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
|
|
|
163
163
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
164
164
|
*/
|
|
165
165
|
clone(): TREE;
|
|
166
|
-
/**
|
|
167
|
-
* Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
|
|
168
|
-
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
169
|
-
*
|
|
170
|
-
* The function adds a new node to a binary tree, either as the left child or the right child of a
|
|
171
|
-
* given parent node.
|
|
172
|
-
* @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
|
|
173
|
-
* added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
|
|
174
|
-
* `undefined` if there is no node to add.
|
|
175
|
-
* @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
|
|
176
|
-
* which the new node will be added as a child. It can be either a node object (`N`) or a key value
|
|
177
|
-
* (`K`).
|
|
178
|
-
* @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
|
|
179
|
-
* added, or `undefined` if no node was added.
|
|
180
|
-
*/
|
|
181
|
-
protected _addTo(newNode: N | undefined, parent: BSTNKeyOrNode<K, N>): N | undefined;
|
|
182
166
|
/**
|
|
183
167
|
* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
|
|
184
168
|
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
|
|
@@ -33,7 +33,7 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
33
33
|
// TODO the _count is not accurate after nodes count modified
|
|
34
34
|
get count() {
|
|
35
35
|
let sum = 0;
|
|
36
|
-
this.subTreeTraverse(node => sum += node.count);
|
|
36
|
+
this.subTreeTraverse(node => (sum += node.count));
|
|
37
37
|
return sum;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -312,48 +312,6 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
312
312
|
this.bfs(node => cloned.add(node.key, node.value, node.count));
|
|
313
313
|
return cloned;
|
|
314
314
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
|
|
317
|
-
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
318
|
-
*
|
|
319
|
-
* The function adds a new node to a binary tree, either as the left child or the right child of a
|
|
320
|
-
* given parent node.
|
|
321
|
-
* @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
|
|
322
|
-
* added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
|
|
323
|
-
* `undefined` if there is no node to add.
|
|
324
|
-
* @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
|
|
325
|
-
* which the new node will be added as a child. It can be either a node object (`N`) or a key value
|
|
326
|
-
* (`K`).
|
|
327
|
-
* @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
|
|
328
|
-
* added, or `undefined` if no node was added.
|
|
329
|
-
*/
|
|
330
|
-
_addTo(newNode, parent) {
|
|
331
|
-
parent = this.ensureNode(parent);
|
|
332
|
-
if (parent) {
|
|
333
|
-
if (parent.left === undefined) {
|
|
334
|
-
parent.left = newNode;
|
|
335
|
-
if (newNode !== undefined) {
|
|
336
|
-
this._size = this.size + 1;
|
|
337
|
-
this._count += newNode.count;
|
|
338
|
-
}
|
|
339
|
-
return parent.left;
|
|
340
|
-
}
|
|
341
|
-
else if (parent.right === undefined) {
|
|
342
|
-
parent.right = newNode;
|
|
343
|
-
if (newNode !== undefined) {
|
|
344
|
-
this._size = this.size + 1;
|
|
345
|
-
this._count += newNode.count;
|
|
346
|
-
}
|
|
347
|
-
return parent.right;
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
315
|
/**
|
|
358
316
|
* The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
|
|
359
317
|
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { DijkstraResult, EntryCallback, VertexKey } from '../../types';
|
|
9
|
-
import { IterableEntryBase } from
|
|
9
|
+
import { IterableEntryBase } from '../base';
|
|
10
10
|
import { IGraph } from '../../interfaces';
|
|
11
11
|
export declare abstract class AbstractVertex<V = any> {
|
|
12
12
|
key: VertexKey;
|
|
@@ -95,7 +95,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
95
95
|
}
|
|
96
96
|
isVertexKey(potentialKey) {
|
|
97
97
|
const potentialKeyType = typeof potentialKey;
|
|
98
|
-
return potentialKeyType ===
|
|
98
|
+
return potentialKeyType === 'string' || potentialKeyType === 'number';
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
@@ -1015,7 +1015,8 @@ class AbstractGraph extends base_1.IterableEntryBase {
|
|
|
1015
1015
|
const visited = new Set();
|
|
1016
1016
|
const dfs = (vertex, currentPath, visited) => {
|
|
1017
1017
|
if (visited.has(vertex)) {
|
|
1018
|
-
if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) &&
|
|
1018
|
+
if (((!isInclude2Cycle && currentPath.length > 2) || (isInclude2Cycle && currentPath.length >= 2)) &&
|
|
1019
|
+
currentPath[0] === vertex.key) {
|
|
1019
1020
|
cycles.push([...currentPath]);
|
|
1020
1021
|
}
|
|
1021
1022
|
return;
|
|
@@ -121,7 +121,7 @@ export declare class HashMap<K = any, V = any> extends IterableEntryBase<K, V> {
|
|
|
121
121
|
*/
|
|
122
122
|
protected _getIterator(): IterableIterator<[K, V]>;
|
|
123
123
|
protected _hashFn: (key: K) => string;
|
|
124
|
-
protected _isObjKey(key: any): key is
|
|
124
|
+
protected _isObjKey(key: any): key is object | ((...args: any[]) => any);
|
|
125
125
|
protected _getNoObjKey(key: K): string;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
@@ -219,11 +219,11 @@ class HashMap extends base_1.IterableEntryBase {
|
|
|
219
219
|
_getNoObjKey(key) {
|
|
220
220
|
const keyType = typeof key;
|
|
221
221
|
let strKey;
|
|
222
|
-
if (keyType !==
|
|
222
|
+
if (keyType !== 'string' && keyType !== 'number' && keyType !== 'symbol') {
|
|
223
223
|
strKey = this._hashFn(key);
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
226
|
-
if (keyType ===
|
|
226
|
+
if (keyType === 'number') {
|
|
227
227
|
// TODO numeric key should has its own hash
|
|
228
228
|
strKey = key;
|
|
229
229
|
}
|
|
@@ -401,11 +401,10 @@ class Heap extends base_1.IterableElementBase {
|
|
|
401
401
|
_sinkDown(index, halfLength) {
|
|
402
402
|
const element = this.elements[index];
|
|
403
403
|
while (index < halfLength) {
|
|
404
|
-
let left = index << 1 | 1;
|
|
404
|
+
let left = (index << 1) | 1;
|
|
405
405
|
const right = left + 1;
|
|
406
406
|
let minItem = this.elements[left];
|
|
407
|
-
if (right < this.elements.length &&
|
|
408
|
-
this.options.comparator(minItem, this.elements[right]) > 0) {
|
|
407
|
+
if (right < this.elements.length && this.options.comparator(minItem, this.elements[right]) > 0) {
|
|
409
408
|
left = right;
|
|
410
409
|
minItem = this.elements[right];
|
|
411
410
|
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { ElementCallback } from
|
|
9
|
-
import { IterableElementBase } from
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
10
10
|
export declare class SinglyLinkedListNode<E = any> {
|
|
11
11
|
value: E;
|
|
12
12
|
next: SinglyLinkedListNode<E> | undefined;
|
|
@@ -15,6 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./matrix"), exports);
|
|
18
|
-
__exportStar(require("./vector2d"), exports);
|
|
19
|
-
__exportStar(require("./matrix2d"), exports);
|
|
20
18
|
__exportStar(require("./navigator"), exports);
|
|
@@ -5,17 +5,135 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
9
|
-
protected readonly _matrix: Array<Array<V>>;
|
|
8
|
+
export declare class Matrix {
|
|
10
9
|
/**
|
|
11
|
-
* The constructor
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
10
|
+
* The constructor function initializes a matrix object with the provided data and options, or with
|
|
11
|
+
* default values if no options are provided.
|
|
12
|
+
* @param {number[][]} data - A 2D array of numbers representing the data for the matrix.
|
|
13
|
+
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
14
|
+
* properties:
|
|
14
15
|
*/
|
|
15
|
-
constructor(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
constructor(data: number[][], options?: {
|
|
17
|
+
rows?: number;
|
|
18
|
+
cols?: number;
|
|
19
|
+
addFn?: (a: number, b: number) => any;
|
|
20
|
+
subtractFn?: (a: number, b: number) => any;
|
|
21
|
+
multiplyFn?: (a: number, b: number) => any;
|
|
19
22
|
});
|
|
20
|
-
|
|
23
|
+
protected _rows: number;
|
|
24
|
+
get rows(): number;
|
|
25
|
+
protected _cols: number;
|
|
26
|
+
get cols(): number;
|
|
27
|
+
protected _data: number[][];
|
|
28
|
+
get data(): number[][];
|
|
29
|
+
get addFn(): (a: number | undefined, b: number) => number | undefined;
|
|
30
|
+
get subtractFn(): (a: number, b: number) => number;
|
|
31
|
+
get multiplyFn(): (a: number, b: number) => number;
|
|
32
|
+
/**
|
|
33
|
+
* The `get` function returns the value at the specified row and column index if it is a valid index.
|
|
34
|
+
* @param {number} row - The `row` parameter represents the row index of the element you want to
|
|
35
|
+
* retrieve from the data array.
|
|
36
|
+
* @param {number} col - The parameter "col" represents the column number of the element you want to
|
|
37
|
+
* retrieve from the data array.
|
|
38
|
+
* @returns The `get` function returns a number if the provided row and column indices are valid.
|
|
39
|
+
* Otherwise, it returns `undefined`.
|
|
40
|
+
*/
|
|
41
|
+
get(row: number, col: number): number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The set function updates the value at a specified row and column in a two-dimensional array.
|
|
44
|
+
* @param {number} row - The "row" parameter represents the row index of the element in a
|
|
45
|
+
* two-dimensional array or matrix. It specifies the row where the value will be set.
|
|
46
|
+
* @param {number} col - The "col" parameter represents the column index of the element in a
|
|
47
|
+
* two-dimensional array.
|
|
48
|
+
* @param {number} value - The value parameter represents the number that you want to set at the
|
|
49
|
+
* specified row and column in the data array.
|
|
50
|
+
* @returns a boolean value. It returns true if the index (row, col) is valid and the value is
|
|
51
|
+
* successfully set in the data array. It returns false if the index is invalid and the value is not
|
|
52
|
+
* set.
|
|
53
|
+
*/
|
|
54
|
+
set(row: number, col: number, value: number): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The function checks if the dimensions of the given matrix match the dimensions of the current
|
|
57
|
+
* matrix.
|
|
58
|
+
* @param {Matrix} matrix - The parameter `matrix` is of type `Matrix`.
|
|
59
|
+
* @returns a boolean value.
|
|
60
|
+
*/
|
|
61
|
+
isMatchForCalculate(matrix: Matrix): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The `add` function adds two matrices together, returning a new matrix with the result.
|
|
64
|
+
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
65
|
+
* @returns The `add` method returns a new `Matrix` object that represents the result of adding the
|
|
66
|
+
* current matrix with the provided `matrix` parameter.
|
|
67
|
+
*/
|
|
68
|
+
add(matrix: Matrix): Matrix | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The `subtract` function performs element-wise subtraction between two matrices and returns a new
|
|
71
|
+
* matrix with the result.
|
|
72
|
+
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class. It
|
|
73
|
+
* represents the matrix that you want to subtract from the current matrix.
|
|
74
|
+
* @returns a new Matrix object with the result of the subtraction operation.
|
|
75
|
+
*/
|
|
76
|
+
subtract(matrix: Matrix): Matrix | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The `multiply` function performs matrix multiplication between two matrices and returns the result
|
|
79
|
+
* as a new matrix.
|
|
80
|
+
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
81
|
+
* @returns a new Matrix object.
|
|
82
|
+
*/
|
|
83
|
+
multiply(matrix: Matrix): Matrix | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* The transpose function takes a matrix and returns a new matrix that is the transpose of the
|
|
86
|
+
* original matrix.
|
|
87
|
+
* @returns The transpose() function returns a new Matrix object with the transposed data.
|
|
88
|
+
*/
|
|
89
|
+
transpose(): Matrix;
|
|
90
|
+
/**
|
|
91
|
+
* The `inverse` function calculates the inverse of a square matrix using Gaussian elimination.
|
|
92
|
+
* @returns a Matrix object, which represents the inverse of the original matrix.
|
|
93
|
+
*/
|
|
94
|
+
inverse(): Matrix | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* The dot function calculates the dot product of two matrices and returns a new matrix.
|
|
97
|
+
* @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
|
|
98
|
+
* @returns a new Matrix object.
|
|
99
|
+
*/
|
|
100
|
+
dot(matrix: Matrix): Matrix | undefined;
|
|
101
|
+
protected _addFn(a: number | undefined, b: number): number | undefined;
|
|
102
|
+
protected _subtractFn(a: number, b: number): number;
|
|
103
|
+
protected _multiplyFn(a: number, b: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* The function checks if a given row and column index is valid within a specified range.
|
|
106
|
+
* @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
|
|
107
|
+
* matrix. It is a number that indicates the specific row in the matrix.
|
|
108
|
+
* @param {number} col - The "col" parameter represents the column index in a two-dimensional array
|
|
109
|
+
* or grid. It is used to check if the given column index is valid within the bounds of the grid.
|
|
110
|
+
* @returns A boolean value is being returned.
|
|
111
|
+
*/
|
|
112
|
+
protected isValidIndex(row: number, col: number): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The function `_swapRows` swaps the positions of two rows in an array.
|
|
115
|
+
* @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.
|
|
116
|
+
* @param {number} row2 - The `row2` parameter is the index of the second row that you want to swap
|
|
117
|
+
* with the first row.
|
|
118
|
+
*/
|
|
119
|
+
protected _swapRows(row1: number, row2: number): void;
|
|
120
|
+
/**
|
|
121
|
+
* The function scales a specific row in a matrix by a given scalar value.
|
|
122
|
+
* @param {number} row - The `row` parameter represents the index of the row in the matrix that you
|
|
123
|
+
* want to scale. It is a number that indicates the position of the row within the matrix.
|
|
124
|
+
* @param {number} scalar - The scalar parameter is a number that is used to multiply each element in
|
|
125
|
+
* a specific row of a matrix.
|
|
126
|
+
*/
|
|
127
|
+
protected _scaleRow(row: number, scalar: number): void;
|
|
128
|
+
/**
|
|
129
|
+
* The function `_addScaledRow` multiplies a row in a matrix by a scalar value and adds it to another
|
|
130
|
+
* row.
|
|
131
|
+
* @param {number} targetRow - The targetRow parameter represents the index of the row in which the
|
|
132
|
+
* scaled values will be added.
|
|
133
|
+
* @param {number} sourceRow - The sourceRow parameter represents the index of the row from which the
|
|
134
|
+
* values will be scaled and added to the targetRow.
|
|
135
|
+
* @param {number} scalar - The scalar parameter is a number that is used to scale the values in the
|
|
136
|
+
* source row before adding them to the target row.
|
|
137
|
+
*/
|
|
138
|
+
protected _addScaledRow(targetRow: number, sourceRow: number, scalar: number): void;
|
|
21
139
|
}
|