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

bitset

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitset

BitSet implementation for JavaScript

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.1K
decreased by-27.02%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

BitSet

This module implements an array of bits, that grows as needed. It can be used from both JavaScript:

var bs = new BitSet();

for(var n = 0; n < 12; n++) {
  bs.set(n);
}

console.dir(bs);

as well as CoffeeScript:

bs = new BitSet

bs.set 1
bs.clear 1

console.log bs.toString()

Usage

BitSets are very useful for realtime metrics. If you want to count the number of active users (CoffeeScript):

# Somewhere in application code
todaysUserCount = new Bitset
    
# The User class
class User
  @login: (userName, password) ->
    todaysUserCount.set @userId
    
# In reporting code
todaysUserCount.cardinality()

Documentation

  • BitSet#set(pos) - sets the bit on position pos to true
  • BitSet#get(pos) - returns whether the bit on position pos is set
  • BitSet#clear(pos) - clears the bit on position pos
  • BitSet#length - returns the logical length of the bitset
  • BitSet#wordLength - returns the word-length of the bitset
  • BitSet#cardinality - returns how many bits are set to true in the bitset
  • BitSet#toString - returns a string representation of the bitset
  • BitSet#toBinaryString - returns a binary string representation of the bitset
  • BitSet#or(bitset) - OR's this bitset with the argument bitset
  • BitSet#and(bitset) - AND's this bitset with the argument bitset
  • BitSet#andNot(bitset) - ANDNOT's this bitset with the argument bitset
  • BitSet#xor(bitset) - XOR's this bitset with the argument bitset

For details see src/bitset.coffee

Installation

npm install bitset

Performance

It performs pretty well, you can try the performance.js in the support folder. This is the output with 100.000.000 bits:

set 100000000 bits: 3173ms
cardinality 100000000
cardinality: 949ms

Tests

Testing is done via the excellent mocha (cake test)

Keywords

FAQs

Package last updated on 04 Dec 2011

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