smsmslib 1.0.59 → 1.0.64
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/javascr/system/matnew.js +69 -0
- package/package.json +2 -2
package/javascr/system/matnew.js
CHANGED
|
@@ -21,6 +21,24 @@ from "./array.js";
|
|
|
21
21
|
* Functions.
|
|
22
22
|
* --------------------------------------------------------------------------- */
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Creates a multi-dimensional array (matrix) with specified dimensions.
|
|
26
|
+
* This function constructs a nested array structure based on the provided
|
|
27
|
+
* dimension arguments.
|
|
28
|
+
*
|
|
29
|
+
* @param {...number} ai_dim [in]
|
|
30
|
+
* A variable number of arguments defining the size of each dimension.
|
|
31
|
+
* For example, `sj_mat_new(2, 3)` creates a 2x3 matrix. All arguments
|
|
32
|
+
* must be positive integers.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Array | null}
|
|
35
|
+
* A new multi-dimensional array initialized with 0 at the deepest level.
|
|
36
|
+
* Returns `null` if any dimension is invalid or if allocation fails.
|
|
37
|
+
*
|
|
38
|
+
* @see mat_new_init
|
|
39
|
+
* @see mat_new_push
|
|
40
|
+
* @see mat_new_pop
|
|
41
|
+
*/
|
|
24
42
|
export function sj_mat_new(...ai_dim)
|
|
25
43
|
{
|
|
26
44
|
let a_mat = null;
|
|
@@ -48,6 +66,20 @@ export function sj_mat_new(...ai_dim)
|
|
|
48
66
|
}
|
|
49
67
|
|
|
50
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Validates matrix dimensions and initializes the root array.
|
|
71
|
+
* This function ensures that `ai_dim` contains only positive integers.
|
|
72
|
+
* If valid, it creates and returns the first-order (root) array.
|
|
73
|
+
*
|
|
74
|
+
* @param {number[]} ai_dim [in]
|
|
75
|
+
* An array where `ai_dim[n]` represents the size of the n-th order dimension.
|
|
76
|
+
* Must contain at least one element, and all elements must be positive integers.
|
|
77
|
+
*
|
|
78
|
+
* @returns {Array | null}
|
|
79
|
+
* A new empty array for the first dimension if validation passes.
|
|
80
|
+
* Returns `null` if `ai_dim` is empty, contains invalid dimensions,
|
|
81
|
+
* or if array allocation fails.
|
|
82
|
+
*/
|
|
51
83
|
function mat_new_init(ai_dim)
|
|
52
84
|
{
|
|
53
85
|
let a_mat = null;
|
|
@@ -67,6 +99,22 @@ function mat_new_init(ai_dim)
|
|
|
67
99
|
}
|
|
68
100
|
|
|
69
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new empty array for a deeper dimension and pushes the current
|
|
104
|
+
* array `a_mat` onto the stack.
|
|
105
|
+
*
|
|
106
|
+
* @param {Array<Array>} aa_stack [in/out]
|
|
107
|
+
* A stack used to store parent array references as the construction
|
|
108
|
+
* moves to deeper dimensions.
|
|
109
|
+
*
|
|
110
|
+
* @param {Array} a_mat [in]
|
|
111
|
+
* The current array level that will now act as a parent to the
|
|
112
|
+
* newly created array.
|
|
113
|
+
*
|
|
114
|
+
* @returns {Array | null}
|
|
115
|
+
* The newly created array instance (the new current level).
|
|
116
|
+
* Returns `null` if array creation or pushing fails.
|
|
117
|
+
*/
|
|
70
118
|
function mat_new_push(aa_stack, a_mat)
|
|
71
119
|
{
|
|
72
120
|
const a_push = sj_array_new(0, 0);
|
|
@@ -90,6 +138,27 @@ function mat_new_push(aa_stack, a_mat)
|
|
|
90
138
|
}
|
|
91
139
|
|
|
92
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Pops the stack to find the next available parent level after a_mat
|
|
143
|
+
* has been fully populated.
|
|
144
|
+
*
|
|
145
|
+
* This function repeatedly executes `a_mat = aa_stack.pop()` until the
|
|
146
|
+
* condition `a_mat.length < ai_dim[aa_stack.length]` is met, ensuring
|
|
147
|
+
* the returned array has space for the next element at its specific depth.
|
|
148
|
+
*
|
|
149
|
+
* @param {Array<Array>} aa_stack [in/out]
|
|
150
|
+
* A stack containing references to the parent arrays of `a_mat`.
|
|
151
|
+
*
|
|
152
|
+
* @param {Array} a_mat [in]
|
|
153
|
+
* The current array level having been populated.
|
|
154
|
+
*
|
|
155
|
+
* @param {number[]} ai_dim [in]
|
|
156
|
+
* An array where `ai_dim[n]` represents the size of the n-th order dimension.
|
|
157
|
+
*
|
|
158
|
+
* @returns {Array}
|
|
159
|
+
* The parent array of `a_mat` that has available capacity.
|
|
160
|
+
* Returns `a_mat` as is if no popping was necessary.
|
|
161
|
+
*/
|
|
93
162
|
function mat_new_pop(aa_stack, a_mat, ai_dim)
|
|
94
163
|
{
|
|
95
164
|
let a_mat_now = a_mat;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smsmslib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.64",
|
|
4
4
|
"description": "Reusable functions for me.",
|
|
5
5
|
"files": [
|
|
6
6
|
"javascr/**/*.js",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"smsmslib": "^1.0.
|
|
22
|
+
"smsmslib": "^1.0.64"
|
|
23
23
|
}
|
|
24
24
|
}
|