]> git.donarmstrong.com Git - biopieces.git/commitdiff
revoked to old working version of each_interval in bitarray.rb
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 19 Oct 2011 19:01:42 +0000 (19:01 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Wed, 19 Oct 2011 19:01:42 +0000 (19:01 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@1588 74ccb610-7750-0410-82ae-013aeee3265d

code_ruby/lib/maasha/bitarray.rb
code_ruby/test/maasha/test_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
 
index 6ec38eba70f6d5719428c894cd2a15ad8c8afd80..b1fcaa0d17a16435b5b5b4b4bfc81c6cb5fae3d1 100755 (executable)
@@ -201,7 +201,7 @@ class TestBitArray < Test::Unit::TestCase
     @ba.fill!
     @ba.bit_unset(4)
     
-    assert_equal([[0, 4], [5, 10]], @ba.each_interval.to_a)
+    assert_equal([[0, 3], [5, 9]], @ba.each_interval.to_a)
   end
 end