bitset_bm 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTlmMTRmMmFiYjI4NGJlY2RjZWJlMzA1MTYzZGRiZTg4MDQ3NjQxOA==
4
+ Y2RjOWU1MTJiNzVjYTRlODVmMTMzNWMwZTJiOTllM2ZlODZjNWZiMQ==
5
5
  data.tar.gz: !binary |-
6
- NDMxOTEyNzgxODUwYjA5ZTMxY2MwYzIwMzMwZmFkNzgzOWI5ODUyNg==
6
+ MTNlMmVlYzdjMjU0NzNhZWViZjY3ZDU5YzUwNDJiYjkzOWNiNjcyMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWI3Mzc4ZjM0MGZjMTE3ZjUyNzI5NWIyYTMyNmQxYWZmMGZjYWZkYjU3MDYz
10
- ZmU4MmIzMTU2NDA4MTM2MzFlMjc5YTE2MjE4MDQxNWZhMjhhMjNmMTFlMzQ3
11
- ODQzNTA1MDlkMjM4OGFiN2EyOTliNzExMTk4MWY1ODdmYTk0YmU=
9
+ MDY1ZWEwY2M3YTA1Njc5YTljM2RmYTQyMGI5MjYwMDUzZmFjNjlhNWI5ZWEy
10
+ YTRhZWNkZTg5ZWI2MDM1ZDBmNDU0YzRhZGJmNmMzYzNkZWQwNzNjNTk5NzNk
11
+ OTFlMjMzNGQ4YTFlYTNjNTEwZmEyYzFmNTYxZmNiODk3OTJlNWY=
12
12
  data.tar.gz: !binary |-
13
- NDNjZjJlMzFlMmE4MWEyNDZkYWNiMzhiNTZiZmE3OTlkNDU1Mjg1MzE3N2U1
14
- NTU0YzI5YWFjMzE2MjYxZmE3MTc2MTlhNTAzNjJiOGRiNWMxNDkwN2NlOGY2
15
- NzliOWQwY2Y1MTAwYjk3YWY4ZGZmZTU3ZTU1YzRiM2E1YjRiMWE=
13
+ NGNlODU0ZjI1YzA4MzQ1MTY2ZGRjOGIwZjM1ODYzYzQwMzQ2OWE3NTY3MGI1
14
+ Y2I0ODdhM2ViMTc1M2M5NDI5YTQ2NWJmYzg0Y2E4YjU1YmQ3MzQ1YzhhNzZh
15
+ Y2ZlZTgyMzNmOGE5YTY0ZjY3N2NhZDU1NWEyMmFmMjhhOWM4NWU=
data/.travis.yml CHANGED
@@ -2,4 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
4
  - "2.0.0"
5
- - "2.1.1"
5
+ - "2.1.1"
6
+ - "2.2.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitset_bm (1.0.0)
4
+ bitset_bm (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -25,5 +25,5 @@ PLATFORMS
25
25
  DEPENDENCIES
26
26
  bitset_bm!
27
27
  rake (~> 10.1)
28
- rake-compiler (~> 0.9, >= 0.9.2)
28
+ rake-compiler (>= 0.9.2)
29
29
  rspec (~> 2.0)
data/bitset.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_development_dependency "rspec", "~> 2.0"
30
30
  s.add_development_dependency "rake", "~> 10.1"
31
- s.add_development_dependency 'rake-compiler', '~> 0.9', '>= 0.9.2'
31
+ s.add_development_dependency 'rake-compiler', '>= 0.9.2'
32
32
  end
33
33
 
data/ext/bitset/bitset.c CHANGED
@@ -104,11 +104,21 @@ static VALUE rb_bitset_aset(VALUE self, VALUE index, VALUE value) {
104
104
  static VALUE rb_bitset_set(int argc, VALUE * argv, VALUE self) {
105
105
  int i;
106
106
  Bitset * bs = get_bitset(self);
107
- for(i = 0; i < argc; i++) {
108
- VALUE index = argv[i];
109
- int idx = NUM2INT(index);
110
- validate_index(bs, idx);
111
- set_bit(bs, idx);
107
+
108
+ if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_const_get(rb_cObject, rb_intern("Array")))) {
109
+ for(i = 0; i < RARRAY_LEN(argv[0]); i++) {
110
+ VALUE index = RARRAY_PTR(argv[0])[i];
111
+ int idx = NUM2INT(index);
112
+ validate_index(bs, idx);
113
+ set_bit(bs, idx);
114
+ }
115
+ } else {
116
+ for(i = 0; i < argc; i++) {
117
+ VALUE index = argv[i];
118
+ int idx = NUM2INT(index);
119
+ validate_index(bs, idx);
120
+ set_bit(bs, idx);
121
+ }
112
122
  }
113
123
  return Qtrue;
114
124
  }
@@ -116,11 +126,21 @@ static VALUE rb_bitset_set(int argc, VALUE * argv, VALUE self) {
116
126
  static VALUE rb_bitset_clear(int argc, VALUE * argv, VALUE self) {
117
127
  int i;
118
128
  Bitset * bs = get_bitset(self);
119
- for(i = 0; i < argc; i++) {
120
- VALUE index = argv[i];
121
- int idx = NUM2INT(index);
122
- validate_index(bs, idx);
123
- clear_bit(bs, idx);
129
+
130
+ if (argc == 1 && rb_obj_is_kind_of(argv[0], rb_const_get(rb_cObject, rb_intern("Array")))) {
131
+ for(i = 0; i < RARRAY_LEN(argv[0]); i++) {
132
+ VALUE index = RARRAY_PTR(argv[0])[i];
133
+ int idx = NUM2INT(index);
134
+ validate_index(bs, idx);
135
+ clear_bit(bs, idx);
136
+ }
137
+ } else {
138
+ for(i = 0; i < argc; i++) {
139
+ VALUE index = argv[i];
140
+ int idx = NUM2INT(index);
141
+ validate_index(bs, idx);
142
+ clear_bit(bs, idx);
143
+ }
124
144
  }
125
145
  return Qtrue;
126
146
  }
@@ -1,3 +1,3 @@
1
1
  module BitsetVersion
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/spec/bitset_spec.rb CHANGED
@@ -68,10 +68,22 @@ describe Bitset do
68
68
  bs[1].should == true
69
69
  bs[2].should == true
70
70
  bs[3].should == true
71
+ bs[4].should == false
72
+ end
73
+
74
+ it 'sets True for all given indexes when passed an array' do
75
+ bs = Bitset.new(8)
76
+ bs.set [1,2,3]
77
+
78
+ bs[1].should == true
79
+ bs[2].should == true
80
+ bs[3].should == true
81
+ bs[4].should == false
71
82
  end
72
83
  end
73
84
 
74
85
  describe :clear do
86
+
75
87
  it 'sets False for all given indexes' do
76
88
  bs = Bitset.new(8)
77
89
  bs.set 1,2,3
@@ -81,6 +93,17 @@ describe Bitset do
81
93
  bs[2].should == true
82
94
  bs[3].should == false
83
95
  end
96
+
97
+ it 'sets False for all given indexes' do
98
+ bs = Bitset.new(8)
99
+ bs.set [1,2,3]
100
+ bs.clear [1,3]
101
+
102
+ bs[1].should == false
103
+ bs[2].should == true
104
+ bs[3].should == false
105
+ end
106
+
84
107
  end
85
108
 
86
109
  describe :set? do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitset_bm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler McMullen
@@ -43,9 +43,6 @@ dependencies:
43
43
  name: rake-compiler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
47
- - !ruby/object:Gem::Version
48
- version: '0.9'
49
46
  - - ! '>='
50
47
  - !ruby/object:Gem::Version
51
48
  version: 0.9.2
@@ -53,9 +50,6 @@ dependencies:
53
50
  prerelease: false
54
51
  version_requirements: !ruby/object:Gem::Requirement
55
52
  requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- version: '0.9'
59
53
  - - ! '>='
60
54
  - !ruby/object:Gem::Version
61
55
  version: 0.9.2
@@ -102,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
96
  version: '0'
103
97
  requirements: []
104
98
  rubyforge_project:
105
- rubygems_version: 2.2.1
99
+ rubygems_version: 2.4.5
106
100
  signing_key:
107
101
  specification_version: 4
108
102
  summary: Bitset implementation.