Deleting elements returned via Array locator methods

Hi Forum,

I have a 2D Unpacked array axi_transaction assoc_q [int][$]; which is iterated in descending order ( based on precedence )

Using array location methods I find the object of interest. Once found I want to delete it

Here is my attempt. During 1st iteration of for loop, there are 2 elements returned via find API.

During 2nd and 3rd iteration, find API returns 1 element. My understanding was that returned element would be pointing to same object so if I were to assign the queue element as null,I would end up removing the respective element from original array assoc_q.

However, the elements still exist within assoc_q

(1) Seeking suggestions to delete the elements returned via find from assoc_q

(2) Using foreach( assoc_q[i,j] ) 1st index ‘i’ iterates through associative array and 2nd index ‘j’ iterates through queue.

So, should I call assoc_q as Queue of Associative array or Associative array of queue ?

Thanks

Technically speaking, SystemVerilog only has single-dimensional arrays. However, you can define an array of another array. You have defined assoc_q as an associative array containing a queue of transaction variables.

The find locator method of an array generates a queue of elements that match the with () clause by copying the value of each matching element and pushing it into the queue. The original array remains unchanged.

What you likely want to do is retain the elements that don’t match the axaddr value you’re searching for.

assoc_q[ind] = assoc_q[ind].find with ( item.axaddr != 4'hA );

However, there’s a catch with the find method: the order in which it returns the results is unspecified. If you need to preserve the ordering of elements in the queue and just delete the elements that match your condition, you’ll have to do something a bit more complicated. Deleting elements of a queue is not straightforward. You’ll need to use the find_index() method instead.

int idx[$]; // A queue of indices of elements to be removed from the original queue. 
idx = assoc_q[ind].find_index with ( item.axaddr == 4'hA );
foreach(idx[i])
       assoc_q[ind].delete(idx[i] - i);   // adjust for earlier deletions