Finding Common Items across all Queues

In reply to Kishankk:

Hi,
You already had that answer. I followed two different approaches to get results for two different requirements.


module dynamic_array;
  
  //dynamic array declaration
  
  string       qa[$];
  string        qb[$];
  
  int    qc[$];
  int qd[$];

  
  int count_indexx[string]='{default:0};
  
  int result1[$];
  string result2[$];
  
  

  initial 
    begin
    $display("Queue Allocation");
    qa= {"AB","SK","OU","SK","OU"};
    qb = {"EP","AB","EP","SK","EP"};
    qc={23,48,45,61,99};
    qd={45,21,35,23,27,83,99};
    
    $display("------qa---------");   
    foreach(qa[i])   $display("\t qa[%0d] = %s",i, qa[i]);
    
    $display("-----qc--------"); 
    foreach(qc[i])   $display("\t qc[%0d] = %0d",i, qc[i]);
    
    if (qa==qb) $display("Good");
    else $display("BAD");
  

      $display("\n");
    
    qa=qa.unique();
    qb=qb.unique;
    qc=qc.unique; // If we follow 1st method we don't need to make these queues unique.
    qd=qd.unique; // If we follow 1st method we don't need to make these queues unique.
    

   // 1st method
      result1 = qc.find() with (item inside{qd}); 
    $display("%0p",result1);
    


   // 2nd method
    foreach(qa[xx]) count_indexx[qa[xx]]++;
    foreach(qb[xx]) count_indexx[qb[xx]]++;
    result2 = count_indexx.find_index() with (item>=2);
    $display("%0p",result2);
    
    
  
  end
  
  
endmodule