title: Fastest and most effective way of comparing two array of hashes of different format
body: <p>I have two arrays of hashes with the format:</p>
  
  <p>hash1</p>
  
  <pre><code>[{:root =&gt; root_value, :child1 =&gt; child1_value, :subchild1 =&gt; subchild1_value, bases =&gt; hit1,hit2,hit3}...]
  </code></pre>
  
  <p>hash2</p>
  
  <pre><code>[{:path =&gt; root_value/child1_value/subchild1_value, :hit1_exist =&gt; t ,hit2_exist =&gt; t,hit3_exist =&gt; f}...]
  </code></pre>
  
  <hr>
  
  <p>IF I do this</p>
  
  <pre><code>Def sample
    results = nil
    project = Project.find(params[:project_id])
    testrun_query = "SELECT root_name, suite_name, case_name, ic_name, executed_platforms FROM testrun_caches WHERE start_date &gt;= '#{params[:start_date]}' AND start_date &lt; '#{params[:end_date]}' AND project_id = #{params[:project_id]} AND result &lt;&gt; 'SKIP' AND result &lt;&gt; 'N/A'"
    if !params[:platform].nil? &amp;&amp; params[:platform] != [""]
      #yell_and_log "platform not nil"
      platform_query = nil
      params[:platform].each do |platform|
        if platform_query.nil?
          platform_query = " AND (executed_platforms LIKE '%#{platform.to_s},%'"
        else
          platform_query += " OR executed_platforms LIKE '%#{platform.to_s},%'"
        end
      end
      testrun_query += ")" + platform_query
    end
    if !params[:location].nil? &amp;&amp;!params[:location].empty?
      #yell_and_log "location not nil"
      testrun_query += "AND location LIKE '#{params[:location].to_s}%'"    
    end
    testrun_query += " GROUP BY root_name, suite_name, case_name, ic_name,   executed_platforms ORDER BY root_name, suite_name, case_name, ic_name"
    ic_query = "SELECT ics.path, memberships.pts8210, memberships.sv6, memberships.sv7,   memberships.pts14k, memberships.pts22k, memberships.pts24k, memberships.spb32, memberships.spb64, memberships.sde, projects.name FROM ics INNER JOIN memberships on memberships.ic_id = ics.id INNER JOIN test_groups ON test_groups.id = memberships.test_group_id INNER JOIN projects ON test_groups.project_id = projects.id WHERE deleted = 'false' AND (memberships.pts8210 = true OR memberships.sv6 = true OR memberships.sv7 = true OR memberships.pts14k = true OR memberships.pts22k = true OR memberships.pts24k = true OR memberships.spb32 = true OR memberships.spb64 = true OR memberships.sde = true) AND projects.name = '#{project.name}' GROUP BY path, memberships.pts8210, memberships.sv6, memberships.sv7, memberships.pts14k, memberships.pts22k, memberships.pts24k, memberships.spb32, memberships.spb64, memberships.sde, projects.name ORDER BY ics.path"
    if params[:ic_type] == "never_run"
      runtest = TestrunCache.connection.select_all(testrun_query)
      alltest = TrsIc.connection.select_all(ic_query) 
      (alltest.length).times do |i|
        #exec_pltfrm = test['executed_platforms'].split(",")
        unfinishedtest = comparison(runtest[i],alltest[i])
        yell_and_log("test = #{unfinishedtest}")
        yell_and_log("#{runtest[i]}")
        yell_and_log("#{alltest[i]}")
      end
    end
  end
  </code></pre>
  
  <p>I get in my log: </p>
  
  <pre><code>test = true
  array of hash 1 = {"root_name"=&gt;"BSDPLATFORM", "suite_name"=&gt;"cli",  "case_name"=&gt;"functional", "ic_name"=&gt;"cli_sanity_test", "executed_platforms"=&gt;"pts22k,pts24k,sv7,"}
  array of hash 2 = {"path"=&gt;"BSDPLATFORM/cli/functional/cli_sanity_test", "pts8210"=&gt;"f", "sv6"=&gt;"f", "sv7"=&gt;"t", "pts14k"=&gt;nil, "pts22k"=&gt;"t", "pts24k"=&gt;"t", "spb32"=&gt;nil, "spb64"=&gt;nil, "sde"=&gt;nil, "name"=&gt;"pts_6_20"}
  test = false
  array of hash 1 = {"root_name"=&gt;"BSDPLATFORM", "suite_name"=&gt;"infrastructure", "case_name"=&gt;"bypass_pts14k_copper", "ic_name"=&gt;"ic_packet_9", "executed_platforms"=&gt;"sv6,"}
  array of hash 2 = {"path"=&gt;"BSDPLATFORM/infrastructure/build/copyrights", "pts8210"=&gt;"f", "sv6"=&gt;"t", "sv7"=&gt;"t", "pts14k"=&gt;"f", "pts22k"=&gt;"t", "pts24k"=&gt;"t", "spb32"=&gt;"f", "spb64"=&gt;nil, "sde"=&gt;nil, "name"=&gt;"pts_6_20"}
  test = false
  array of hash 1 = {"root_name"=&gt;"BSDPLATFORM", "suite_name"=&gt;"infrastructure", "case_name"=&gt;"bypass_pts14k_copper", "ic_name"=&gt;"ic_status_1", "executed_platforms"=&gt;"sv6,"}
  array of hash 2 = {"path"=&gt;"BSDPLATFORM/infrastructure/build/ic_1", "pts8210"=&gt;"f", "sv6"=&gt;"t", "sv7"=&gt;"t", "pts14k"=&gt;"f", "pts22k"=&gt;"t", "pts24k"=&gt;"t", "spb32"=&gt;"f", "spb64"=&gt;nil, "sde"=&gt;nil, "name"=&gt;"pts_6_20"}
  test = false
  array of hash 1 = {"root_name"=&gt;"BSDPLATFORM", "suite_name"=&gt;"infrastructure", "case_name"=&gt;"bypass_pts14k_copper", "ic_name"=&gt;"ic_status_2", "executed_platforms"=&gt;"sv6,"}
  array of hash 2 = {"path"=&gt;"BSDPLATFORM/infrastructure/build/ic_files", "pts8210"=&gt;"f", "sv6"=&gt;"t", "sv7"=&gt;"f", "pts14k"=&gt;"f", "pts22k"=&gt;"t", "pts24k"=&gt;"t", "spb32"=&gt;"f", "spb64"=&gt;nil, "sde"=&gt;nil, "name"=&gt;"pts_6_20"}
  </code></pre>
  
  <p>SO I get only the first to match but rest becomes different and I get result of one instead of 4230</p>
  
  <p>I would like some way to match by path and root/suite/case/ic and then compare the executed platforms passed in array of hashes 1 vs platforms set to true in array of hash2</p>