[Archipelago-submits] [254] trunk/oneliner/lib/oneliner/superstring.rb: even more tries at optimizing

nobody at rubyforge.org nobody at rubyforge.org
Wed Mar 28 12:04:57 EDT 2007


Revision: 254
Author:   zond
Date:     2007-03-28 12:04:57 -0400 (Wed, 28 Mar 2007)

Log Message:
-----------
even more tries at optimizing

Modified Paths:
--------------
    trunk/oneliner/lib/oneliner/superstring.rb

Modified: trunk/oneliner/lib/oneliner/superstring.rb
===================================================================
--- trunk/oneliner/lib/oneliner/superstring.rb	2007-03-28 16:00:00 UTC (rev 253)
+++ trunk/oneliner/lib/oneliner/superstring.rb	2007-03-28 16:04:57 UTC (rev 254)
@@ -85,7 +85,7 @@
 
       if @known_nr_of_blocks > @nr_of_blocks
         interesting = true
-        interesting = decode_chunk(chunk_data) unless first_decode
+        interesting, informative = decode_chunk(chunk_data) unless first_decode
 
         while interesting
           interesting = do_decode(context)
@@ -198,8 +198,9 @@
 
     def do_decode(context)
       found_new_block = false
-      @known_chunks.each do |chunk_data|
-        found_new_block = decode_chunk(chunk_data) || found_new_block
+      @known_chunks.clone.each_with_index do |chunk_data, i|
+        found_new_block, informative = decode_chunk(chunk_data) || found_new_block
+        @known_chunks.delete(i) unless informative
       end
       found_new_block = aux_decode || found_new_block
       return found_new_block
@@ -250,16 +251,18 @@
 
     def decode_chunk(chunk_data)
       got_new_block = false
+      got_informative_block = false
 
       blocks = chunk_data[:blocks]
       blocks.each_with_index do |block, i|
 
         if block
 
+          got_informative_block = true
+
           block_metadata = chunk_data[:block_metadata][i]
-          degree = block_metadata[:degree]
           
-          if degree == 1
+          if (degree = block_metadata[:degree]) == 1
             block_nr = block_metadata[:blocks].first
             
             if @blocks[block_nr].nil?
@@ -273,12 +276,12 @@
               blocks[i] = nil
             end
           end
-          
+
         end
 
       end
       
-      return got_new_block
+      return [got_new_block, got_informative_block]
     end
     
     def generate_aux_hash




More information about the Archipelago-submits mailing list