Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitflags

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitflags

Small library for working with an arbitrarily large array of booleans

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
Source

bitflags

Small library for working with an arbitrarily large array of booleans

Install

npm

npm install bitflags

API

var bitflags = require('bitflags');
var flags = bitflags(1000000); //Creates a million boolean flags

get

Gets the bool at offset

flags.get(n) //returns true or false

set

Sets a bit at offset to bool

flags.set(n,0) //sets to false
flags.set(n,1) //sets to true
flags.set(n,'truthy') //sets to true

on

Sets the bit at offset to true

flags.on(n)

off

Sets the bit at offset to false

flags.off(n)

flip

Flip and returns the value of a single bit at offset

flags.flip(n)

fill

Reset to all 1's

flags.fill()

clear

Reset to all 0's

flags.clear()

size

Return exact size in bits note: may be larger than size specified in constructor, due to storage in octets

flags.size()

Example

Sets a flag for each prime in the first 2000000 integers, using Sieve of Eratosthenes, returns a function to test for primes:

var getSieveOfEratosthenes = function() {
	var size = 2000000;
	var bits = bitflags(size);
	bits.fill();
	bits.set(0,0);
	var lim = Math.ceil(Math.sqrt(size));
	for(var i=2;i<=lim;i++) {
		if(bits.get(i)){
			for(var j=i*i;j<=size;j+=i) {
				bits.set(j,0);
			}
		}
	};

	return function(n){ return bits.get(n); };
};

Keywords

FAQs

Package last updated on 28 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc