1.0.4 • Published 1 year ago

nv-string-map v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

nv-string-map

  • a string-to-id id-to-string simple map
  • to avoid using string when do serde, normally USELESS

install

  • npm install nv-string-map

usage

  const x   = require("nv-string-map");

example

	> var pool = x.creat()

	> pool
	Pool <[Object: null prototype]> {
	  id: 2147483649,
	  smap: [Object: null prototype] {},
	  imap: [Object: null prototype] {}
	}
	> pool.set("abcde")
	2147483649
	> pool.set("我你他")
	2147483650
	> pool
	Pool <[Object: null prototype]> {
	  id: 2147483651,
	  smap: [Object: null prototype] { abcde: 2147483649, '我你他': 2147483650 },
	  imap: [Object: null prototype] {
	    '2147483649': 'abcde',
	    '2147483650': '我你他'
	  }
	}

	var ab = pool.to_ab()

	> ab
	ArrayBuffer {
	  [Uint8Contents]: <01 00 00 80 05 00 00 00 61 62 63 64 65 02 00 00 80 09 00 00 00 e6 88 91 e4 bd a0 e4 bb 96>,
	  byteLength: 30
	}


	var npool = x.load_from_ab(ab);
	/*
	>
	Pool <[Object: null prototype]> {
	  id: 2147483651,
	  smap: { abcde: 2147483649, '我你他': 2147483650 },
	  imap: { '2147483649': 'abcde', '2147483650': '我你他' }
	}
	> 
	*/

	> npool.count()
	2
	> npool.calc_bytsz()
	30
	> 

METHODS

   ////methods
   .set(String)  -> uint32_t@ge_2147483649_and_le_4294967294
   .count()      -> uint32_t
   .calc_bytsz() -> uint32_t

    ////getters
   smap 
   imap
     

APIS

		{
		  MINID: 2147483649,
		  MAXID: 4294967294,
		  MAXCNT: 2147483646,
		  is_valid_id: [Function: is_valid_id],
		  find_nid_from_smap: [Function: find_nid_from_smap],
		  find_nid_from_smap_and_rebuild_imap: [Function: find_nid_from_smap_and_rebuild_imap],
		  find_nid_from_imap: [Function: find_nid_from_imap],
		  find_nid_from_imap_and_rebuild_smap: [Function: find_nid_from_imap_and_rebuild_smap],
		  UTF8TE: { encoding: 'utf-8' },
		  UTF8TD: TextDecoder { encoding: 'utf-8', fatal: false, ignoreBOM: false },
		  creat: [Function: creat],
		  load_from_ab: [Function: load_from_ab]
		}

LICENSE

  • ISC
1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago