System Verilog Queue Methods – delete ( )
Queue Methods in System Verilog
Arrays :
1. size( )
2. delete( )
Queues
Bounded Queues
Queues methods
1.size( )
2. delete( ) & delete(index)
3. insert( )
4. push( ) methods
5. pop( ) methods
Associative arrays
Associative array methods
1.size( )
2.delete ( ) & delete(index)
3.num ( )
4.exists( )
5.first( ) ,next( ), prev ( ), last( )
Common Methods for Dynamic Arrays & Queues :
delete ( ) and delete(index) methods of Queue in System Verilog
2.a)delete( ) :
–> delete( ) is one of the inbuilt method of Queue which deletes the entire Queue .
–> size of the queue will become “ZERO” when the queue is completely deleted.
Syntax : array_name.delete( );
Example :
int xtn[ $ ];
xtn = {10,20,30};
xtn.delete( ); // deletes complete array
2.b)delete(index):
–> System Verilog provides provides facility to delete particular element in the queue.
–> we will use “delete(index)” method for deleting a particular element.
–> we will pass the index number of an element, as argument to delete( ) method which we want to
delete.
Syntax: array_name.delete(index);
Example:
int xtn[ $ ];
xtn ={10,20,30};
xtn.delete( 1 ); // will delete the value “20” as 1 is index number of 20
Simulated_Example:
module tb();
int array_1[$];
int array_2[$];
initial
begin
for(int i=0 ; i<10 ; i=i+1)
begin
array_1 [i]= i;
end
$display(” elements in array_1 before using delete( )
= %p “, array_1);
array_1.delete();
$display(” elements in array_1 after using delete( )
method = %p”,array_1);
for(int i=0 ; i<5 ; i=i+1)
begin
array_2 [i]= i+5;
end
$display(” elements in array_2 before using
delete(index) method = %p “,array_2);
array_2.delete(3);
$display(” elements in array_2 after using
delete(index) method = %p”,array_2);
end
endmodule
Simulator_output :
**************************************************************************
elements in array_1 before using delete( ) = ‘{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
elements in array_1 after using delete( ) method = ‘{}
elements in array_2 before using delete(index) method = ‘{5, 6, 7, 8, 9}
elements in array_2 after using delete(index) method = ‘{5, 6, 7, 9}
*************************************************************************