npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nd-bitset

v1.0.11

Published

nd-bitset ======================= - simple wrap of std::bitset - only work in nodejs - must be 64 * Integer (IF <= 32, directly use a JS integer is BEST) - suitable for bigsize bit-pool (suggested is 1G)

Downloads

11

Readme

nd-bitset

  • simple wrap of std::bitset
  • only work in nodejs
  • must be 64 * Integer (IF <= 32, directly use a JS integer is BEST)
  • suitable for bigsize bit-pool (suggested is 1G)

install

  • npm install nd-bitset

splitted

usage

  const x   = require("nd-bitset");

example

creat new

	> var bits = x.creat_bits_1g()
	> bits[99999] =true
	true
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: true,
	  are_all_fls: false,
	  are_all_tru: false,
	  count_of_0: 1073741823,
	  count_of_1: 1,
	  bit_capacity: 1073741824
	}
	> bits[99999]
	true
	> bits[1073741823] = true
	true
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: true,
	  are_all_fls: false,
	  are_all_tru: false,
	  count_of_0: 1073741822,
	  count_of_1: 2,
	  bit_capacity: 1073741824
	}
	> x.flip_all(bits)
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: true,
	  are_all_fls: false,
	  are_all_tru: false,
	  count_of_0: 2,
	  count_of_1: 1073741822,
	  bit_capacity: 1073741824
	}
	> x.free_bits(bits)              // must free. 

	/* if use it after free, will crash*/

creat on existing buffer

	> var ab = new ArrayBuffer(8)
	> ab
	ArrayBuffer {
	  [Uint8Contents]: <00 00 00 00 00 00 00 00>,
	  byteLength: 8
	}
	> var bits = x.creat_bits_64(ab)
	> ab
	ArrayBuffer {
	  [Uint8Contents]: <00 00 00 00 00 00 00 00>,
	  byteLength: 8
	}
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: false,
	  are_all_fls: true,
	  are_all_tru: false,
	  count_of_0: 64,
	  count_of_1: 0,
	  bit_capacity: 64
	}
	> bits[5] = true
	true
	> ab
	ArrayBuffer {
	  [Uint8Contents]: <20 00 00 00 00 00 00 00>,
	  byteLength: 8
	}
	> x.flip_all(bits)
	> ab
	ArrayBuffer {
	  [Uint8Contents]: <df ff ff ff ff ff ff ff>,
	  byteLength: 8
	}
	>

push /pop (as a circular buffer)

push_one: (bits, v=true)->Void

	> var bits = x.creat_bits_1g()
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: false,
	  are_all_fls: true,
	  are_all_tru: false,
	  count_of_0: 1073741824,
	  count_of_1: 0,
	  bit_capacity: 1073741824
	}
	> x.push_one(bits,1)
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: true,
	  are_all_fls: false,
	  are_all_tru: false,
	  count_of_0: 1073741823,
	  count_of_1: 1,
	  bit_capacity: 1073741824
	}
	> bits[1073741823]
	true
	> bits[1073741822]
	false
	> 

pop_one: (bits)->boolean

	> var bits = x.creat_bits_64()
	> bits
	{
	  is_any_fls: true,
	  is_any_tru: false,
	  are_all_fls: true,
	  are_all_tru: false,
	  count_of_0: 64,
	  count_of_1: 0,
	  bit_capacity: 64
	}
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000000000' ]
	> x.push_one(bits,1)
	> x.show64(bits)
	[ '1000000000000000000000000000000000000000000000000000000000000000' ]
	> bits[0]
	false
	> bits[63]
	true
	> x.push_one(bits,1)
	> x.show64(bits)
	[ '1100000000000000000000000000000000000000000000000000000000000000' ]
	// bit(63)  ...->                                               bit(0)
	> bits[63]
	true
	> bits[62]
	true
	> x.push_one(bits,1)
	> x.show64(bits)
	[ '1110000000000000000000000000000000000000000000000000000000000000' ]
	> x.pop_one(bits)
	true
	> x.show64(bits)
	[ '1100000000000000000000000000000000000000000000000000000000000000' ]
	> x.pop_one(bits)
	true
	> x.show64(bits)
	[ '1000000000000000000000000000000000000000000000000000000000000000' ]
	> x.pop_one(bits)
	true
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000000000' ]
	> bits[0]=true
	true
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000000001' ]
	> bits[1]=true
	true
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000000011' ]
	> x.lshft_inplace(bits,2)
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000001100' ]
	> x.rshft_inplace(bits,2)
	> x.show64(bits)
	[ '0000000000000000000000000000000000000000000000000000000000000011' ]
	>

    x.free_bits(bits)

call as function (range :64-bit-segment)

	// can call-as function  : (start-64bit-unit-idx, end-64bit-unit-idx, value)
	> bits(0,1,0b0000000000000000000000000000000000000000000000000000000000000000n)
	> x.show64(bits)
	[
	  '0000000000000000000000000000000000000000000000000000000000000000',
	  '1111111111111111111111111111111111111111111111111111111111111111'
	]
	> bits(0,1,3)
	> x.show64(bits)
	[
	  '0000000000000000000000000000000000000000000000000000000000000011',
	  '1111111111111111111111111111111111111111111111111111111111111111'
	]
	>

simple stringify (just for debug, its slow)

    (DO-NOT  use this on big-size-bits-larger-than-128M(such as 512M 1G),  its very slow, coz js-string is very slow)

	var bits = x.creat_bits_128();
	x.set_all_to_tru(bits)

	> var bits = x.creat_bits_128()
	> x.show64(bits)
	[
	  '0000000000000000000000000000000000000000000000000000000000000000',
	  '0000000000000000000000000000000000000000000000000000000000000000'
	]
	> x.set_all_to_tru(bits)
	> x.show64(bits)
	[
	  '1111111111111111111111111111111111111111111111111111111111111111',
	  '1111111111111111111111111111111111111111111111111111111111111111'
	]
	> 

    x.free_bits(bits) 

		> var bits = x.creat_bits_128()
		> x.show64(bits)
		[
		  '0000000000000000000000000000000000000000000000000000000000000000',
		  '0000000000000000000000000000000000000000000000000000000000000000'
		]
		> bits[0]=1
		1
		> x.show64(bits)
		[
		  '0000000000000000000000000000000000000000000000000000000000000001',
		  '0000000000000000000000000000000000000000000000000000000000000000'
		]
		> bits[127]=1
		1
		> x.show64(bits)
		[
		  '0000000000000000000000000000000000000000000000000000000000000001',
		  '1000000000000000000000000000000000000000000000000000000000000000'
		]
		> x.free_bits(bits)

&= |= ^= inplace

	var bits0 = x.creat_bits_64()
	var bits1 = x.creat_bits_64()
	bits0[0]=1
	bits1[63]=1

	> x.show64(bits0)
	[ '0000000000000000000000000000000000000000000000000000000000000001' ]

	> x.show64(bits1)
	[ '1000000000000000000000000000000000000000000000000000000000000000' ]
	> 

	x.bor_inplace(bits0,bits1)  //   bits0 = bits0 | bits1

	> x.show64(bits0)
	[ '1000000000000000000000000000000000000000000000000000000000000001' ]
	> 
	> x.show64(bits1)
	[ '1000000000000000000000000000000000000000000000000000000000000000' ]
	>
	> x.bxor_inplace(bits1,bits0)
	> x.show64(bits1)
	[ '0000000000000000000000000000000000000000000000000000000000000001' ]
	> x.show64(bits0)
	[ '1000000000000000000000000000000000000000000000000000000000000001' ]
	> 	

& | ^ NOT-inplace, will creat new

		> var bits0 = x.creat_bits_64();
		> var bits1 = x.creat_bits_64();

		> bits0
		{
		  is_any_fls: true,
		  is_any_tru: false,
		  are_all_fls: true,
		  are_all_tru: false,
		  count_of_0: 64,
		  count_of_1: 0,
		  bit_capacity: 64
		}
		> x.flip_all(bits1)
		> x.show64(bits0)
		[ '0000000000000000000000000000000000000000000000000000000000000000' ]
		> x.show64(bits1)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		> var bits2 = x.bor(bits0,bits1)
		> bits2
		{
		  is_any_fls: false,
		  is_any_tru: true,
		  are_all_fls: false,
		  are_all_tru: true,
		  count_of_0: 0,
		  count_of_1: 64,
		  bit_capacity: 64
		}
		> x.show64(bits2)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		> bits0[25] = 1
		1
		> x.show64(bits2)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		> x.show64(bits0)
		[ '0000000000000000000000000000000000000010000000000000000000000000' ]
		> x.show64(bits1)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		> bits1[26] = 1
		1
		> x.show64(bits1)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		> bits1[26] = 0
		0
		> x.show64(bits1)
		[ '1111111111111111111111111111111111111011111111111111111111111111' ]
		> x.show64(bits2)
		[ '1111111111111111111111111111111111111111111111111111111111111111' ]
		>

METHODS

APIS

		{
		  creat_bits_64: [Function (anonymous)],
		  creat_bits_128: [Function (anonymous)],
		  creat_bits_256: [Function (anonymous)],
		  creat_bits_512: [Function (anonymous)],
		  creat_bits_1k: [Function (anonymous)],
		  creat_bits_2k: [Function (anonymous)],
		  creat_bits_4k: [Function (anonymous)],
		  creat_bits_8k: [Function (anonymous)],
		  creat_bits_16k: [Function (anonymous)],
		  creat_bits_32k: [Function (anonymous)],
		  creat_bits_64k: [Function (anonymous)],
		  creat_bits_128k: [Function (anonymous)],
		  creat_bits_256k: [Function (anonymous)],
		  creat_bits_512k: [Function (anonymous)],
		  creat_bits_1m: [Function (anonymous)],
		  creat_bits_2m: [Function (anonymous)],
		  creat_bits_4m: [Function (anonymous)],
		  creat_bits_8m: [Function (anonymous)],
		  creat_bits_16m: [Function (anonymous)],
		  creat_bits_32m: [Function (anonymous)],
		  creat_bits_64m: [Function (anonymous)],
		  creat_bits_128m: [Function (anonymous)],
		  creat_bits_256m: [Function (anonymous)],
		  creat_bits_512m: [Function (anonymous)],
		  creat_bits_1g: [Function (anonymous)],
		  creat_bits_2g: [Function (anonymous)],
		  creat_bits_4g: [Function (anonymous)],
		  creat_bits_8g: [Function (anonymous)],
		  creat_bits_16g: [Function (anonymous)],
		  creat_bits_32g: [Function (anonymous)],
		  creat_bits_64g: [Function (anonymous)],
		  creat_bits_128g: [Function (anonymous)],


		      set_all_to_tru: [Function (anonymous)],
		      set_all_to_fls: [Function (anonymous)],
		      flip_all: [Function (anonymous)],
		      clone: [Function (anonymous)],


		  free_bits: [Function (anonymous)]
		}

LICENSE

  • ISC