How do I define an associative array of queues?

I want to define an associative array with a pkt_id (of type int) as the index and each index has a queue.

I tried this :

bit[31:0]trans_q[$]recd_trans[*];

Does not seem correct.

Any inputs?

In reply to Verif Engg:
Never declare an associative array with a wildcard index[*]. You can not retrieve any key values because its type is unknown. Use [int] if you mean the index to mean a 32-bit integer.

bit [31:0] trans_q[int][$];

This declares an associative array of queues.

In reply to dave_59:
trans_q will be packed or unpacked ?

In reply to pawar:

trans_q is an unpacked associative array of unpacked queues whose queue elements are packed arrays of bits.

I have a confusion with this, could you please elaborate with a picture if possible?
lets say bit[1:0] a [int]; here a is unpacked associative array where the key is unpacked and value is packed array of bits ??

In reply to pawar:

I don’t have the time to draw a picture that would help you. A packed type is just any type that could be treated as an integral(integer) value greater than a single scalar bit. trans_q by itself without any key select expression is a whole unpacked array. You can copy or compare unpacked arrays as a whole, but you can not use a whole unpacked array in an integral expression.

In reply to dave_59:

How to register associative array of queue into UVM factory (uvm_field_*)?

In reply to shahkavish77:

The UVM factory only concerns classes, not fields of a class.

The `uvm_field_* macros register fields of a class for automation of certain operations. But they only handle certain field types and do not support multi-dimensional arrays.

We strongly discourage the use of `uvm_field for any field because of their poor performance.
https://verificationacademy.com/cookbook/macrocostbenefit

In reply to dave_59:

Got it. Appreciate your quick help sir.

Hi All,
Here i am pushing the associative array to the associative array of queue.
But i am facing the “asssignment operator type check failed” error.

//Associative array declaration
bit [15:0] memory[int];

//Associative array of queue declaration
bit [15:0] assoc_queue[int][$];

//Here i am pushing to the value to memory
   memory[5]  = 16'h5;
   memory[22] = 16'h5;
   etc ,....

//Below i am pushing memory to assoc_queue.I want to push before i am collecting all the memory elements to assoc_queue.

assoc_queue[1].push_back(memory);

Thanks in Advance
Rajaraman

In reply to Rajaraman Rak7:

The push_back() method only can push one element at a time onto the queue. And you cannot directly assign an associative array to a queue (or any other unpacked array) because you lose the index keys.

You could

foreach(memory[index]) assoc_queue[1].push_back(memory[index]);

You loose the index keys [5] [22] … this way.

Hi dave,
I got this point.
Thank you for your immediate response.

In reply to Rajaraman Rak7:

Hi dave,
I got this point.
Thank you for your immediate response.

Hi Dave,
When we use a queue of assoc array , how to use assoc functions like exists?

//in a method, want to check if a memory element exists?
if (assoc_queue[1].exists(memory[input_val]) )

Error: Could not find member ‘exists’ assoc_queue

I am looking for, how to use assoc functions , when we use queue of assoc array.
Will you please show some example code.
Thanks in adavance
SV

In reply to svasekar:

The examples here are associative arrays of queues, not queues of associative arrays.
assoc_queue[1]
is one element of the associative array whose type is a queue, so the exists() method is not appropriate.
assoc_queue.exists(1)
would be appropriate.

In reply to dave_59:

Thanks Dave for clarification.

In reply to dave_59:

bit [31:0] trans_q[int][$];

Could you give an example of how I can pass the value to this queue whose elements are an associative array? I just want to know how to declare or assign value to bit [31:0] trans_q[int][$];, because both the key and value of an associative array are important to me, I do not want to lose any value while I am storing it in a queue.

I want to work on pushing front and popping back an associative array in a queue.

Thank you