Find the number of elements corresponding to one key in associative array

Hi,

Is it possible to find the number of elements corresponding to a particular key in an associative array ?

This is an array of a queue of read data with key = iid_type.
rdata_t mem_rdata_array[iid_type][$];

It will store something like this, based on iid.

mem_rdata_array is ‘{0x8:’{'{beat_count:'h7, iid:'h8, data:'h289e87bea83f11ec88188673025272b75cf68bb0b6c029756489ed400e320b69}, '{beat_count:'h8, iid:'h8, data:'ha64aff1422618d64b94d53cdc53a475238f5e08198eaf6e83436bfbed236d192}, '{beat_count:'h14, iid:'h19, data:'h18fd6c52bd6dac6ddc9de88c9da5de26e53e055aedf50c9f3effe882281801c6}, '{beat_count:'h13, iid:'h19, data:'h4739bd7debd296f43d503e9293cd630ce243101057006f113f5a95a6eba331c9}, '{beat_count:'h12, iid:'h19, data:'h798fb8643732b0cc7a2a72a08bf0e7565b7ef4bf2715de5027ea961d01b6e714}, '{beat_count:'h11, iid:'h19, data:'ha88d3c6f3768387af38a113cea6c8bf555affafe2ccff564e7496eeea0ccee39},

I would like to count the number of entries in the array corresponding to iid=8, for example, without having to pop the elements/storing in another queue.

Thanks

In reply to UVM_learner6:

Basically you want to find out, How many element are stored in the queue pointed by specific key?


//mem_rdata_array is the array of queue
rdata_t mem_rdata_array[iid_type][$];

//give the size of the queue pointed by specific key
mem_rdata_array[key].size();



In reply to UVM_learner6:

You can use find_index() to get a list of indexes that meet your criteria, and then count the entries in the list.

iid_type list[$];

list = mem_rdata_array.find_index() with (item.index.iid=='h8)
$display("count is %d",list.size() );

In reply to dave_59:

In reply to UVM_learner6:
You can use find_index() to get a list of indexes that meet your criteria, and then count the entries in the list.

iid_type list[$];
list = mem_rdata_array.find_index() with (item.index.iid=='h8)
$display("count is %d",list.size() );



iid_type list[$];

//shouldn't list queue of rdata_t type? Please correct me if i misunderstanding it?
rdata_t list[$];


In reply to Rahulkumar Patel:

For my example, it should be iid_type, that is the index key type, and that is what is returned by find_index.

UVM_learner6’s question is not very clear. Is iid a member of rdata_t or iid_type? It would help to have shown those type declarations in the first place.