GithubHelp home page GithubHelp logo

alexxnica / bitfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fb55/bitfield

0.0 1.0 0.0 28 KB

a very simple bitfield implementation using buffers

License: MIT License

JavaScript 100.00%

bitfield's Introduction

#bitfield

a very simple bitfield, compliant with the Bittorrent spec

npm install bitfield

browser support

####Example

var Bitfield = require("bitfield");

var field = new Bitfield(256); //create a bitfield with 256 bits

field.set(128); //set the 128th bit
field.set(128, true); //same as above

field.get(128); //true
field.get(200); //false (all values are initialised to `false`)
field.get(1e3); //false (out-of-bounds is also false)

field.set(128, false); //set the 128th bit to 0 again

field.buffer; //the buffer used by bitfield

####Methods Bitfield(data): data can be either a node.js buffer, WebGL Int8Array or numeric array, or a number representing the maximum number of supported bytes.

Bitfield#get(index): Returns a boolean indicating whether the bit is set.

Bitfield#set(index[, value]): value defaults to true. Sets the bit to 1 for a value of true or 0 for false.

Auto-grow mode

Bitfield(data, { grow: size }): If you set an index that is out-of-bounds, the Bitfield will automatically grow so that the bitfield is big enough to contain the given index, up to the given size (in bit). If you want the Bitfield to grow indefinitely, pass Infinity as the size.

####Properties Bitfield#buffer: The contents of the bitfield.

Bitfield#grow: The passed growth option (defaults to 0).

##License

MIT

bitfield's People

Contributors

fb55 avatar feross avatar mafintosh avatar astro avatar transitive-bullshit avatar greenkeeper[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.