]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/bitarray.rb
bitarray.rb bits_on method speedup x 3
[biopieces.git] / code_ruby / lib / maasha / bitarray.rb
index d054eb07a5db394ae12e1e1634dc391b21c11376..4cb77b4ce8c53d65c1791d02a99e449301a8c20e 100644 (file)
@@ -54,15 +54,15 @@ class BitArray
     raise BitArrayError, "Position #{pos} must be an integer."              unless pos.is_a? Fixnum
     raise BitArrayError, "Position #{pos} outside of range: 0 ... #{@size}" unless (0 ... @size ).include? pos
 
-    (@byte_array[byte_pos(pos)].ord & bit_pos(pos)) != 0
+    (@byte_array[byte_pos(pos)] & bit_pos(pos)) != 0
   end
 
   # Method that returns the number of bits set "on" in a bit array.
   def bits_on 
     bits_on = 0
 
-    (0 ... self.byte_array.size).each do |byte|
-      bits_on += @count_array[self.byte_array[byte].ord]
+    self.byte_array.each do |byte|
+      bits_on += @count_array[byte]
     end
 
     bits_on
@@ -130,11 +130,6 @@ class BitArray
     raise BitArrayError, "Size must be an integer, not #{@size}" unless @size.is_a? Fixnum
     raise BitArrayError, "Size must be positive, not #{@size}"   unless @size > 0
 
-    byte_array = ""
-    byte_array << 0.chr * (((@size - 1) / BitsInChar) + 1)
-
-    byte_array
-
     NArray.byte(((@size - 1) / BitsInChar) + 1)
   end