Socket
Socket
Sign inDemoInstall

fast-bitfield

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fast-bitfield

Variable sized bitfield that allows you to quickly iterate over bits


Version published
Weekly downloads
703
increased by3.69%
Maintainers
1
Install size
22.9 kB
Created
Weekly downloads
 

Readme

Source

fast-bitfield

A variable sized bitfield (based on indexed-bitfield) that allows you to quickly iterate over the bits.

npm install sparse-indexed-bitfield

Allocates a series of ~4kb bitfields (when needed) to store the underlying data efficiently.

Usage

const bitfield = require('fast-bitfield')

const bits = bitfield()

bits.set(1000, true)
bits.set(1000000000, true)

const ite = bits.iterator()

console.log(ite.next(true)) // 1000
console.log(ite.next(true)) // 1000000000
console.log(ite.next(true)) // -1

API

bits = bitfield()

Make a new fast bitfield

updated = bits.set(index, bool)

Set a bit.

Runs in O(log32(maxBitIndex)) worst case but often O(1)

bool = bits.get(index)

Get a bit.

Runs in O(log32(maxBitIndex))

bits.fill(val, [start], [end])

Set a range of bits efficiently.

iterator = bits.iterator()

Make a new bit iterator.

iterator.seek(index)

Move the iterator to start at index.

Runs in O(log32(maxBitIndex))

index = iterator.next(bit)

Returns the index of the next bit and -1 if none can be found.

Runs in O(log32(distanceToNextBit))

License

MIT

FAQs

Last updated on 11 Dec 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc