fast-bitfield
Variable sized bitfield that allows you to quickly iterate over bits
Last updated 6 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install fast-bitfield 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.2.2                                ...           latest (6 years ago)

8 Versions

  • 1.2.2                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |