bitset 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -18
- data/VERSION +1 -1
- data/ext/bitset/bitset.c +13 -0
- data/spec/bitset_spec.rb +14 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
=
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to bitset
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2011 Tyler McMullen. See LICENSE.txt for
|
18
|
-
further details.
|
1
|
+
= Bitset
|
19
2
|
|
3
|
+
A fast Bitset implementation for Ruby. Available as the 'bitset' gem.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/ext/bitset/bitset.c
CHANGED
@@ -250,8 +250,20 @@ static VALUE rb_bitset_hamming(VALUE self, VALUE other) {
|
|
250
250
|
return INT2NUM(count);
|
251
251
|
}
|
252
252
|
|
253
|
+
static VALUE rb_bitset_each(VALUE self) {
|
254
|
+
Bitset * bs = get_bitset(self);
|
255
|
+
int i;
|
256
|
+
|
257
|
+
for(i = 0; i < bs->len; i++) {
|
258
|
+
rb_yield(get_bit(bs, i) > 0 ? Qtrue : Qfalse);
|
259
|
+
}
|
260
|
+
|
261
|
+
return self;
|
262
|
+
}
|
263
|
+
|
253
264
|
void Init_bitset() {
|
254
265
|
cBitset = rb_define_class("Bitset", rb_cObject);
|
266
|
+
rb_include_module(cBitset, rb_mEnumerable);
|
255
267
|
rb_define_alloc_func(cBitset, rb_bitset_alloc);
|
256
268
|
rb_define_method(cBitset, "initialize", rb_bitset_initialize, 1);
|
257
269
|
rb_define_method(cBitset, "size", rb_bitset_size, 0);
|
@@ -272,4 +284,5 @@ void Init_bitset() {
|
|
272
284
|
rb_define_alias(cBitset, "^", "xor");
|
273
285
|
rb_define_alias(cBitset, "symmetric_difference", "xor");
|
274
286
|
rb_define_method(cBitset, "hamming", rb_bitset_hamming, 1);
|
287
|
+
rb_define_method(cBitset, "each", rb_bitset_each, 0);
|
275
288
|
}
|
data/spec/bitset_spec.rb
CHANGED
@@ -200,4 +200,18 @@ describe Bitset do
|
|
200
200
|
bs1.hamming(bs2).should == 3
|
201
201
|
end
|
202
202
|
end
|
203
|
+
|
204
|
+
describe :each do
|
205
|
+
it 'iterates over the bits in the Bitset' do
|
206
|
+
bs = Bitset.new(4)
|
207
|
+
bs.set 0, 2
|
208
|
+
|
209
|
+
i = 0
|
210
|
+
bs.each do |bit|
|
211
|
+
bit.should == bs[i]
|
212
|
+
i += 1
|
213
|
+
end
|
214
|
+
i.should == 4
|
215
|
+
end
|
216
|
+
end
|
203
217
|
end
|