System Verilog Associative Array Methods – size( )
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 :
size( ) method of associative array in System Verilog
1.size( ):
–>size ( ) method will return the size of the associative array at current instance of time.
–> It returns the number of entries in the array.
Syntax : array_name.size( );
Example : int pkt [ * ];
int size;
pkt[0] = 10;
pkt[“apple”] =20;
size=pkt.size( );
In the above example we are capturing the size of the array into varibale “size” by calling the inbuilt method size( ).
Simulated_Example:
module tb();
int array_1[*];
int array_2[*];
int size;
initial
begin
array_1[0] = 10;
array_1[1] = 20;
array_1[2] = 30;
for(int i=0 ; i<5 ; i=i+1)
begin
array_2 [i]= i+5;
end
size = array_1.size();
$display(” size of array_1 = %p”, size);
$display(” size of array_2 = %p “,array_2.size());
end
endmodule
Simulator_output:
***********************************************************************
size of array_1 = 3
size of array_2 = 5
***********************************************************************