summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/bitmap.rb
blob: 8349a23c344b1ae6691837d161bb4b2d192d5e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Lrama
  module Bitmap
    def self.from_array(ary)
      bit = 0

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

      bit
    end

    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
  end
end