smsmslib 1.0.86 → 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.
@@ -50,6 +50,12 @@ import
50
50
  }
51
51
  from "./tree.js";
52
52
 
53
+ import
54
+ {
55
+ sj_deep_get_own,
56
+ }
57
+ from "./deep.js";
58
+
53
59
 
54
60
  /** ---------------------------------------------------------------------------
55
61
  * Functions.
@@ -73,7 +79,7 @@ from "./tree.js";
73
79
  * The user-defined callback function called at each node.
74
80
  * Expected signature: `f_cb(ao_TreeStack, i_depth, user)`
75
81
  * - ao_TreeStack: The current traversal stack.
76
- * - i_depth: The maximum depth limit passed to `sj_deep_walk`.
82
+ * - i_depth: The maximum depth limit passed to `sj_deepwalk`.
77
83
  * - user: The user data provided.
78
84
  * Must return `true` to continue or `false` to abort.
79
85
  *
@@ -84,7 +90,7 @@ from "./tree.js";
84
90
  * Status code defined in `go_tree_walk_ret`. Same as `sj_tree_walk`.
85
91
  * @see sj_tree_walk
86
92
  */
87
- export function sj_deep_walk(value, i_depth, f_cb, user)
93
+ export function sj_deepwalk(value, i_depth, f_cb, user)
88
94
  {
89
95
  let i_ret = go_tree_walk_ret.i_noncb;
90
96
 
@@ -96,11 +102,11 @@ export function sj_deep_walk(value, i_depth, f_cb, user)
96
102
 
97
103
  if (o_user)
98
104
  {
99
- const o_root = deep_walk_node_t(value);
105
+ const o_root = deepwalk_node_t(value);
100
106
 
101
107
  if (o_root)
102
108
  {
103
- i_ret = sj_tree_walk(deep_walk_cb, o_root, o_user);
109
+ i_ret = sj_tree_walk(deepwalk_cb, o_root, o_user);
104
110
  }
105
111
  }
106
112
  }
@@ -114,7 +120,7 @@ export function sj_deep_walk(value, i_depth, f_cb, user)
114
120
  *
115
121
  * This function serves two primary purposes:
116
122
  * 1. **Node Adaptation**: It wraps the next child value into a node object
117
- * using `deep_walk_node_t` for the next step of traversal.
123
+ * using `deepwalk_node_t` for the next step of traversal.
118
124
  * 2. **User Callback Execution**: It triggers the user-provided callback
119
125
  * (`o_user.f_cb`) in "leading order".
120
126
  *
@@ -133,7 +139,7 @@ export function sj_deep_walk(value, i_depth, f_cb, user)
133
139
  * @returns {boolean}
134
140
  * true to continue the traversal; otherwise false to abort.
135
141
  */
136
- function deep_walk_cb(ao_TreeStack, from_child, o_user)
142
+ function deepwalk_cb(ao_TreeStack, from_child, o_user)
137
143
  {
138
144
  let b_continue = true;
139
145
  const b_depth = (o_user.i_depth < 1) || (ao_TreeStack.length <= o_user.i_depth);
@@ -146,7 +152,7 @@ function deep_walk_cb(ao_TreeStack, from_child, o_user)
146
152
  {
147
153
  const s_key = o_node.as_key[o_TreeStack.i_child];
148
154
 
149
- o_TreeStack.child = deep_walk_node_t(o_node.value[s_key]);
155
+ o_TreeStack.child = deepwalk_node_t(o_node.value[s_key]);
150
156
  b_continue &&= (!!o_TreeStack.child);
151
157
  }
152
158
 
@@ -165,7 +171,7 @@ function deep_walk_cb(ao_TreeStack, from_child, o_user)
165
171
  *
166
172
  * This function reconstructs the path by iterating through the tree stack
167
173
  * from the root up to the parent of the current node. It is designed to be
168
- * called within a callback of `sj_deep_walk`.
174
+ * called within a callback of `sj_deepwalk`.
169
175
  *
170
176
  * Since the last element of `ao_TreeStack` represents the current node itself,
171
177
  * this function collects keys from all elements except the last to form the
@@ -179,7 +185,7 @@ function deep_walk_cb(ao_TreeStack, from_child, o_user)
179
185
  * otherwise null if the stack is invalid or an internal error occurs.
180
186
  * Note: Returns an empty array if the current node is the root.
181
187
  */
182
- export function sj_deep_path(ao_TreeStack)
188
+ export function sj_deepwalk_path(ao_TreeStack)
183
189
  {
184
190
  let as_path = sj_array_new(0);
185
191
  const b_arr = Array.isArray(ao_TreeStack);
@@ -228,7 +234,7 @@ export function sj_deep_path(ao_TreeStack)
228
234
  * otherwise null.
229
235
  * Returns null if the node object cannot be created.
230
236
  */
231
- function deep_walk_node_t(value)
237
+ function deepwalk_node_t(value)
232
238
  {
233
239
  let o_node = null;
234
240
  let as_key = null;
@@ -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.86",
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.86"
22
+ "smsmslib": "^1.0.88"
23
23
  }
24
24
  }