1.0.12 • Published 2 years ago

nv-data-tree-csp-json v1.0.12

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

nv-data-tree-csp-json

  • nv-data-tree-csp-json
  • json relation tree,support such as: parent,sibling....

install

  • npm install nv-data-tree-csp-json

usage

    const Forest = require('nv-data-tree-csp-forest');
      
    const {
        creat_undefined,
        creat_null,
        creat_true,
        creat_false,
        creat_str,
        creat_number,
        creat_ary,
        creat_obj,
        creat_external,
        creat_ref,
        is_jleaf,
        load_from_json,
    } = require("nv-data-tree-csp-json");

    load_from_json(J,forest=undefined,max_size=10000)

    //max_size default 10000(for small-size json), if larger than 1500000, speed low
    //   

perf

    /*

     nv-data-tree-csp-json# ls -l WORKDIR/TEST/ | egrep linux
     -rw-r--r-- 1 root root 34474647 Feb 28 12:47 linux-path.dict
     nv-data-tree-csp-json#


    // 160_0000  nodes

    > forest
    Forest {
      fid: '986368f3-c93f-4ac8-b0d9-cc4975b025dd',
      max_size: 2000000,
      idpool: { minid_: 1, maxid_: 2000000, used_: 1604477, lefted_: 395523 }
    }
    >

    > rt.$sdfs_.length
    1604477
    >
    > process.memoryUsage()
    {
      rss: 519315456,
      heapTotal: 455655424,
      heapUsed: 436544960,
      external: 1080249,
      arrayBuffers: 24785
    }
    >

    nv-file-reader# free
                  total        used        free      shared  buff/cache   available
    Mem:        2014880      666604      959736          64      388540     1190408
    Swap:       1970172      103572     1866600
    nv-file-reader#

    function tst() {
       let now = (new Date).getTime();
       let c =0
       let g = rt.$gen_sdfs_next();
       for(let each of g) {
           c = c+1
       }
       console.log(c);
       console.log((new Date).getTime() - now)
    }
    > tst()
    1604477
    282

    */

from_json

    var j = {
        undef: undefined,
        null: null,
        n1: 1,
        n2: 2,
        n3: 3,
        t: true,
        f: false,
        ary: [ 'a', 'b', 'c' ]
    }
    var [nd,forest] = load_from_json(j)

    > nd.show()
    {
      undef: undefined,
      null: null,
      n1: 1,
      n2: 2,
      n3: 3,
      t: true,
      f: false,
      ary: [...<3 unshow>...]
    }
   > nd.get('ary').show()
   [ "a", "b", "c" ]
   > nd
   {
     undef: undefined,
     null: null,
     n1: 1,
     n2: 2,
     n3: 3,
     t: true,
     f: false,
     ary: [ "a", "b", "c" ]
   }
   >
   > nd.json()
   {
     undef: undefined,
     null: null,
     n1: 1,
     n2: 2,
     n3: 3,
     t: true,
     f: false,
     ary: [ 'a', 'b', 'c' ]
   }
   >
   > nd.stringify()
   '{"null":null,"n1":1,"n2":2,"n3":3,"t":true,"f":false,["a","b","c"]}'
   > nd.get('ary')
   [ 'a', 'b', 'c' ]
   >
   > nd.get('ary').get(1)
   'b'
   > nd.get('ary').get(1).$parent_
   [ 'a', 'b', 'c' ]
   >       

    var forest = new Forest(10000);  //10000 max-supported nodes, must < 2**29


    var o = creat_obj(forest)
    o.show()
    o.append_undefined('undef')
    o.append_null('null')
    o.append_number("n1",1)
    o.append_number("n2",2)
    o.append_number("n3",3)
    o.append_true("t")
    o.append_false("f")

    o.append_ary("ary")
    var ary = o.get('ary')
    ary.show()
    ary.append_str("a")
    ary.append_str("b")
    ary.append_str("c")

    > o
    {
      undef: undefined,
      null: null,
      n1: 1,
      n2: 2,
      n3: 3,
      t: true,
      f: false,
      ary: [ 'a', 'b', 'c' ]
    }
    >

> o.get('ary').get(1)
b
> o.get('ary').get(1).$parent_
[ a, b, c ]
>

> o.stringify()
'{"null":null,"n1":1,"n2":2,"n3":3,"t":true,"f":false,["a","b","c"]}'
>


> o.json()
{
  undef: undefined,
  null: null,
  n1: 1,
  n2: 2,
  n3: 3,
  t: true,
  f: false,
  ary: [ 'a', 'b', 'c' ]
}
>

> o.$sedfs_
[
  [
    {
      undef: undefined,
      null: null,
      n1: 1,
      n2: 2,
      n3: 3,
      t: true,
      f: false,
      ary: [Array]
    },
    'open'
  ],
  [ undefined, 'open' ],
  [ undefined, 'close' ],
  [ null, 'open' ],
  [ null, 'close' ],
  [ 1, 'open' ],
  [ 1, 'close' ],
  [ 2, 'open' ],
  [ 2, 'close' ],
  [ 3, 'open' ],
  [ 3, 'close' ],
  [ true, 'open' ],
  [ true, 'close' ],
  [ false, 'open' ],
  [ false, 'close' ],
  [ [ a, b, c ], 'open' ],
  [ a, 'open' ],
  [ a, 'close' ],
  [ b, 'open' ],
  [ b, 'close' ],
  [ c, 'open' ],
  [ c, 'close' ],
  [ [ 'a', 'b', 'c' ], 'close' ],
  [
    {
      undef: undefined,
      null: null,
      n1: 1,
      n2: 2,
      n3: 3,
      t: true,
      f: false,
      ary: [Array]
    },
    'close'
  ]
]
>    

proxy

> o.$_.ary
Proxy [
  [ 'a', 'b', 'c' ],
  { get: [Function: get], set: [Function: set] }
]
> o.$_.ary[1]
Proxy [ 'b', { get: [Function: get] } ]
>
> o.$_.ary[1] = 'BBB'
'BBB'
> o
{
  undef: undefined,
  null: null,
  n1: 1,
  n2: 2,
  n3: 3,
  t: true,
  f: false,
  ary: [ 'a', 'BBB', 'c' ]
}
>    

LICENSE

  • ISC