Giter VIP home page Giter VIP logo

bit-array's Introduction

bit-array

License: License: MIT Branches, Functions, Lines, Statements: Coverage Branches Coverage Functions Coverage Lines Coverage Statements

Save memory space by using a BitArray! Behind the scene, the library stores bits within elements of a Uint8Array resulting in memory space savings.

// ~256 bits in memory + overhead
const jsArray = [1, 0, 0, 1, 1, 0, 0, 0];

// ~8 bits in memory + overhead
const bitArray = new BitArray([1, 0, 0, 1, 1, 0, 0, 0]);

Size

2.9 KB

Installation

via npm

npm install bit-array

via yarn

yarn add bit-array

dev

npm install

yarn install

yarn start

Documentation

Usage

import BitArray from "../lib/bit-array";

const arr = new BitArray([0, 1, 0]);

arr.pushAll([1, 1, 1]);
// 0, 1, 0, 1, 1, 1

arr.push(0);
// 0, 1, 0, 1, 1, 1, 0

arr.atIndex(0);
// 0

arr.atIndexRange(0, 3);
// 0, 1, 0

console.log(arr.size)
// 7

Methods

Method Description
pushAll(values: Array<bit>) Pushes a an array of bits onto the array
push(value: bit) Pushes a single bit onto the array
atIndex(index: number) Gets the bit at a given index
atIndexRange(index: number, count?: number) Gets count bits at a given index. If count is null, the range goes to the end of the array
set(index: number, value: bit) Sets a specified bit at an index of the array

Properties

Property Description
size Gets the size of the array

Release notes

1.0.0

Initial release

  • pushAll(values: Array<bit>)
  • push(value: bit)
  • atIndex(index: number)
  • atIndexRange(index: number, count: number)
  • size

1.1.0

Added method set and made count parameter optional for atIndexRange

  • set(index: number, value: bit)
  • atIndexRange(index: number, count?: number)

1.2.0

Added code coverage badge creation on running tests

bit-array's People

Contributors

bubblesphere avatar

Stargazers

 avatar  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.