Module: Lrama::Bitmap

Defined in:
lib/lrama/bitmap.rb

Class Method Summary collapse

Class Method Details

.from_array(ary) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/lrama/bitmap.rb', line 3

def self.from_array(ary)
  bit = 0

  ary.each do |int|
    bit |= (1 << int)
  end

  bit
end

.to_array(int) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lrama/bitmap.rb', line 13

def self.to_array(int)
  a = []
  i = 0

  while int > 0 do
    if int & 1 == 1
      a << i
    end

    i += 1
    int >>= 1
  end

  a
end