nv-facutil-slct-ta 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/index.js +90 -30
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -86,11 +86,8 @@ BRIEF_MIRR.set("i32a", Int32Array);
86
86
  BRIEF_MIRR.set("i64a", BigInt64Array);
87
87
  BRIEF_MIRR.set("f32a", Float32Array);
88
88
  BRIEF_MIRR.set("f64a", Float64Array);
89
- if (globalThis.Float16Array !== undefined) {BRIEF_MIRR.set("f16a", globalThis.Float16Array);}
90
89
  BRIEF_MIRR.set("dv", DataView);
91
- if (globalThis.Buffer !== undefined) {BRIEF_MIRR.set("buf", globalThis.Buffer);}
92
- if (globalThis.Blob !== undefined) {BRIEF_MIRR.set("blob", globalThis.Blob);}
93
- if (globalThis.File !== undefined) {BRIEF_MIRR.set("file", globalThis.File);}
90
+ BRIEF_MIRR.set("ab", ArrayBuffer);
94
91
  BRIEF_MIRR.set(Uint8Array,"u8a");
95
92
  BRIEF_MIRR.set(Uint8ClampedArray, "u8ca");
96
93
  BRIEF_MIRR.set(Uint16Array, "u16a");
@@ -102,24 +99,15 @@ BRIEF_MIRR.set(Int32Array, "i32a");
102
99
  BRIEF_MIRR.set(BigInt64Array, "i64a");
103
100
  BRIEF_MIRR.set(Float32Array, "f32a");
104
101
  BRIEF_MIRR.set(Float64Array, "f64a");
105
-
106
- if (globalThis.Float16Array !== undefined) {
107
- BRIEF_MIRR.set(globalThis.Float16Array, "f16a");
108
- }
109
-
110
102
  BRIEF_MIRR.set(DataView, "dv");
103
+ BRIEF_MIRR.set(ArrayBuffer, "ab");
111
104
 
112
- if (globalThis.Buffer !== undefined) {
113
- BRIEF_MIRR.set(globalThis.Buffer, "buf");
114
- }
115
-
116
- if (globalThis.Blob !== undefined) {
117
- BRIEF_MIRR.set(globalThis.Blob, "blob");
118
- }
105
+ if (globalThis.Float16Array !== undefined) {BRIEF_MIRR.set("f16a", globalThis.Float16Array);BRIEF_MIRR.set(globalThis.Float16Array, "f16a");}
106
+ if (globalThis.Buffer !== undefined) {BRIEF_MIRR.set("buf", globalThis.Buffer);BRIEF_MIRR.set(globalThis.Buffer, "buf");}
107
+ if (globalThis.Blob !== undefined) {BRIEF_MIRR.set("blob", globalThis.Blob);BRIEF_MIRR.set(globalThis.Blob, "blob");}
108
+ if (globalThis.File !== undefined) {BRIEF_MIRR.set("file", globalThis.File);BRIEF_MIRR.set(globalThis.File, "file");}
109
+ if (globalThis.SharedArrayBuffer !== undefined) {BRIEF_MIRR.set("sab", globalThis.SharedArrayBuffer);BRIEF_MIRR.set(globalThis.SharedArrayBuffer, "sab");}
119
110
 
120
- if (globalThis.File !== undefined) {
121
- BRIEF_MIRR.set(globalThis.File, "file");
122
- }
123
111
  function get_brief_name(Cls) {return BRIEF_MIRR.get(Cls)}
124
112
  function get_cls_from_brief_name(brief) {return BRIEF_MIRR.get(brief.toLowerCase())}
125
113
 
@@ -205,18 +193,77 @@ const creat_on_ab =(Cls,requested_cnt,ab,offset=0)=>{
205
193
  }
206
194
  }
207
195
 
208
- const is_overlaped = (typed_array0,typed_array1)=>{
209
- var ab0 = typed_array0.buffer;
210
- var ab1 = typed_array1.buffer;
211
- if(ab0 === ab1) {
212
- var si0 = typed_array0.byteOffset; var ei0 = si0 + typed_array0.byteLength;
213
- var si1 = typed_array1.byteOffset; var ei1 = si1 + typed_array1.byteLength;
214
- return !(ei0 <= si1 || ei1 <= si0); // 没有重叠时,返回 false
215
- } else {
216
- return false;
217
- }
196
+ const is_rng_overlaped = (si0,ei0,si1,ei1)=>{
197
+ //assume(si0< ei0, si1< ei1)
198
+ if(ei0<=si1) {return false;}
199
+ if(ei1<=si0) {return false;}
200
+ return true;
201
+ }
202
+
203
+ const is_ab_rng_overlaped = (abrng0,abrng1)=>{
204
+ var [ab0,si0,ei0] = abrng0;
205
+ var [ab1,si1,ei1] = abrng1;
206
+ if(ab0 === ab1) {
207
+ return is_rng_overlaped(si0,ei0,si1,ei1);
208
+ } else {
209
+ return false;
210
+ }
218
211
  }
219
212
 
213
+ const ta2abrng = (ta)=>[ta.buffer,ta.byteOffset,ta.byteOffset+ta.byteLength]
214
+
215
+ const is_ta_overlaped = (typed_array0,typed_array1)=>is_ab_rng_overlaped(
216
+ ta2abrng(typed_array0),
217
+ ta2abrng(typed_array1),
218
+ );
219
+
220
+ const to_abrng = (o)=> Array.isArray(o)?o:ta2abrng(o);
221
+ const is_overlaped = (o0,o1) => is_ab_rng_overlaped(to_abrng(o0),to_abrng(o1));
222
+
223
+
224
+ ////
225
+ const TACLS_TO_MTHD_HINT = new Map([
226
+ [Uint8ClampedArray, { r: "ru8ca", w: "wu8ca", "?": false }],
227
+ [Uint8Array, { r: "ru8a", w: "wu8a", "?": false }],
228
+ [Int8Array, { r: "ri8a", w: "wi8a", "?": false }],
229
+ [Uint16Array, { r: "ru16a", w: "wu16a", "?": false }],
230
+ [Int16Array, { r: "ri16a", w: "wi16a", "?": false }],
231
+ [Uint32Array, { r: "ru32a", w: "wu32a", "?": false }],
232
+ [Int32Array, { r: "ri32a", w: "wi32a", "?": false }],
233
+ [BigUint64Array, { r: "ru64a", w: "wu64a", "?": false }],
234
+ [BigInt64Array, { r: "ri64a", w: "wi64a", "?": false }],
235
+ [Float32Array, { r: "rf32a", w: "wf32a", "?": true }],
236
+ [Float64Array, { r: "rf64a", w: "wf64a", "?": true }],
237
+ [DataView, { r: "rdv", w: "wdv", "?": false }],
238
+ ]);
239
+ if(globalThis.Float16Array !== undefined) {TACLS_TO_MTHD_HINT.set(globalThis.Float16Array,{ r: "rf16a", w: "wf16a", "?": true })}
240
+ const tacls_to_mthd_hint = (Cls)=>TACLS_TO_MTHD_HINT.get(Cls);
241
+ ////
242
+
243
+ const TACLS_OR_ABCLS_TO_MTHD_HINT = new Map(Array.from(TACLS_TO_MTHD_HINT.entries()));
244
+ if(globalThis.Buffer !== undefined) {TACLS_OR_ABCLS_TO_MTHD_HINT.set(globalThis.Buffer, { r: "ru8a", w: "wu8a", "?": false })}
245
+ if(globalThis.SharedArrayBuffer !== undefined) {TACLS_OR_ABCLS_TO_MTHD_HINT.set(globalThis.SharedArrayBuffer,{ r: "ro", w: "wo", "?": false })}
246
+ const tacls_or_abcls_to_mthd_hint = (Cls)=>TACLS_OR_ABCLS_TO_MTHD_HINT.get(Cls);
247
+ ////
248
+
249
+ const TACLSNM_TO_TBRIEF = {
250
+ "Uint8Array": "u8a",
251
+ "Uint8ClampedArray": "u8ca",
252
+ "Int8Array": "i8a",
253
+ "Uint16Array": "u16a",
254
+ "Int16Array": "i16a",
255
+ "Uint32Array": "u32a",
256
+ "Int32Array": "i32a",
257
+ "BigUint64Array": "u64a",
258
+ "BigInt64Array": "i64a",
259
+ "Float16Array" : "f16a",
260
+ "Float32Array": "f32a",
261
+ "Float64Array": "f64a",
262
+ "DataView": "dv",
263
+ };
264
+ const taclsnm_to_tbrief = (clsnm/*constructor.name*/)=>TACLSNM_TO_TBRIEF[clsnm];
265
+ const tbrief_to_taclsnm = (tbrief)=>get_cls_from_brief_name(tbrief).name;
266
+
220
267
  module.exports = {
221
268
  check_sz_and_algn,
222
269
  calc_algn_si,
@@ -230,7 +277,10 @@ module.exports = {
230
277
  get_display_name_prefix,
231
278
  get_brief_name,get_cls_from_brief_name,
232
279
  ////
233
- AB_CLSES,TA_CLSES,VWLIKE_CLSES,BUFLIKE_CLSES,
280
+ AB_CLSES,
281
+ TA_CLSES,
282
+ VWLIKE_CLSES,
283
+ BUFLIKE_CLSES,
234
284
  ////
235
285
  cp,
236
286
  setv,
@@ -239,5 +289,15 @@ module.exports = {
239
289
  creat_debug_view,
240
290
  is_ablike,
241
291
  creat_on_ab,
292
+ is_rng_overlaped,
293
+ is_ab_rng_overlaped,
294
+ ta2abrng,
295
+ is_ta_overlaped,
296
+ to_abrng,
242
297
  is_overlaped,
298
+ ////
299
+ tacls_to_mthd_hint,
300
+ tacls_or_abcls_to_mthd_hint,
301
+ taclsnm_to_tbrief,
302
+ tbrief_to_taclsnm,
243
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-facutil-slct-ta",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"