Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/has_many_booleans/simple_bitset.rb
Overview
binary representation/bitset: store an array of indices in one decimal number
Instance Method Summary collapse
-
#to_bra ⇒ Object
Generates an array consisting of the set bit indexes.
Instance Method Details
#to_bra ⇒ Object
Generates an array consisting of the set bit indexes.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/has_many_booleans/simple_bitset.rb', line 16 def to_bra # to binary representation array ret = [] i = 0 while self >= x = x ? x*2 : 1 ret << i if 0 < self[i] # ruby sugar: bit is set? i+=1 end ret end |