]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_ruby/lib/maasha/bitarray.rb
fixed method name change
[biopieces.git] / code_ruby / lib / maasha / bitarray.rb
index 114bc26474c7acc4019e1cd27e66b325f8d5a928..81568a08db13c944e70de2c069840ae8a98df072 100644 (file)
@@ -221,63 +221,25 @@ class BitArray
   # Method to locate intervals of bits set to "on" in a bit array.
   #   BitArray.each_interval -> Array
   #   BitArray.each_interval { |start, stop| } -> Fixnum
-  def each_interval_old
+  def each_interval
     intervals = []
     bit_start = 0
     bit_stop  = 0
 
     while bit_start < self.size
       bit_start += 1 while bit_start < self.size and not self.bit_set?(bit_start)
-      bit_stop = bit_start
-      bit_stop  += 1 while bit_stop < self.size and self.bit_set?(bit_stop)
-
-      if block_given?
-        yield bit_start, bit_stop
-      else
-        intervals << [bit_start, bit_stop]
-      end
-
-      bit_start = bit_stop + 1
-    end
-
-    return intervals unless block_given?
-  end
-
-  # Method to locate intervals of bits set to "on" in a bit array.
-  #   BitArray.each_interval -> Array
-  #   BitArray.each_interval { |start, stop| } -> Fixnum
-  def each_interval
-    intervals  = []
-    byte_start = 0
-    bit_start  = 0
-
-    while bit_start < self.size
-#      puts "0 byte_start: #{byte_start}   bit_start: #{bit_start}"
-      byte_start += 1 while byte_start < self.byte_array.size and self.byte_array[byte_start] == 0
-      bit_start  += byte_start * BitsInChar
-      bit_start  += 1 while bit_start < self.size and not self.bit_set?(bit_start)
-
-#      puts "1 byte_start: #{byte_start}   bit_start: #{bit_start}"
 
       if bit_start < self.size
-        bit_stop   = bit_start
-        byte_stop  = byte_start
-#        puts "1.5 byte_stop: #{byte_stop}   bit_stop: #{bit_stop}"
-        byte_stop += 1 while byte_stop < self.byte_array.size and self.byte_array[byte_stop] == ~0
-        bit_stop  += (byte_stop - byte_start) * BitsInChar
-#        puts "1.5 byte_stop: #{byte_stop}   bit_stop: #{bit_stop}"
+        bit_stop = bit_start
         bit_stop  += 1 while bit_stop < self.size and self.bit_set?(bit_stop)
 
-#        puts "2 byte_stop: #{byte_stop}   bit_stop: #{bit_stop}"
-
         if block_given?
           yield bit_start, bit_stop - 1
         else
           intervals << [bit_start, bit_stop - 1]
         end
 
-        byte_start  = byte_stop
-        bit_start   = bit_stop + 1
+        bit_start = bit_stop + 1
       end
     end