Coder Social home page Coder Social logo

bitarray's Introduction

BitArray: A simple bit array/bit field library in pure Ruby

Basic, pure Ruby bit field. Pretty fast (for what it is) and memory efficient. Works well for Bloom filters (the reason I wrote it).

Written in 2007 and not updated since then, just bringing it on to GitHub by user request. It used to be called BitField and was hosted at http://snippets.dzone.com/posts/show/4234 .. I will review the code and bring the docs up to date in due course.

Installation

gem install bitarray

Examples

To use:

require 'bitarray'

Create a bit array 1000 bits wide:

ba = BitArray.new(1000)

Setting and reading bits:

ba[100] = 1
ba[100]
#=> 1

ba[100] = 0
ba[100]
#=> 0

More:

ba = BitArray.new(20)
[1,3,5,9,11,13,15].each { |i| ba[i] = 1 }
ba.to_s
#=> "01010100010101010000"
ba.total_set
#=> 7

History

  • v5 (added support for flags being on by default, instead of off)
  • v4 (fixed bug where setting 0 bits to 0 caused a set to 1)
  • v3 (supports dynamic bitwidths for array elements.. now doing 32 bit widths default)
  • v2 (now uses 1 << y, rather than 2 ** y .. it's 21.8 times faster!)
  • v1 (first release)

License

MIT licensed. Copyright 2007-2012 Peter Cooper, yada yada.

bitarray's People

Contributors

mceachen avatar peterc avatar

Stargazers

 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.