summaryrefslogtreecommitdiff
path: root/tool/lrama/lib/lrama/bitmap.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lrama/lib/lrama/bitmap.rb')
-rw-r--r--tool/lrama/lib/lrama/bitmap.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/tool/lrama/lib/lrama/bitmap.rb b/tool/lrama/lib/lrama/bitmap.rb
new file mode 100644
index 0000000000..8349a23c34
--- /dev/null
+++ b/tool/lrama/lib/lrama/bitmap.rb
@@ -0,0 +1,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