Skip to content

Commit 978833b

Browse files
committed
Merge master
2 parents 0c7de3e + f1b4d40 commit 978833b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ ba.total_set
4848
```
4949

5050
## History
51-
- 2.0.0 in 2018 (Changed bits order to be compliant with Redis' setbit/getbit and fixed initialize with custom field)
52-
- 1.0.0 in 2017 (updated for modern Ruby, more efficient storage, and 10th birthday)
51+
- 2.0.0 in 2018 (Changed bits order to be compliant with Redis' setbit/getbit)
52+
- 1.1 in 2018 (fixed a significant bug)
53+
- 1.0 in 2017 (updated for modern Ruby, more efficient storage, and 10th birthday)
5354
- 0.0.1 in 2012 (original v5 released on GitHub)
5455
- v5 (added support for flags being on by default, instead of off)
5556
- v4 (fixed bug where setting 0 bits to 0 caused a set to 1)
@@ -61,6 +62,8 @@ ba.total_set
6162

6263
Thanks to Michael Slade for encouraging me to update this library on its 10th birthday and for suggesting finally using String's getbyte and setbyte methods now that we're all on 1.9+ compatible implementations.
6364

65+
Further thanks to @tdeo, @JoshuaSP, and @m1lt0n for pull requests.
66+
6467
## License
6568

66-
MIT licensed. Copyright 2007-2017 Peter Cooper.
69+
MIT licensed. Copyright 2007-2018 Peter Cooper.

lib/bitarray-array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class BitArray
33
attr_reader :field
44
include Enumerable
55

6-
VERSION = "1.0.0"
6+
VERSION = "2.0.0"
77
ELEMENT_WIDTH = 32
88

99
def initialize(size, field = nil)

lib/bitarray.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def []=(position, value)
1515
if value == 1
1616
@field.setbyte(position >> 3, @field.getbyte(position >> 3) | (1 << (7 - position % 8)))
1717
else
18-
@field.setbyte(position >> 3, @field.getbyte(position >> 3) ^ (1 << (7 - position % 8)))
18+
@field.setbyte(position >> 3, @field.getbyte(position >> 3) & ~(1 << (7 - position % 8)))
1919
end
2020
end
2121

test/test_bitarray.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ def test_random_setting_and_unsetting
3030

3131
def test_multiple_setting
3232
1.upto(999) do |pos|
33-
2.times { @public_ba[pos] = 1 }
34-
assert_equal 1, @public_ba[pos]
33+
2.times do
34+
@public_ba[pos] = 1
35+
assert_equal 1, @public_ba[pos]
36+
end
3537
end
3638
end
3739

3840
def test_multiple_unsetting
3941
1.upto(999) do |pos|
40-
2.times { @public_ba[pos] = 0 }
41-
assert_equal 0, @public_ba[pos]
42+
2.times do
43+
@public_ba[pos] = 0
44+
assert_equal 0, @public_ba[pos]
45+
end
4246
end
4347
end
4448

0 commit comments

Comments
 (0)