System Verilog Associative Array Methods – exists( )
Associative Array 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 :
exists( ) method of Associative Array in System Verilog
4.exists( ):
–> exists( ) method is an inbuilt method of associative array.
–> exists( ) method will check for the key (or) index wether it is present in the array or not and If the key or index is
present then it will returns value as 1(true ) .
–> It can be used as condition so that if key is present then it will execute true part or else part will be executed.
Syntax : array_name.exists( );
Example :
int pkt [*];
pkt[“apple”] = 10;
pkt[0] = 50;
if(pkt.exists(“apple”)
begin
$display(“apple key or index is present”);
end
In the above example , we are checking wether the “apple” key (or) index is present in the array by calling exists( ) method . If key (or) index with name “apple” is present then exists( ) method will return 1(true) and hence true part of if block will be executed.
Simulated_Example:
module tb();
int xtn[*];
initial
begin
xtn[0] =10;
xtn[20]=30;
xtn[“emp_id”] = 45;
if(xtn.exists(20))
begin
$display(“value present in the xtn[20]=%0p”,xtn[20]);
end
else
begin
$display(“key is not present”);
end
if(xtn.exists(“transaction”))
begin
$display(“value present in
xtn[transaction]=%0p”,xtn[“transaction”]);
end
if(xtn.exists(10))
begin
$display(“value present in the xtn[20] =%0p”,xtn[20];
end
else
begin
$display(“10 key or index is not present “);
end
end
endmodule
Simulator_output :
*********************************************************************
value present in the xtn[20] =30
value present in xtn[transaction]=45
10 key or index is not present
*********************************************************************