nv-facutil-slct-ta 1.1.3 → 1.1.4
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/index.js +112 -43
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8,6 +8,80 @@ const tcate = (o)=> {
|
|
|
8
8
|
return 'other'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// 判断是否为有符号整数类型(包括大整数)
|
|
12
|
+
const is_signed_int_cls = (TypedArrayClass) => {
|
|
13
|
+
return (
|
|
14
|
+
TypedArrayClass === Int8Array ||
|
|
15
|
+
TypedArrayClass === Int16Array ||
|
|
16
|
+
TypedArrayClass === Int32Array ||
|
|
17
|
+
TypedArrayClass === BigInt64Array // 有符号大整数(64位)
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// 判断是否为无符号整数类型(包括大整数和 clamped 类型)
|
|
22
|
+
const is_unsigned_int_cls = (TypedArrayClass) => {
|
|
23
|
+
return (
|
|
24
|
+
TypedArrayClass === Uint8Array || // 无符号8位整数
|
|
25
|
+
TypedArrayClass === Uint8ClampedArray || // 无符号8位钳位整数(特殊无符号)
|
|
26
|
+
TypedArrayClass === Uint16Array || // 无符号16位整数
|
|
27
|
+
TypedArrayClass === Uint32Array || // 无符号32位整数
|
|
28
|
+
TypedArrayClass === BigUint64Array // 无符号大整数(64位)
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function get_display_name_prefix(TypedArrayClass) {
|
|
33
|
+
const byteSize = TypedArrayClass.BYTES_PER_ELEMENT;
|
|
34
|
+
// 判断是否为有符号类型(需要添加"Half"前缀)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// 基础名称映射
|
|
38
|
+
let baseName;
|
|
39
|
+
if (byteSize === 1) {
|
|
40
|
+
baseName = "Tiny";
|
|
41
|
+
} else if (byteSize === 2) {
|
|
42
|
+
baseName = "Small";
|
|
43
|
+
} else if (byteSize === 4) {
|
|
44
|
+
baseName = "Normal";
|
|
45
|
+
} else {
|
|
46
|
+
baseName = "Large";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 有符号类型添加"Half"前缀
|
|
50
|
+
return is_signed_int_cls(TypedArrayClass) ? `Half${baseName}` : baseName;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DUMP_ONE_BYTE_TYPE_MP = {
|
|
54
|
+
0: Uint8Array,
|
|
55
|
+
1: Uint16Array,
|
|
56
|
+
2: Uint32Array,
|
|
57
|
+
3: BigUint64Array, // js version NOT supported
|
|
58
|
+
//-----------------------------------------------------
|
|
59
|
+
4: Int8Array,
|
|
60
|
+
5: Int16Array,
|
|
61
|
+
6: Int32Array,
|
|
62
|
+
7: BigInt64Array, // js version NOT supported
|
|
63
|
+
255: Float64Array,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const CLS2BYT = new Map([
|
|
67
|
+
[Uint8Array,0],
|
|
68
|
+
[Uint16Array,1],
|
|
69
|
+
[Uint32Array,2],
|
|
70
|
+
[BigUint64Array,3],
|
|
71
|
+
//-----------------------------------------------------------
|
|
72
|
+
[Int8Array,4],
|
|
73
|
+
[Int16Array,5],
|
|
74
|
+
[Int32Array,6],
|
|
75
|
+
[BigInt64Array,7],
|
|
76
|
+
[Float64Array,255]
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
11
85
|
|
|
12
86
|
|
|
13
87
|
////
|
|
@@ -137,24 +211,44 @@ function to_u8avw(ta) {
|
|
|
137
211
|
function cp_rtrn_u8a(ta) {return to_u8avw(ta).slice(0)}
|
|
138
212
|
|
|
139
213
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
214
|
+
function calc_max_incr_cnt(Cls, curr_cnt) {
|
|
215
|
+
// 处理 Float64Array
|
|
216
|
+
if (Cls === Float64Array) {
|
|
217
|
+
return Number.MAX_SAFE_INTEGER - curr_cnt; // 2^53-1 是最大安全整数
|
|
218
|
+
}
|
|
219
|
+
// 处理 BigUint64Array
|
|
220
|
+
else if (Cls === BigUint64Array) {
|
|
221
|
+
const n = 8n * BigInt(Cls.BYTES_PER_ELEMENT); // 64
|
|
222
|
+
const limit = 2n ** n; // 2^64
|
|
223
|
+
return limit - 1n- BigInt(curr_cnt);
|
|
224
|
+
}
|
|
225
|
+
// 处理有符号整数类型
|
|
226
|
+
else if (Cls === Int8Array) {
|
|
227
|
+
return 127 - curr_cnt; // 2^7 - 1
|
|
228
|
+
}
|
|
229
|
+
else if (Cls === Int16Array) {
|
|
230
|
+
return 32767 - curr_cnt; // 2^15 - 1
|
|
231
|
+
}
|
|
232
|
+
else if (Cls === Int32Array) {
|
|
233
|
+
return 2147483647 - curr_cnt; // 2^31 - 1
|
|
234
|
+
}
|
|
235
|
+
// 处理无符号整数类型(使用原逻辑)
|
|
236
|
+
else {
|
|
237
|
+
// 计算无符号整数最大值:2^(8*字节数) - 1
|
|
238
|
+
const n = 8 * Cls.BYTES_PER_ELEMENT;
|
|
239
|
+
const limit = 2 ** n; // 2^8, 2^16, 2^32
|
|
240
|
+
return limit -1 - curr_cnt;
|
|
151
241
|
}
|
|
152
242
|
}
|
|
153
243
|
|
|
244
|
+
|
|
154
245
|
function get_ta_cls_with_max_cnt(cnt,using_u64_when_gt_safe_f64_int=false) {
|
|
155
246
|
cnt = BigInt(cnt);
|
|
156
|
-
if(cnt<=
|
|
247
|
+
if(cnt <= 127n) { return Int8Array;
|
|
248
|
+
} else if(cnt<=255n) { return Uint8Array;
|
|
249
|
+
} else if(cnt<=32767n) { return Int16Array;
|
|
157
250
|
} else if(cnt<=65535n) { return Uint16Array;
|
|
251
|
+
} else if(cnt<=2147483647n) { return Int32Array;
|
|
158
252
|
} else if(cnt<=(2n**32n-1n)) { return Uint32Array;
|
|
159
253
|
} else if(cnt<=(2n**53n-1n)) {
|
|
160
254
|
return using_u64_when_gt_safe_f64_int?BigUint64Array:Float64Array;
|
|
@@ -163,37 +257,19 @@ function get_ta_cls_with_max_cnt(cnt,using_u64_when_gt_safe_f64_int=false) {
|
|
|
163
257
|
}
|
|
164
258
|
}
|
|
165
259
|
|
|
166
|
-
const DUMP_ONE_BYTE_TYPE_MP = {
|
|
167
|
-
0: Uint8Array,
|
|
168
|
-
1: Uint16Array,
|
|
169
|
-
2: Uint32Array,
|
|
170
|
-
3: BigUint64Array, // js version NOT supported
|
|
171
|
-
255: Float64Array,
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const CLS2BYT = new Map([
|
|
175
|
-
[Uint8Array,0],
|
|
176
|
-
[Uint16Array,1],
|
|
177
|
-
[Uint32Array,2],
|
|
178
|
-
[BigUint64Array,3],
|
|
179
|
-
[Float64Array,255]
|
|
180
|
-
]);
|
|
181
260
|
|
|
182
261
|
function get_byt_from_cls(Cls) {
|
|
183
262
|
return CLS2BYT.get(Cls)
|
|
184
263
|
}
|
|
264
|
+
function get_fst_byte_for_dump(Cls) { //旧代码兼容
|
|
265
|
+
return CLS2BYT.get(Cls)
|
|
266
|
+
}
|
|
267
|
+
|
|
185
268
|
|
|
186
269
|
function get_cls_from_dump_fst_byte(byt) {
|
|
187
270
|
return DUMP_ONE_BYTE_TYPE_MP[byt]??Float64Array
|
|
188
271
|
}
|
|
189
272
|
|
|
190
|
-
function get_fst_byte_for_dump(Cls) {
|
|
191
|
-
if(Cls === Uint8Array) return 0;
|
|
192
|
-
if(Cls === Uint16Array) return 1;
|
|
193
|
-
if(Cls === Uint32Array) return 2;
|
|
194
|
-
if(Cls === BigUint64Array) return 3; // js version NOT supported
|
|
195
|
-
return 255;
|
|
196
|
-
}
|
|
197
273
|
|
|
198
274
|
function set_fst_byte_for_dump(ta) {
|
|
199
275
|
var u8a = new Uint8Array(ta.buffer,ta.byteOffset,1);
|
|
@@ -211,14 +287,6 @@ function get_nth_byte(ta,I) {
|
|
|
211
287
|
}
|
|
212
288
|
|
|
213
289
|
|
|
214
|
-
function get_display_name_prefix(TypedArrayClass) {
|
|
215
|
-
if(TypedArrayClass.BYTES_PER_ELEMENT === 1) {return "Tiny"}
|
|
216
|
-
if(TypedArrayClass.BYTES_PER_ELEMENT === 2) {return "Small"}
|
|
217
|
-
if(TypedArrayClass.BYTES_PER_ELEMENT === 4) {return "Normal"}
|
|
218
|
-
return "Large";
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
290
|
//------------------------------------------------------------------------------
|
|
223
291
|
|
|
224
292
|
|
|
@@ -485,7 +553,7 @@ const write_dv_with_cls = (dv, Cls, offset, value, little_endian = true) => {
|
|
|
485
553
|
|
|
486
554
|
|
|
487
555
|
module.exports = {
|
|
488
|
-
tcate,
|
|
556
|
+
tcate, is_signed_int_cls , is_unsigned_int_cls,
|
|
489
557
|
////
|
|
490
558
|
check_sz_and_algn,
|
|
491
559
|
calc_algn_si,
|
|
@@ -539,4 +607,5 @@ module.exports = {
|
|
|
539
607
|
min_tacls,max_tacls,
|
|
540
608
|
read_dv_with_cls,
|
|
541
609
|
write_dv_with_cls,
|
|
610
|
+
////
|
|
542
611
|
}
|