Finding Common Items across all Queues

Hi,

string db_q[int][$];

I have some list of queues.

db_q[0] = {"AB","SK","OU","SK","OU"};
db_q[1] = {"EP","AB","EP","SK","EP"};
db_q[2] = {"AB","SK","OU","SK","SK"};
db_q[3] = {"Sk","SK","SK","SK","EP"};

From Above queues, there is term called “SK” in different indexes of each Queue.
I need a logic such that, to get the common index of all Queues which has “SK”

From the above table, “SK” is in common index[Index =3] for all Queues .Logic should return the common indexes.


I am writing like this, but it became complicated

  1. find_index in all queues with “SK”.
  db_q_index[0]={1,3};
   db_q_index[1]={3};
   db_q_index[2] ={1,3};
   db_q_index[3]= {0,1,2,3};

2.I need to find the common items across all db_q_index[*]
???

Can Anybody can give their own logic to implement this?

In reply to naaj_ila:

I would count each index returned from db_q_index in another associative array.

int count_index[int] = '{default:0};

foreach(db_q_index[xx,yy]) count_index[db_q_index[xx][yy]]++;

result_index = count_index.find_index() with (item==4);

result_index should be {3}.

Hi Dave,

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};

How to print common elements of two arrays(say qa and qb;qc and qd) in another queue or array

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

In reply to dave_59:

Hi Dave,
I believe this approach will work only if the given queues are unique.

Thank you Shubhabrata.