Associative Array Methods in System Verilog

Arrays :

                       1. size( )

                       2. delete( )

                                    1.size( )

                                   2. delete( ) & delete(index)

                                   3. insert(  )

                                   4. push( ) methods

                                   5. pop( ) methods

                                   1.size( )

                                   2.delete ( ) & delete(index)

                                  3.num ( )

                                  4.exists( )

                                  5.first( ) ,next( ), prev ( ), last( )

Common  Methods for Dynamic Arrays & Queues :

         num(  ) method of Associative array in System Verilog

3.num( ):

           –> num( ) is also an inbuilt method of associative array.

           –> num( ) method will return the number of entries present inside an array at the current instance of time.

           –> If array is empty , num( ) will return ” 0 (zero)”.

           –>  If we want to capture the returned value , we need to declare another variable which can hold the returned data.

          Syntax : array_name.num( );

          Example : 

                   int mem [ *][0:3];  // 2-dimensional associative array

                   int no_of_entries;

                   int mem[0] ={10,20,30,40};

                   no_of_entries =mem.num( );

          In the above example , we declared 2-dimensional associative array . one dimension is variable and other dimension is of size 4. we are storing 4 elements into the index 0 of array mem.

 

Simulated_Example:

module tb();

    int array_1[*];

    int number_of_elements;

    initial

     begin

       for(int i=0 ; i<5 ; i=i+1)

         begin

           array_1 [i]= i;

         end

       number_of_elements = array_1.num();

       $display(“number_of_elementes in array_1=%0p “,number_of_elements);

       array_1.delete(2);

       $display(” number_of_elementes in array_1 = %0p ” ,array_1.num());

     end

   endmodule

 

 

 

 

 

Simulator_output:

   *************************************************************************

    number_of_elementes in array_1 = 5

    number_of_elementes in array_1 = 4

    *************************************************************************