Is it possible to use find_index() functions to match nested queues?

In a queue of a class/Transaction holding multiple variables and queues.
Is it possible to use find_index to search the second level of queues along with the first level?
Haven’t been able to find any language in the LRM that points to it, alternative is to sequentially match one step at a time.

Adding a simple example below:

class A;
  int sub_q1[$];
  int sub_q2[$]
endclass: A
class B;
A bad_idea_q[$];
  
  function match(int addr1, int addr2);
    int match_q[$];
    match_q = bad_idea_q.find_index with ( item.sub_q1[x]==addr1 && item.sub_q2[y]==addr2);
  endfunction
endclass: B

In reply to markiv:

It would help to show some examples with data, and what are you expecting the function. match to return.

In reply to dave_59:

Function match should return a queue of matching indexes of the bad_idea_q which holds sub_q1==addr1 and sub_q2[y]==addr2.

int match_q[$];
bit stage1, stage2;
foreach(bad_idea_q[i]) begin
 stage1 = 0;
 stage2 = 0;
 foreach(bad_idea_q[i].sub_q1[j]) begin
  if(bad_idea_q[i].sub_q1[j] == addr1) stage1=1;
 end
 foreach(bad_idea_q[i].sub_q2[k]) begin
  if(bad_idea_q[i].sub_q2[k] == addr2) stage2=1;
 end 
 if(stage1&&stage2) match_q.push_back(i);
end


Here’s an example
There are 4 items in the bad_idea_q: {1,2,3,4}
Every item has two sub queues, sub_q1 and sub_q2
item → {sub_q1} {sub_q2}
1 → {a,b,c,d} {e,f,g,h}
2 → {e,f,g,h} {i,j,k,l}
3 → {a,b,c,d} {e,f,g,k}
4 → {e,f,g,h} {l,m,n,o}

Output of match(a,g) → {1,3}
Output of match(a,k) → {3}
Output of match(e,l) → {2,4}
Output of match(e,j) → {2}


Its straightforward to match in a single level search. Curious if there’s a way to simplify searching through the sub queues without a dedicated function. I hope that helped clarify my earlier question

In reply to markiv:

I think this does what you want:

match_q = bad_idea_q.find_index with ( addr1 inside {item.sub_q1} && addr2 inside {item.sub_q2});

In reply to dave_59:

Hi Sir,
This code could have also been written in the following way, I guess :


match_q = bad_idea_q.find_index with ( addr1 inside {subq1[item]} && addr2 inside {subq2[item]});

subq1 and subq2 - both of them are 2D queues. bad_idea_q is the queue with the positions/row numbers of those 2D queues.
Now, when I am writing item.subq1 along with the “with” clause, it will go to that row number and search whether addr1 is present in that row. I believe subq1[item] will do the exact thing.

In reply to Shubhabrata:

No it will not. Try compiling it.

In reply to dave_59:

Yes, It didn’t work. Is it any characteristic of the “with” clause or limitation of eda tool?

In reply to Shubhabrata:

bad_idea_q is a queue of class variables, each element containing a handle a class A object.

The with expression iterates replacing ‘item’ with a handle to a class A object.

sub_q1 and sub_q2 are members of a class A object. You cannot access then without a reference to a class handle. The error message you get when compiling should point out the problem with the code.

This works, thanks Dave.
Additionally, is it possible to bit manipulate the variables inside the queue ?
If I want to shift out the last nibble in both matching variables
I understand the below code is an illegal operation, is there an alternative?

match_q = bad_idea_q.find_index with ( (addr1 >> 4) inside { item.sub_q1 >> 4 } && addr2 inside {item.sub_q2});

In reply to markiv:
There is, but it is quite convoluted.

match_q = bad_idea_q.find_index with ( item.sub_q1.or(q1) with (addr1 >> 4 == q1 >> 4) && 
                                       item.sub_q2.or(q2) with (addr2 >> 4 == q2 >> 4) );

It might be more suitable to write a function.

In reply to dave_59:

That is quite some sorcery!
Thank you Dave