smsmslib 1.0.87 → 1.0.88
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/util/matnew.js +90 -0
- package/package.json +2 -2
package/javascr/util/matnew.js
CHANGED
|
@@ -40,11 +40,101 @@ import
|
|
|
40
40
|
}
|
|
41
41
|
from "./tree.js";
|
|
42
42
|
|
|
43
|
+
import
|
|
44
|
+
{
|
|
45
|
+
sj_deep_set_own,
|
|
46
|
+
}
|
|
47
|
+
from "./deep.js";
|
|
48
|
+
|
|
49
|
+
import
|
|
50
|
+
{
|
|
51
|
+
sj_deepwalk,
|
|
52
|
+
sj_deepwalk_path,
|
|
53
|
+
}
|
|
54
|
+
from "./deepwalk.js";
|
|
55
|
+
|
|
43
56
|
|
|
44
57
|
/** ---------------------------------------------------------------------------
|
|
45
58
|
* Functions.
|
|
46
59
|
* --------------------------------------------------------------------------- */
|
|
47
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Creates a deep copy of a matrix.
|
|
63
|
+
*
|
|
64
|
+
* @param {any} a_src [in]
|
|
65
|
+
* The source matrix to be copied. This must be a matrix structure previously
|
|
66
|
+
* created using `sj_mat_new`.
|
|
67
|
+
*
|
|
68
|
+
* @param {number[]} a_dim [in]
|
|
69
|
+
* An array of integers representing the dimensions of the matrix.
|
|
70
|
+
* This must be identical to the dimensions used to create `a_src` (though the
|
|
71
|
+
* actual instance may differ). For example, if `a_src` is a 2x3 matrix,
|
|
72
|
+
* `a_dim` must be [2, 3].
|
|
73
|
+
*
|
|
74
|
+
* @returns {any|null}
|
|
75
|
+
* A new deep-copied matrix if successful; otherwise, null if allocation or
|
|
76
|
+
* traversal fails.
|
|
77
|
+
*/
|
|
78
|
+
export function sj_mat_new_copy(a_src, a_dim)
|
|
79
|
+
{
|
|
80
|
+
let i_ret = go_tree_walk_ret.i_fatal;
|
|
81
|
+
let a_dst = sj_mat_new(a_dim, 0);
|
|
82
|
+
|
|
83
|
+
if (a_dst)
|
|
84
|
+
{
|
|
85
|
+
i_ret = sj_deepwalk(a_src, a_dim.length + 1, mat_new_copy_cb, a_dst);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (i_ret !== go_tree_walk_ret.i_ok)
|
|
89
|
+
{
|
|
90
|
+
a_dst = null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return a_dst;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Callback function for deeply copying matrix elements during a deep walk.
|
|
99
|
+
* This function is intended to be used as a callback for `sj_deepwalk`.
|
|
100
|
+
*
|
|
101
|
+
* @param {Object[]} ao_TreeStack [in]
|
|
102
|
+
* The current traversal stack from `sj_deepwalk`, containing node information.
|
|
103
|
+
*
|
|
104
|
+
* @param {number} i_depth [in]
|
|
105
|
+
* The current depth of the traversal.
|
|
106
|
+
* - 1 indicates the root element.
|
|
107
|
+
* - In a 2D matrix (array of arrays), 3 represents a leaf node (the actual value).
|
|
108
|
+
*
|
|
109
|
+
* @param {any} a_dst [in,out]
|
|
110
|
+
* The destination matrix (object or array) where values will be copied.
|
|
111
|
+
* The structure must be pre-allocated.
|
|
112
|
+
*
|
|
113
|
+
* @returns {boolean}
|
|
114
|
+
* true to continue the traversal; false if a path could not be resolved.
|
|
115
|
+
*/
|
|
116
|
+
function mat_new_copy_cb(ao_TreeStack, i_depth, a_dst)
|
|
117
|
+
{
|
|
118
|
+
let b_continue = true;
|
|
119
|
+
|
|
120
|
+
if (i_depth === ao_TreeStack.length)
|
|
121
|
+
{
|
|
122
|
+
const o_TreeStack = ao_TreeStack.at(- 1); /* tail */
|
|
123
|
+
const src = o_TreeStack.node.value;
|
|
124
|
+
const as_path = sj_deepwalk_path(ao_TreeStack);
|
|
125
|
+
|
|
126
|
+
b_continue = !!as_path;
|
|
127
|
+
|
|
128
|
+
if (b_continue)
|
|
129
|
+
{
|
|
130
|
+
b_continue = sj_deep_set_own(a_dst, as_path, src);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return b_continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
48
138
|
/**
|
|
49
139
|
* Creates a multi-dimensional array (matrix) with specified dimensions.
|
|
50
140
|
* This function constructs a nested array structure based on the provided
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smsmslib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.88",
|
|
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.88"
|
|
23
23
|
}
|
|
24
24
|
}
|