1.0.3 • Published 2 years ago

nv-tary-shared-basic v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

nv-tary-shared-basic

  • nv-tary-shared-basic creat a shared-array-buffer AND a TypedArray-view
  • creat many-view of same shared-array-buf
  • for parser in worker-thread using, normally USELESS

install

  • npm install nv-tary-shared-basic

usage

example

        > var rslt = x.creat_many(128,["u8","u64","f32"])

        > rslt
        {
          buf: SharedArrayBuffer {
            [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 28 more bytes>,
            byteLength: 128
          },
          view: {
            u8: Uint8Array(128) [
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0,
              ... 28 more items
            ],
            bu64: BigUint64Array(16) [
              0n, 0n, 0n, 0n, 0n, 0n,
              0n, 0n, 0n, 0n, 0n, 0n,
              0n, 0n, 0n, 0n
            ],
            f32: Float32Array(32) [
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0, 0, 0, 0, 0,
              0, 0, 0, 0, 0
            ]
          }
        }
        >

        rslt.view.f32[0] = 1.33333333333333333333


        > rslt
        {
          buf: SharedArrayBuffer {
            [Uint8Contents]: <ab aa aa 3f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... 28 more bytes>,
            byteLength: 128
          },
          view: {
            u8: Uint8Array(128) [
              171, 170, 170, 63,           //========>  use this to serialize float
              0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
                0,   0,   0,  0,
              ... 28 more items
            ],
            bu64: BigUint64Array(16) [
              1068149419n,               //========>
              0n,
                       0n, 0n,
                       0n, 0n,
                       0n, 0n,
                       0n, 0n,
                       0n, 0n,
                       0n, 0n,
                       0n, 0n
            ],
            f32: Float32Array(32) [
              1.3333333730697632,   //========>
              0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0,
                               0, 0
            ]
          }
        }
        >

APIS

    const DFLT_CFG = ()=>({
    > x.DFLT_CFG()
    { use_float: false, signed: false, clamped: false }
    >
    
    const NAMES = [
         "u8","u8c","u16","u32",
         "bu64","u64",
         "i8","i16","i32",
         "bi64","i64",
         "f32","f64"
    ];


    
    const SAB = SharedArrayBuffer;
    const U8  = Uint8Array;
    const U8C = Uint8ClampedArray;
    const U16 = Uint16Array;
    const U32 = Uint32Array;
    const I8  = Int8Array;
    const I16 = Int16Array;
    const I32 = Int32Array;
    const F32 = Float32Array;
    const F64 = Float64Array;
    const BI64 = BigInt64Array;
    const I64  = BI64;
    const BU64 = BigUint64Array;
    const U64  = BU64;

    const _u8 = (sab) => new U8(sab);
    const u8 = (byte_sz) => {
    const _u8c = (sab) => new U8C(sab);
    const u8c = (byte_sz) => {
    const _u16 = (sab) => new U16(sab);
    const u16 = (byte_sz) => {
    const _u32 = (sab) => new U32(sab);
    const u32 = (byte_sz) => {
    const _bu64 = (sab) => new BU64(sab);
    const bu64 = (byte_sz) => {
    const _i8 = (sab) => new I8(sab);
    const i8 = (byte_sz) => {
    const _i16 = (sab) => new I16(sab);
    const i16 = (byte_sz) => {
    const _i32 = (sab) => new I32(sab);
    const i32 = (byte_sz) => {
    const _bi64 = (sab) => new BI64(sab);
    const bi64 = (byte_sz) => {
    const _f32 = (sab) => new F32(sab);
    const f32 = (byte_sz) => {
    const _f64 = (sab) => new F64(sab);
    const f64 = (byte_sz) => {
    const _$unsigned = (sab,view_sz=8,clamped=false) => {
    const $unsigned = (byte_sz,view_sz=8,clamped=false) => {
    const _$signed = (sab,view_sz=8) => {
    const $signed = (byte_sz,view_sz=8) => {
    const _$float = (sab,view_sz=64) => {
    const $float = (byte_sz,view_sz=64) => {
    const DFLT_CFG = ()=>({
    const _creat = (sab,view_sz,cfg=DFLT_CFG()) => {
    const creat = (byte_sz,view_sz,cfg=DFLT_CFG()) => {
    const parse_name_to_cfg = (name) => {
    const _creat_many = (sab,names=["u8","u64"]) => {
    const creat_many = (byte_sz,names=["u8","u64"])=> {

LICENSE

  • ISC