sparse-bitfield

WebJar for sparse-bitfield

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

sparse-bitfield
Last Version

Last Version

3.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

sparse-bitfield
WebJar for sparse-bitfield
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mafintosh/sparse-bitfield

Download sparse-bitfield

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/sparse-bitfield/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>sparse-bitfield</artifactId>
    <version>3.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/sparse-bitfield/
implementation 'org.webjars.npm:sparse-bitfield:3.0.3'
// https://jarcasting.com/artifacts/org.webjars.npm/sparse-bitfield/
implementation ("org.webjars.npm:sparse-bitfield:3.0.3")
'org.webjars.npm:sparse-bitfield:jar:3.0.3'
<dependency org="org.webjars.npm" name="sparse-bitfield" rev="3.0.3">
  <artifact name="sparse-bitfield" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='sparse-bitfield', version='3.0.3')
)
libraryDependencies += "org.webjars.npm" % "sparse-bitfield" % "3.0.3"
[org.webjars.npm/sparse-bitfield "3.0.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : memory-pager jar [1.0.2,2)

Project Modules

There are no modules declared in this project.

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

build status

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([options])

Create a new bitfield. Options include

{
  pageSize: 1024, // how big should the partial buffers be
  buffer: anExistingBitfield,
  trackUpdates: false // track when pages are being updated in the pager
}

bits.set(index, value)

Set a bit to true or false.

bits.get(index)

Get the value of a bit.

bits.pages

A memory-pager instance that is managing the underlying memory. If you set trackUpdates to true in the constructor you can use .lastUpdate() on this instance to get the last updated memory page.

var buffer = bits.toBuffer()

Get a single buffer representing the entire bitfield.

License

MIT

Versions

Version
3.0.3