JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4647387
  • Score
    100M100P100Q228000F
  • License MIT

Bitfield that allocates a series of 1kb buffers to support sparse bits without allocating a massive buffer

Package Exports

  • sparse-bitfield

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sparse-bitfield) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sparse-bitfield

Bitfield implementation that allocates a series of 1kb buffers to support sparse bitfields without allocating a massive buffer. If you want to simple implementation of a flat bitfield see the bitfield module.

This module is mostly useful if you need a big bitfield where you won't nessecarily set every bit.

npm install sparse-bitfield

Usage

var bitfield = require('sparse-bitfield')
var bits = bitfield()

bits.set(0, true) // set first bit
bits.set(1, true) // set second bit
bits.set(1000000000000, true) // set the 1.000.000.000.000th bit

Running the above example will allocate two 1kb buffers internally. Each 1kb buffer can hold information about 8192 bits so the first one will be used to store information about the first two bits and the second will be used to store the 1.000.000.000.000th bit.

API

var bits = bitfield()

Create a new bitfield

bits.set(index, value)

Set a bit to true or false.

bits.get(index)

Get the value of a bit.

bits.getBuffer(index)

Get the 1kb buffer that stores the value of the index

bits.setBuffer(index, buffer)

Set the 1kb buffer that stores the value of the index. Mostly useful if you want to serialize the bitfield.

License

MIT