nv-facutil-slct-ta 1.0.0
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.d.ts +20 -0
- package/index.js +74 -0
- package/package.json +12 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* 计算对齐后的起始位置。
|
|
4
|
+
* @param si 起始位置
|
|
5
|
+
* @param algnsz 对齐字节数
|
|
6
|
+
* @returns 对齐后的起始位置
|
|
7
|
+
*/
|
|
8
|
+
export function calc_algn_si(si: number, algnsz: number): number;
|
|
9
|
+
|
|
10
|
+
export function calc_max_incr_cnt(Cls:Uint8Array|Uint16Array|Uint32Array|BigUint64Array|Float64Array,curr_cnt:Number|BigInt):Number|BigInt;
|
|
11
|
+
|
|
12
|
+
export function get_ta_cls_with_max_cnt(cnt: bigint | number): any;
|
|
13
|
+
|
|
14
|
+
export function get_cls_from_dump_fst_byte(byt: number): any;
|
|
15
|
+
|
|
16
|
+
export function get_fst_byte_for_dump(Cls: any): number;
|
|
17
|
+
|
|
18
|
+
export function set_fst_byte_for_dump(ta:TypedArray): number;
|
|
19
|
+
|
|
20
|
+
export function get_display_name_prefix(ta:TypedArray): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function calc_algn_si(si,algnsz) {
|
|
2
|
+
var r = si % algnsz;
|
|
3
|
+
if(r === 0) {
|
|
4
|
+
return si;
|
|
5
|
+
} else {
|
|
6
|
+
return si + algnsz - r;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function calc_max_incr_cnt(Cls,curr_cnt) {
|
|
11
|
+
if(Cls === Float64Array) {
|
|
12
|
+
return 2**53 - curr_cnt;
|
|
13
|
+
} else if(Cls === BigUint64Array) { //JS version NOT supported
|
|
14
|
+
var limit = 2n** (8n* BigInt(Cls.BYTES_PER_ELEMENT));
|
|
15
|
+
return limit - BigInt(curr_cnt);
|
|
16
|
+
} else {
|
|
17
|
+
var limit = 2** (8*Cls.BYTES_PER_ELEMENT);
|
|
18
|
+
return limit - curr_cnt;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function get_ta_cls_with_max_cnt(cnt,using_u64_when_gt_safe_f64_int=false) {
|
|
23
|
+
cnt = BigInt(cnt);
|
|
24
|
+
if(cnt<=255n) { return Uint8Array;
|
|
25
|
+
} else if(cnt<=65535n) { return Uint16Array;
|
|
26
|
+
} else if(cnt<=(2n**32n-1n)) { return Uint32Array;
|
|
27
|
+
} else if(cnt<=(2n**53n-1n)) {
|
|
28
|
+
return using_u64_when_gt_safe_f64_int?BigUint64Array:Float64Array;
|
|
29
|
+
} else {
|
|
30
|
+
return BigUint64Array;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const DUMP_ONE_BYTE_TYPE_MP = {
|
|
35
|
+
0: Uint8Array,
|
|
36
|
+
1: Uint16Array,
|
|
37
|
+
2: Uint32Array,
|
|
38
|
+
3: BigUint64Array, // js version NOT supported
|
|
39
|
+
255: Float64Array,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function get_cls_from_dump_fst_byte(byt) {
|
|
43
|
+
return DUMP_ONE_BYTE_TYPE_MP[byt]??Float64Array
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function get_fst_byte_for_dump(Cls) {
|
|
47
|
+
if(Cls === Uint8Array) return 0;
|
|
48
|
+
if(Cls === Uint16Array) return 1;
|
|
49
|
+
if(Cls === Uint32Array) return 2;
|
|
50
|
+
if(Cls === BigUint64Array) return 3; // js version NOT supported
|
|
51
|
+
return 255;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function set_fst_byte_for_dump(ta) {
|
|
55
|
+
var u8a = new Uint8Array(ta.buffer,ta.byteOffset,1);
|
|
56
|
+
u8a[0] = get_fst_byte_for_dump(ta.constructor);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function get_display_name_prefix(TypedArrayClass) {
|
|
60
|
+
if(TypedArrayClass.BYTES_PER_ELEMENT === 1) {return "Tiny"}
|
|
61
|
+
if(TypedArrayClass.BYTES_PER_ELEMENT === 2) {return "Small"}
|
|
62
|
+
if(TypedArrayClass.BYTES_PER_ELEMENT === 4) {return "Normal"}
|
|
63
|
+
return "Large";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = {
|
|
67
|
+
calc_algn_si,
|
|
68
|
+
calc_max_incr_cnt,
|
|
69
|
+
get_ta_cls_with_max_cnt,
|
|
70
|
+
get_cls_from_dump_fst_byte,
|
|
71
|
+
get_fst_byte_for_dump,
|
|
72
|
+
set_fst_byte_for_dump,
|
|
73
|
+
get_display_name_prefix
|
|
74
|
+
}
|
package/package.json
ADDED