Simple Bit array class to hold state for our tree drawing class.
create a bit store using Fixnum. Initialize to 0.
# File lib/chart/bit.rb, line 5 def initialize(bm = 0) @bm = bm end
Set bit i to 0.
# File lib/chart/bit.rb, line 15 def clear(i) @bm &= 0 << i end
Return true if bit i is clear
# File lib/chart/bit.rb, line 25 def clear?(i) @bm[i] == 0 end
set the bit i to 1. Relies on auto promotion of Fixnum to Bignum.
# File lib/chart/bit.rb, line 10 def set(i) @bm |= 1 << i end
Return true if bit i is set
# File lib/chart/bit.rb, line 20 def set?(i) @bm[i] == 1 end
print the Bit array as a binary number.
# File lib/chart/bit.rb, line 30 def to_s @bm.to_s(2) end