System Verilog Queue Methods – insert( )
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 :
insert( ) method of Queue in System Verilog
3.insert( ):
–> insert( ) method is one of the inbuilt method of Queue .
–> insert( ) method will add (or) injects an element at particular position of the Queue. Values (or)
elements can be added at any index within the size.
–> This method requires two arguments . first argument is for index and second argument is for element
to include in the Queue.
–> Value can be inserted at the immediate index number after the last index of an array.
Syntax : array_name.insert(index , value);
Example :
int pkt[ $ ];
pkt = {10,20,30};
pkt.insert(1 , 40); // including value 40 at index 1
In the above example we declared a Queue with a name “pkt” . we are calling inbuilt insert( ) method for
including the value 40 at the index number 1 of a Queue .The first argument is “1” which represents
index of Queue and the second argument is “40” which is the value to be included .
Simulated_Example:
module tb();
int array_1[$];
initial
begin
for(int i=0 ; i<5 ; i=i+1)
begin
array_1 [i]= i;
end
$display(” elements in array_1 = %p “, array_1);
array_1.insert(0,10);
$display(” elements in array_1 after inserting value-10 at 0 position= %p”,array_1);
array_1.insert(3,20);
$display(” elements in array_1 after inserting value-20 at 3rd position= %p”,array_1);
array_1.insert(5,50);
$display(” elements in array_1 after inserting value-50 at 5th position= %p”,array_1);
end
endmodule
Simulator_output :
*********************************************************************************
elements in array_1 = ‘{0, 1, 2, 3, 4}
elements in array_1 after inserting value-10 at 0 position= ‘{10, 0, 1, 2, 3, 4}
elements in array_1 after inserting value-20 at 3rd position= ‘{10, 0, 1, 20, 2, 3, 4}
elements in array_1 after inserting value-50 at 5th position= ‘{10, 0, 1, 20, 2, 50, 3, 4}
*********************************************************************************