data-structure-typed 1.49.3 → 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.
Files changed (162) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +70 -69
  3. package/README_zh-CN.md +44 -49
  4. package/benchmark/report.html +16 -16
  5. package/benchmark/report.json +187 -187
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  15. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
  16. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -11
  18. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -19
  19. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/directed-graph.js +4 -0
  21. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  22. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  24. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  25. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  26. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/heap.js +2 -3
  28. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  29. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  31. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  32. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  33. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  34. package/dist/cjs/data-structures/matrix/index.js +0 -2
  35. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  36. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  37. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  38. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  39. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  40. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  41. package/dist/cjs/data-structures/queue/deque.js +5 -7
  42. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  43. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  44. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  45. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  46. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  47. package/dist/cjs/utils/utils.d.ts +1 -0
  48. package/dist/cjs/utils/utils.js +6 -1
  49. package/dist/cjs/utils/utils.js.map +1 -1
  50. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  51. package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
  52. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
  53. package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
  54. package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
  55. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
  56. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  57. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
  58. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -11
  59. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -20
  60. package/dist/mjs/data-structures/graph/directed-graph.js +4 -0
  61. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  62. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  63. package/dist/mjs/data-structures/heap/heap.js +2 -3
  64. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  65. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  66. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  67. package/dist/mjs/data-structures/matrix/index.js +0 -2
  68. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  69. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  70. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  71. package/dist/mjs/data-structures/queue/deque.js +7 -9
  72. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  73. package/dist/mjs/data-structures/queue/queue.js +1 -1
  74. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  75. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  76. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  77. package/dist/mjs/utils/utils.d.ts +1 -0
  78. package/dist/mjs/utils/utils.js +4 -0
  79. package/dist/umd/data-structure-typed.js +361 -542
  80. package/dist/umd/data-structure-typed.min.js +2 -2
  81. package/dist/umd/data-structure-typed.min.js.map +1 -1
  82. package/package.json +4 -3
  83. package/src/data-structures/base/index.ts +1 -1
  84. package/src/data-structures/base/iterable-base.ts +7 -10
  85. package/src/data-structures/binary-tree/avl-tree.ts +15 -8
  86. package/src/data-structures/binary-tree/binary-tree.ts +57 -74
  87. package/src/data-structures/binary-tree/bst.ts +16 -13
  88. package/src/data-structures/binary-tree/rb-tree.ts +16 -10
  89. package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
  90. package/src/data-structures/graph/abstract-graph.ts +14 -24
  91. package/src/data-structures/graph/directed-graph.ts +8 -6
  92. package/src/data-structures/graph/map-graph.ts +6 -1
  93. package/src/data-structures/graph/undirected-graph.ts +4 -7
  94. package/src/data-structures/hash/hash-map.ts +18 -16
  95. package/src/data-structures/heap/heap.ts +7 -10
  96. package/src/data-structures/heap/max-heap.ts +2 -1
  97. package/src/data-structures/heap/min-heap.ts +2 -1
  98. package/src/data-structures/linked-list/singly-linked-list.ts +3 -5
  99. package/src/data-structures/matrix/index.ts +0 -2
  100. package/src/data-structures/matrix/matrix.ts +442 -13
  101. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  102. package/src/data-structures/queue/deque.ts +18 -39
  103. package/src/data-structures/queue/queue.ts +1 -1
  104. package/src/interfaces/binary-tree.ts +7 -2
  105. package/src/types/common.ts +4 -4
  106. package/src/types/data-structures/base/base.ts +14 -3
  107. package/src/types/data-structures/base/index.ts +1 -1
  108. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  109. package/src/types/data-structures/hash/hash-map.ts +3 -3
  110. package/src/types/data-structures/heap/heap.ts +2 -2
  111. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  112. package/src/utils/utils.ts +7 -1
  113. package/test/integration/avl-tree.test.ts +18 -1
  114. package/test/integration/bst.test.ts +2 -2
  115. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
  116. package/test/performance/data-structures/comparison/comparison.test.ts +18 -23
  117. package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
  118. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -28
  119. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
  120. package/test/performance/data-structures/queue/deque.test.ts +11 -12
  121. package/test/performance/data-structures/queue/queue.test.ts +15 -14
  122. package/test/performance/data-structures/stack/stack.test.ts +11 -11
  123. package/test/performance/reportor.ts +14 -15
  124. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  125. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -15
  126. package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
  127. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  128. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  129. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  130. package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
  131. package/test/unit/data-structures/graph/directed-graph.test.ts +112 -40
  132. package/test/unit/data-structures/graph/undirected-graph.test.ts +63 -33
  133. package/test/unit/data-structures/hash/hash-map.test.ts +64 -23
  134. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  135. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  136. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  137. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -4
  138. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  139. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  140. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  141. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  142. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  143. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  144. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  145. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  146. package/test/utils/big-o.ts +14 -14
  147. package/test/utils/performanc.ts +1 -1
  148. package/typedoc.json +30 -0
  149. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  150. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  151. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  152. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  153. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  154. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  155. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  156. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  157. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  158. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  159. package/src/data-structures/matrix/matrix2d.ts +0 -211
  160. package/src/data-structures/matrix/vector2d.ts +0 -315
  161. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  162. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -1 +1 @@
1
- {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF;AAbD,oDAaC;AAED,MAAa,gBAA0B,SAAQ,0BAAsB;IACnE;;OAEG;IACH,YAAY,QAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,EAAE,IAAI,QAAQ;gBACvB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IAEH;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAI,IAAS;QAC3B,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAK,CAAC;QACnD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,gBAAgB,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;QACzD,MAAM,YAAY,GAAG,IAAI,gBAAgB,EAAK,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAGD;;;OAGG;IACH;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAI,QAA+B,EAAE,OAAa;QACnD,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAK,CAAC;QAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAEQ,CAAE,YAAY;QACrB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AA3tBD,4CA2tBC"}
1
+ {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,SAAS,CA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AI,gBAAgB,EAAK,CAAC;QAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAEQ,CAAE,YAAY;QACrB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAztBD,4CAytBC"}
@@ -1,4 +1,2 @@
1
1
  export * from './matrix';
2
- export * from './vector2d';
3
- export * from './matrix2d';
4
2
  export * from './navigator';
@@ -15,7 +15,5 @@ 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);
21
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-structures/matrix/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,6CAA2B;AAC3B,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-structures/matrix/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B"}
@@ -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 MatrixNTI2D<V = any> {
9
- protected readonly _matrix: Array<Array<V>>;
8
+ export declare class Matrix {
10
9
  /**
11
- * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
12
- * given initial value or 0 if not provided.
13
- * @param options - An object containing the following properties:
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(options: {
16
- row: number;
17
- col: number;
18
- initialVal?: V;
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
- toArray(): Array<Array<V>>;
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
  }
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MatrixNTI2D = void 0;
4
2
  /**
5
3
  * data-structure-typed
6
4
  *
@@ -8,22 +6,409 @@ exports.MatrixNTI2D = void 0;
8
6
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
7
  * @license MIT License
10
8
  */
11
- // todo need to be improved
12
- class MatrixNTI2D {
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Matrix = void 0;
11
+ class Matrix {
13
12
  /**
14
- * The constructor creates a matrix with the specified number of rows and columns, and initializes all elements to a
15
- * given initial value or 0 if not provided.
16
- * @param options - An object containing the following properties:
13
+ * The constructor function initializes a matrix object with the provided data and options, or with
14
+ * default values if no options are provided.
15
+ * @param {number[][]} data - A 2D array of numbers representing the data for the matrix.
16
+ * @param [options] - The `options` parameter is an optional object that can contain the following
17
+ * properties:
17
18
  */
18
- constructor(options) {
19
- const { row, col, initialVal } = options;
20
- this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0));
19
+ constructor(data, options) {
20
+ var _a, _b, _c;
21
+ this._rows = 0;
22
+ this._cols = 0;
23
+ if (options) {
24
+ const { rows, cols, addFn, subtractFn, multiplyFn } = options;
25
+ if (typeof rows === 'number' && rows > 0)
26
+ this._rows = rows;
27
+ else
28
+ this._rows = data.length;
29
+ if (typeof cols === 'number' && cols > 0)
30
+ this._cols = cols;
31
+ else
32
+ this._cols = ((_a = data[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
33
+ if (addFn)
34
+ this._addFn = addFn;
35
+ if (subtractFn)
36
+ this._subtractFn = subtractFn;
37
+ if (multiplyFn)
38
+ this._multiplyFn = multiplyFn;
39
+ }
40
+ else {
41
+ this._rows = data.length;
42
+ this._cols = (_c = (_b = data[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
43
+ }
44
+ if (data.length > 0) {
45
+ this._data = data;
46
+ }
47
+ else {
48
+ this._data = [];
49
+ for (let i = 0; i < this.rows; i++) {
50
+ this._data[i] = new Array(this.cols).fill(0);
51
+ }
52
+ }
53
+ }
54
+ get rows() {
55
+ return this._rows;
56
+ }
57
+ get cols() {
58
+ return this._cols;
59
+ }
60
+ get data() {
61
+ return this._data;
62
+ }
63
+ get addFn() {
64
+ return this._addFn;
65
+ }
66
+ get subtractFn() {
67
+ return this._subtractFn;
21
68
  }
22
- /* The `toArray` method returns the matrix as a two-dimensional array. It converts the internal representation of the
23
- matrix, which is an array of arrays, into a format that is more commonly used in JavaScript. */
24
- toArray() {
25
- return this._matrix;
69
+ get multiplyFn() {
70
+ return this._multiplyFn;
71
+ }
72
+ /**
73
+ * The `get` function returns the value at the specified row and column index if it is a valid index.
74
+ * @param {number} row - The `row` parameter represents the row index of the element you want to
75
+ * retrieve from the data array.
76
+ * @param {number} col - The parameter "col" represents the column number of the element you want to
77
+ * retrieve from the data array.
78
+ * @returns The `get` function returns a number if the provided row and column indices are valid.
79
+ * Otherwise, it returns `undefined`.
80
+ */
81
+ get(row, col) {
82
+ if (this.isValidIndex(row, col)) {
83
+ return this.data[row][col];
84
+ }
85
+ }
86
+ /**
87
+ * The set function updates the value at a specified row and column in a two-dimensional array.
88
+ * @param {number} row - The "row" parameter represents the row index of the element in a
89
+ * two-dimensional array or matrix. It specifies the row where the value will be set.
90
+ * @param {number} col - The "col" parameter represents the column index of the element in a
91
+ * two-dimensional array.
92
+ * @param {number} value - The value parameter represents the number that you want to set at the
93
+ * specified row and column in the data array.
94
+ * @returns a boolean value. It returns true if the index (row, col) is valid and the value is
95
+ * successfully set in the data array. It returns false if the index is invalid and the value is not
96
+ * set.
97
+ */
98
+ set(row, col, value) {
99
+ if (this.isValidIndex(row, col)) {
100
+ this.data[row][col] = value;
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ /**
106
+ * The function checks if the dimensions of the given matrix match the dimensions of the current
107
+ * matrix.
108
+ * @param {Matrix} matrix - The parameter `matrix` is of type `Matrix`.
109
+ * @returns a boolean value.
110
+ */
111
+ isMatchForCalculate(matrix) {
112
+ return this.rows === matrix.rows && this.cols === matrix.cols;
113
+ }
114
+ /**
115
+ * The `add` function adds two matrices together, returning a new matrix with the result.
116
+ * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
117
+ * @returns The `add` method returns a new `Matrix` object that represents the result of adding the
118
+ * current matrix with the provided `matrix` parameter.
119
+ */
120
+ add(matrix) {
121
+ if (!this.isMatchForCalculate(matrix)) {
122
+ throw new Error('Matrix dimensions must match for addition.');
123
+ }
124
+ const resultData = [];
125
+ for (let i = 0; i < this.rows; i++) {
126
+ resultData[i] = [];
127
+ for (let j = 0; j < this.cols; j++) {
128
+ const a = this.get(i, j), b = matrix.get(i, j);
129
+ if (a !== undefined && b !== undefined) {
130
+ const added = this._addFn(a, b);
131
+ if (added) {
132
+ resultData[i][j] = added;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ return new Matrix(resultData, {
138
+ rows: this.rows,
139
+ cols: this.cols,
140
+ addFn: this.addFn,
141
+ subtractFn: this.subtractFn,
142
+ multiplyFn: this.multiplyFn
143
+ });
144
+ }
145
+ /**
146
+ * The `subtract` function performs element-wise subtraction between two matrices and returns a new
147
+ * matrix with the result.
148
+ * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class. It
149
+ * represents the matrix that you want to subtract from the current matrix.
150
+ * @returns a new Matrix object with the result of the subtraction operation.
151
+ */
152
+ subtract(matrix) {
153
+ if (!this.isMatchForCalculate(matrix)) {
154
+ throw new Error('Matrix dimensions must match for subtraction.');
155
+ }
156
+ const resultData = [];
157
+ for (let i = 0; i < this.rows; i++) {
158
+ resultData[i] = [];
159
+ for (let j = 0; j < this.cols; j++) {
160
+ const a = this.get(i, j), b = matrix.get(i, j);
161
+ if (a !== undefined && b !== undefined) {
162
+ const subtracted = this._subtractFn(a, b);
163
+ if (subtracted) {
164
+ resultData[i][j] = subtracted;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return new Matrix(resultData, {
170
+ rows: this.rows,
171
+ cols: this.cols,
172
+ addFn: this.addFn,
173
+ subtractFn: this.subtractFn,
174
+ multiplyFn: this.multiplyFn
175
+ });
176
+ }
177
+ /**
178
+ * The `multiply` function performs matrix multiplication between two matrices and returns the result
179
+ * as a new matrix.
180
+ * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
181
+ * @returns a new Matrix object.
182
+ */
183
+ multiply(matrix) {
184
+ if (this.cols !== matrix.rows) {
185
+ throw new Error('Matrix dimensions must be compatible for multiplication (A.cols = B.rows).');
186
+ }
187
+ const resultData = [];
188
+ for (let i = 0; i < this.rows; i++) {
189
+ resultData[i] = [];
190
+ for (let j = 0; j < matrix.cols; j++) {
191
+ let sum;
192
+ for (let k = 0; k < this.cols; k++) {
193
+ const a = this.get(i, k), b = matrix.get(k, j);
194
+ if (a !== undefined && b !== undefined) {
195
+ const multiplied = this.multiplyFn(a, b);
196
+ if (multiplied !== undefined) {
197
+ sum = this.addFn(sum, multiplied);
198
+ }
199
+ }
200
+ }
201
+ if (sum !== undefined)
202
+ resultData[i][j] = sum;
203
+ }
204
+ }
205
+ return new Matrix(resultData, {
206
+ rows: this.rows,
207
+ cols: matrix.cols,
208
+ addFn: this.addFn,
209
+ subtractFn: this.subtractFn,
210
+ multiplyFn: this.multiplyFn
211
+ });
212
+ }
213
+ /**
214
+ * The transpose function takes a matrix and returns a new matrix that is the transpose of the
215
+ * original matrix.
216
+ * @returns The transpose() function returns a new Matrix object with the transposed data.
217
+ */
218
+ transpose() {
219
+ if (this.data.some(row => row.length !== this.rows)) {
220
+ throw new Error('Matrix must be rectangular for transposition.');
221
+ }
222
+ const resultData = [];
223
+ for (let j = 0; j < this.cols; j++) {
224
+ resultData[j] = [];
225
+ for (let i = 0; i < this.rows; i++) {
226
+ const trans = this.get(i, j);
227
+ if (trans !== undefined)
228
+ resultData[j][i] = trans;
229
+ }
230
+ }
231
+ return new Matrix(resultData, {
232
+ rows: this.cols,
233
+ cols: this.rows,
234
+ addFn: this.addFn,
235
+ subtractFn: this.subtractFn,
236
+ multiplyFn: this.multiplyFn
237
+ });
238
+ }
239
+ /**
240
+ * The `inverse` function calculates the inverse of a square matrix using Gaussian elimination.
241
+ * @returns a Matrix object, which represents the inverse of the original matrix.
242
+ */
243
+ inverse() {
244
+ var _a;
245
+ // Check if the matrix is square
246
+ if (this.rows !== this.cols) {
247
+ throw new Error('Matrix must be square for inversion.');
248
+ }
249
+ // Create an augmented matrix [this | I]
250
+ const augmentedMatrixData = [];
251
+ for (let i = 0; i < this.rows; i++) {
252
+ augmentedMatrixData[i] = this.data[i].slice(); // Copy the original matrix
253
+ for (let j = 0; j < this.cols; j++) {
254
+ augmentedMatrixData[i][this.cols + j] = i === j ? 1 : 0; // Append the identity matrix
255
+ }
256
+ }
257
+ const augmentedMatrix = new Matrix(augmentedMatrixData, {
258
+ rows: this.rows,
259
+ cols: this.cols * 2,
260
+ addFn: this.addFn,
261
+ subtractFn: this.subtractFn,
262
+ multiplyFn: this.multiplyFn
263
+ });
264
+ // Apply Gaussian elimination to transform the left half into the identity matrix
265
+ for (let i = 0; i < this.rows; i++) {
266
+ // Find pivot
267
+ let pivotRow = i;
268
+ while (pivotRow < this.rows && augmentedMatrix.get(pivotRow, i) === 0) {
269
+ pivotRow++;
270
+ }
271
+ if (pivotRow === this.rows) {
272
+ // Matrix is singular, and its inverse does not exist
273
+ throw new Error('Matrix is singular, and its inverse does not exist.');
274
+ }
275
+ // Swap rows to make the pivot the current row
276
+ augmentedMatrix._swapRows(i, pivotRow);
277
+ // Scale the pivot row to make the pivot element 1
278
+ const pivotElement = (_a = augmentedMatrix.get(i, i)) !== null && _a !== void 0 ? _a : 1;
279
+ if (pivotElement === 0) {
280
+ // Handle division by zero
281
+ throw new Error('Matrix is singular, and its inverse does not exist (division by zero).');
282
+ }
283
+ augmentedMatrix._scaleRow(i, 1 / pivotElement);
284
+ // Eliminate other rows to make elements in the current column zero
285
+ for (let j = 0; j < this.rows; j++) {
286
+ if (j !== i) {
287
+ let factor = augmentedMatrix.get(j, i);
288
+ if (factor === undefined)
289
+ factor = 0;
290
+ augmentedMatrix._addScaledRow(j, i, -factor);
291
+ }
292
+ }
293
+ }
294
+ // Extract the right half of the augmented matrix as the inverse
295
+ const inverseData = [];
296
+ for (let i = 0; i < this.rows; i++) {
297
+ inverseData[i] = augmentedMatrix.data[i].slice(this.cols);
298
+ }
299
+ return new Matrix(inverseData, {
300
+ rows: this.rows,
301
+ cols: this.cols,
302
+ addFn: this.addFn,
303
+ subtractFn: this.subtractFn,
304
+ multiplyFn: this.multiplyFn
305
+ });
306
+ }
307
+ /**
308
+ * The dot function calculates the dot product of two matrices and returns a new matrix.
309
+ * @param {Matrix} matrix - The `matrix` parameter is an instance of the `Matrix` class.
310
+ * @returns a new Matrix object.
311
+ */
312
+ dot(matrix) {
313
+ if (this.cols !== matrix.rows) {
314
+ throw new Error('Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.');
315
+ }
316
+ const resultData = [];
317
+ for (let i = 0; i < this.rows; i++) {
318
+ resultData[i] = [];
319
+ for (let j = 0; j < matrix.cols; j++) {
320
+ let sum;
321
+ for (let k = 0; k < this.cols; k++) {
322
+ const a = this.get(i, k), b = matrix.get(k, j);
323
+ if (a !== undefined && b !== undefined) {
324
+ const multiplied = this.multiplyFn(a, b);
325
+ if (multiplied !== undefined) {
326
+ sum = this.addFn(sum, multiplied);
327
+ }
328
+ }
329
+ }
330
+ if (sum !== undefined)
331
+ resultData[i][j] = sum;
332
+ }
333
+ }
334
+ return new Matrix(resultData, {
335
+ rows: this.rows,
336
+ cols: matrix.cols,
337
+ addFn: this.addFn,
338
+ subtractFn: this.subtractFn,
339
+ multiplyFn: this.multiplyFn
340
+ });
341
+ }
342
+ _addFn(a, b) {
343
+ if (a === undefined)
344
+ return b;
345
+ return a + b;
346
+ }
347
+ _subtractFn(a, b) {
348
+ return a - b;
349
+ }
350
+ _multiplyFn(a, b) {
351
+ return a * b;
352
+ }
353
+ /**
354
+ * The function checks if a given row and column index is valid within a specified range.
355
+ * @param {number} row - The `row` parameter represents the row index of a two-dimensional array or
356
+ * matrix. It is a number that indicates the specific row in the matrix.
357
+ * @param {number} col - The "col" parameter represents the column index in a two-dimensional array
358
+ * or grid. It is used to check if the given column index is valid within the bounds of the grid.
359
+ * @returns A boolean value is being returned.
360
+ */
361
+ isValidIndex(row, col) {
362
+ return row >= 0 && row < this.rows && col >= 0 && col < this.cols;
363
+ }
364
+ /**
365
+ * The function `_swapRows` swaps the positions of two rows in an array.
366
+ * @param {number} row1 - The `row1` parameter is the index of the first row that you want to swap.
367
+ * @param {number} row2 - The `row2` parameter is the index of the second row that you want to swap
368
+ * with the first row.
369
+ */
370
+ _swapRows(row1, row2) {
371
+ const temp = this.data[row1];
372
+ this.data[row1] = this.data[row2];
373
+ this.data[row2] = temp;
374
+ }
375
+ /**
376
+ * The function scales a specific row in a matrix by a given scalar value.
377
+ * @param {number} row - The `row` parameter represents the index of the row in the matrix that you
378
+ * want to scale. It is a number that indicates the position of the row within the matrix.
379
+ * @param {number} scalar - The scalar parameter is a number that is used to multiply each element in
380
+ * a specific row of a matrix.
381
+ */
382
+ _scaleRow(row, scalar) {
383
+ for (let j = 0; j < this.cols; j++) {
384
+ let multiplied = this.multiplyFn(this.data[row][j], scalar);
385
+ if (multiplied === undefined)
386
+ multiplied = 0;
387
+ this.data[row][j] = multiplied;
388
+ }
389
+ }
390
+ /**
391
+ * The function `_addScaledRow` multiplies a row in a matrix by a scalar value and adds it to another
392
+ * row.
393
+ * @param {number} targetRow - The targetRow parameter represents the index of the row in which the
394
+ * scaled values will be added.
395
+ * @param {number} sourceRow - The sourceRow parameter represents the index of the row from which the
396
+ * values will be scaled and added to the targetRow.
397
+ * @param {number} scalar - The scalar parameter is a number that is used to scale the values in the
398
+ * source row before adding them to the target row.
399
+ */
400
+ _addScaledRow(targetRow, sourceRow, scalar) {
401
+ for (let j = 0; j < this.cols; j++) {
402
+ let multiplied = this.multiplyFn(this.data[sourceRow][j], scalar);
403
+ if (multiplied === undefined)
404
+ multiplied = 0;
405
+ const scaledValue = multiplied;
406
+ let added = this.addFn(this.data[targetRow][j], scaledValue);
407
+ if (added === undefined)
408
+ added = 0;
409
+ this.data[targetRow][j] = added;
410
+ }
26
411
  }
27
412
  }
28
- exports.MatrixNTI2D = MatrixNTI2D;
413
+ exports.Matrix = Matrix;
29
414
  //# sourceMappingURL=matrix.js.map