Skip to content

Commit 456625b

Browse files
committed
Merge remote-tracking branch 'peterc/master'
Conflicts: .gitignore Gemfile README.md Rakefile bitarray.gemspec lib/bitarray.rb test/test_bitarray.rb
2 parents ee0d8b4 + 9fe36be commit 456625b

File tree

6 files changed

+56
-83
lines changed

6 files changed

+56
-83
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
*.gem
2-
.idea/
3-
.yardoc/
4-
.bundle/
2+
.bundle
53
Gemfile.lock
6-
pkg/
4+
pkg/*

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
# BitArray: A fast(ish), pure Ruby bit field "type"
1+
# BitArray: A simple bit array/bit field library in pure Ruby
22

3-
This is a simple rubygem wrapper for the class written by Peter Cooper and posted to dzone.
3+
Basic, pure Ruby bit field. Pretty fast (for what it is) and memory efficient. Works well for Bloom filters (the reason I wrote it).
44

5-
## History
6-
- v5 (added support for flags being on by default, instead of off)
7-
- v4 (fixed bug where setting 0 bits to 0 caused a set to 1)
8-
- v3 (supports dynamic bitwidths for array elements.. now doing 32 bit widths default)
9-
- v2 (now uses 1 << y, rather than 2 ** y .. it's 21.8 times faster!)
10-
- v1 (first release)
5+
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.
6+
7+
## Installation
8+
9+
```ruby
10+
gem install bitarray
11+
```
12+
13+
## Examples
14+
15+
To use:
1116

12-
## Description
13-
Basic, pure Ruby bit array. Pretty fast (for what it is) and memory efficient.
14-
Works well for Bloom filters (the reason I wrote it).
17+
```ruby
18+
require 'bitarray'
19+
```
1520

1621
Create a bit array 1000 bits wide:
1722

@@ -40,4 +45,15 @@ ba.to_s
4045
#=> "01010100010101010000"
4146
ba.total_set
4247
#=> 7
43-
```
48+
```
49+
50+
## History
51+
- v5 (added support for flags being on by default, instead of off)
52+
- v4 (fixed bug where setting 0 bits to 0 caused a set to 1)
53+
- v3 (supports dynamic bitwidths for array elements.. now doing 32 bit widths default)
54+
- v2 (now uses 1 << y, rather than 2 ** y .. it's 21.8 times faster!)
55+
- v1 (first release)
56+
57+
## License
58+
59+
MIT licensed. Copyright 2007-2012 Peter Cooper, yada yada.

Rakefile

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
begin
2-
require 'bundler/setup'
3-
rescue LoadError
4-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5-
end
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
63

7-
Bundler::GemHelper.install_tasks
8-
9-
require 'yard'
10-
YARD::Rake::YardocTask.new do |t|
11-
t.files = ['lib/**/*.rb', 'README.md']
12-
end
13-
14-
require 'rake/testtask'
15-
16-
Rake::TestTask.new do |t|
17-
t.libs << 'test'
18-
end
19-
20-
desc "Run tests"
21-
task :default => :test
4+
Rake::TestTask.new # defaults are fine for now
5+
task :default => :test

bitarray.gemspec

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
# -*- encoding: utf-8 -*-
22
$:.push File.expand_path("../lib", __FILE__)
3-
require "bitarray"
3+
4+
require 'bitarray'
45

56
Gem::Specification.new do |s|
6-
s.name = "bitarray"
7-
s.version = BitArray::VERSION
8-
s.authors = ["Peter Cooper"]
9-
s.email = ["git@peterc.org"]
10-
s.homepage = "https://github.com/mceachen/bit-array/"
11-
s.summary = %q{A fast(ish), pure Ruby bit field "type"}
12-
s.description = %q{Rubygem packaging of Peter Cooper's BitArray class'}
7+
s.name = "bitarray"
8+
s.version = BitArray::VERSION
9+
s.authors = ["Peter Cooper"]
10+
s.email = ["git@peterc.org"]
11+
s.homepage = "https://github.com/peterc/bitarray"
12+
s.summary = %q{A simple, pure Ruby bit array implementation.}
13+
s.description = %q{A simple, pure Ruby bit array implementation.}
1314

1415
s.rubyforge_project = "bitarray"
1516

16-
s.files = `git ls-files`.split("\n")
17-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18-
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17+
s.files = `git ls-files`.split("\n")
18+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
1920
s.require_paths = ["lib"]
20-
21+
2122
s.add_development_dependency "rake"
2223
s.add_development_dependency "yard"
2324
s.add_development_dependency "test-unit"

lib/bitarray.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# NAME: BitArray
2-
# AUTHOR: Peter Cooper
3-
# LICENSE: MIT ( http://www.opensource.org/licenses/mit-license.php )
4-
# COPYRIGHT: (c) 2007 Peter Cooper (http://www.petercooper.co.uk/)
5-
# VERSION: v5
6-
# HISTORY: v5 (added support for flags being on by default, instead of off)
7-
# v4 (fixed bug where setting 0 bits to 0 caused a set to 1)
8-
# v3 (supports dynamic bitwidths for array elements.. now doing 32 bit widths default)
9-
# v2 (now uses 1 << y, rather than 2 ** y .. it's 21.8 times faster!)
10-
# v1 (first release)
11-
#
12-
# DESCRIPTION: Basic, pure Ruby bit array. Pretty fast (for what it is) and memory efficient.
13-
# I've written a pretty intensive test suite for it and it passes great.
14-
# Works well for Bloom filters (the reason I wrote it).
15-
#
16-
# Create a bit array 1000 bits wide
17-
# ba = BitArray.new(1000)
18-
#
19-
# Setting and reading bits
20-
# ba[100] = 1
21-
# ba[100] .. => 1
22-
# ba[100] = 0
23-
#
24-
# More
25-
# ba.to_s = "10101000101010101" (example)
26-
# ba.total_set .. => 10 (example - 10 bits are set to "1")
27-
281
class BitArray
292
attr_reader :size
303
include Enumerable

test/test_bitarray.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "test/unit"
2+
require "bitarray"
23

34
class TestBitArray < Test::Unit::TestCase
45

@@ -62,16 +63,16 @@ def test_size
6263
end
6364

6465
def test_to_s
65-
bf = BitArray.new(10)
66-
bf[1] = 1
67-
bf[5] = 1
68-
assert_equal "0100010000", bf.to_s
66+
ba = BitArray.new(10)
67+
ba[1] = 1
68+
ba[5] = 1
69+
assert_equal "0100010000", ba.to_s
6970
end
7071

7172
def test_total_set
72-
bf = BitArray.new(10)
73-
bf[1] = 1
74-
bf[5] = 1
75-
assert_equal 2, bf.total_set
73+
ba = BitArray.new(10)
74+
ba[1] = 1
75+
ba[5] = 1
76+
assert_equal 2, ba.total_set
7677
end
7778
end

0 commit comments

Comments
 (0)