# fast-bitfield

> Variable sized bitfield that allows you to quickly iterate over bits

Latest version **1.2.2** (published 2018-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install fast-bitfield
pnpm add fast-bitfield
yarn add fast-bitfield
bun add fast-bitfield
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2018-12-11 |
| First published | 2018-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/fast-bitfield
- Repository: https://github.com/mafintosh/fast-bitfield
- Issues: https://github.com/mafintosh/fast-bitfield/issues
- npm.io page: https://npm.io/package/fast-bitfield

## Dependencies (1)

- [count-trailing-zeros](https://npm.io/package/count-trailing-zeros.md) ^1.0.1

## Recent versions

- 1.2.2 (latest) — 2018-12-11
- 1.2.1 — 2018-08-21
- 1.2.0 — 2018-08-20
- 1.1.2 — 2018-08-20
- 1.1.1 — 2018-08-20
- 1.1.0 — 2018-08-20
- 1.0.1 — 2018-08-17
- 1.0.0 — 2018-08-16

## README

# fast-bitfield

A variable sized bitfield (based on [indexed-bitfield](https://github.com/mafintosh/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

``` js
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

---
_Source: https://npm.io/package/fast-bitfield · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
