Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'peterc/master'

Conflicts:
	.gitignore
	Gemfile
	README.md
	Rakefile
	bitarray.gemspec
	lib/bitarray.rb
	test/test_bitarray.rb
  • Loading branch information...
commit 456625bfc4550100095581e8a4b103b94e911e3c 2 parents ee0d8b4 + 9fe36be
@mceachen mceachen authored
View
6 .gitignore
@@ -1,6 +1,4 @@
*.gem
-.idea/
-.yardoc/
-.bundle/
+.bundle
Gemfile.lock
-pkg/
+pkg/*
View
40 README.md
@@ -1,17 +1,22 @@
-# BitArray: A fast(ish), pure Ruby bit field "type"
+# BitArray: A simple bit array/bit field library in pure Ruby
-This is a simple rubygem wrapper for the class written by Peter Cooper and posted to dzone.
+Basic, pure Ruby bit field. Pretty fast (for what it is) and memory efficient. Works well for Bloom filters (the reason I wrote it).
-## 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)
+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
+
+```ruby
+gem install bitarray
+```
+
+## Examples
+
+To use:
-## Description
-Basic, pure Ruby bit array. Pretty fast (for what it is) and memory efficient.
-Works well for Bloom filters (the reason I wrote it).
+```ruby
+require 'bitarray'
+```
Create a bit array 1000 bits wide:
@@ -40,4 +45,15 @@ 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.
View
24 Rakefile
@@ -1,21 +1,5 @@
-begin
- require 'bundler/setup'
-rescue LoadError
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
-end
+require "bundler/gem_tasks"
+require "rake/testtask"
-Bundler::GemHelper.install_tasks
-
-require 'yard'
-YARD::Rake::YardocTask.new do |t|
- t.files = ['lib/**/*.rb', 'README.md']
-end
-
-require 'rake/testtask'
-
-Rake::TestTask.new do |t|
- t.libs << 'test'
-end
-
-desc "Run tests"
-task :default => :test
+Rake::TestTask.new # defaults are fine for now
+task :default => :test
View
25 bitarray.gemspec
@@ -1,23 +1,24 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "bitarray"
+
+require 'bitarray'
Gem::Specification.new do |s|
- s.name = "bitarray"
- s.version = BitArray::VERSION
- s.authors = ["Peter Cooper"]
- s.email = ["git@peterc.org"]
- s.homepage = "https://github.com/mceachen/bit-array/"
- s.summary = %q{A fast(ish), pure Ruby bit field "type"}
- s.description = %q{Rubygem packaging of Peter Cooper's BitArray class'}
+ s.name = "bitarray"
+ s.version = BitArray::VERSION
+ s.authors = ["Peter Cooper"]
+ s.email = ["git@peterc.org"]
+ s.homepage = "https://github.com/peterc/bitarray"
+ s.summary = %q{A simple, pure Ruby bit array implementation.}
+ s.description = %q{A simple, pure Ruby bit array implementation.}
s.rubyforge_project = "bitarray"
- s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
-
+
s.add_development_dependency "rake"
s.add_development_dependency "yard"
s.add_development_dependency "test-unit"
View
27 lib/bitarray.rb
@@ -1,30 +1,3 @@
-# NAME: BitArray
-# AUTHOR: Peter Cooper
-# LICENSE: MIT ( http://www.opensource.org/licenses/mit-license.php )
-# COPYRIGHT: (c) 2007 Peter Cooper (http://www.petercooper.co.uk/)
-# VERSION: v5
-# 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)
-#
-# DESCRIPTION: Basic, pure Ruby bit array. Pretty fast (for what it is) and memory efficient.
-# I've written a pretty intensive test suite for it and it passes great.
-# Works well for Bloom filters (the reason I wrote it).
-#
-# Create a bit array 1000 bits wide
-# ba = BitArray.new(1000)
-#
-# Setting and reading bits
-# ba[100] = 1
-# ba[100] .. => 1
-# ba[100] = 0
-#
-# More
-# ba.to_s = "10101000101010101" (example)
-# ba.total_set .. => 10 (example - 10 bits are set to "1")
-
class BitArray
attr_reader :size
include Enumerable
View
17 test/test_bitarray.rb
@@ -1,4 +1,5 @@
require "test/unit"
+require "bitarray"
class TestBitArray < Test::Unit::TestCase
@@ -62,16 +63,16 @@ def test_size
end
def test_to_s
- bf = BitArray.new(10)
- bf[1] = 1
- bf[5] = 1
- assert_equal "0100010000", bf.to_s
+ ba = BitArray.new(10)
+ ba[1] = 1
+ ba[5] = 1
+ assert_equal "0100010000", ba.to_s
end
def test_total_set
- bf = BitArray.new(10)
- bf[1] = 1
- bf[5] = 1
- assert_equal 2, bf.total_set
+ ba = BitArray.new(10)
+ ba[1] = 1
+ ba[5] = 1
+ assert_equal 2, ba.total_set
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.