How do I match and remove an item from the queue?

According to the 1800-2012 specification ,

Queue::delete( [input int index] ) 

      

removes a queue item in SystemVerilog, in addition, the queue can perform the same operations as an unpacked array, giving it access to:

Array::find_first_index( )

      

which returns the index of the first element that meets certain criteria. i.e.

find_first_index( x ) with ( x == 3)

      

Now I want to remove from the queue a unique element guaranteed to exist. Combining 1 and 1 gives me:

queue.delete(queue.find_first_index( x ) with ( x == obj_to_del ));

      

The compiler doesn't understand that by saying that the passed argument must be either integer or integer. I could possibly split the two:

int index = queue.find_first_index( x ) with ( x == obj_to_del );
queue.delete( index );

      

or force an integer using typging find_first_index:

queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del ))) //Just finished compiling, does not work.

      

The former doesn't look very graceful to me, and the latter seems somewhat forced, which made me wonder if there might be a better way to achieve this. Perhaps find_first_index is returning an array of size one with index at location 0?

EDIT: I foolishly didn't provide a self-contained example: a stripped example of what I'm doing looks like this:

class parent_task;
endclass;

class child_taskA extends parent_task;
endclass;

class child_taskB extends parent_task;
endclass;    

class task_collector;

 child_taskA A_queue[$];
 child_taskB B_queue[$];

 function delete_from_queue(parent_task task_to_del);
      case (task_to_del.type):
         A: A_queue.delete(A_queue.find_first_index( x ) with ( x == task_to_del));
         B: B_queue.delete(B_queue.find_first_index( x ) with ( x == task_to_del));
         default: $display("This shouldn't happen.");
 endfunction
endclass

      

Error message, word for word:

Error-[SV-IQDA] Invalid Queue delete argument
"this.A_queue.find_first_index( iterator ) with ((iterator == task))"
 Queue method delete can take optional integer argument. So, argument passed
 to it must be either integer or integer assignment compatible.

      

There are checks to ensure that this task exists prior to calling delete_from_queue.

+3


source to share


2 answers


queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del )));

      

works for me. It would really help if you could provide complete self-contained examples like the ones below:



module top;
   int queue[$] = {1,2,3,4,5};
   let object_to_del = 3;
       initial begin
      queue.delete(int'(queue.find_first_index( x ) with ( x == object_to_del )));
      $display("%p", queue);
       end
endmodule

      

But what if there was no match? Wouldn't you need to check the result from find_first_index () anyway before deleting?

0


source


I didn't work for me either, but the following works



int index_to_del[$];

index_to_del = que.find_first_index(x) with ( x == task_to_del );
que.delete(index_to_del[0]);

      

0


source







All Articles