Bitary
Ruby-based implementation of the bit array data structure.
It implements simple and well-optimized logic allowing you to set, unset and retrieve bits (as well as some extra features, see below).
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add bitary
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install bitary
Usage
Here is a breakdown of the main capabilities brought by the current implementation:
require 'bitary'
bit_array_sz = Bitary.new(128)
bit_array_ar = Bitary.new(
bytes: [255, 10, 20],
bpi: Bitary::BYTE
)
bit_array_sz.bpi
bit_array_ar.bpi
bit_array_ar.bits
bit_array_ar.bits
bit_array_sz[23] = 1
bit_array_sz[23]
bit_array_sz[32]
bit_array_ar[0]
bit_array_ar[0] = 0
bit_array_ar[0]
bit_array_sz.each_byte do |byte|
end
bit_array_ar.to_a
bit_array_ar.to_s
bit_array_ar.bpi = Bitary::LONG
bit_array_ar.to_a
bit_array_ar.to_s
bit_array_sz.bpi
bit_array_sz.to_a
bit_array_sz.bpi = Bitary::INT
bit_array_sz.to_a
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests and rake rubocop
to lint your code. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Access the technical documentation in HTML format by issuing:
$ bundle exec yardoc
The YARD documentation will be generated under /doc
.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Patacode/bitary.
License
The gem is available as open source under the terms of the MIT License.