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 :

          delete(  ) & delete(index) methods of associative array

 

2.a) delete( );

                     –> delete ( ) is inbuilt method which is used to delete the elements of an array.

                     –> delete( ) method will deletes the complete array.

                     Syntax : array_name.delete( );

                     Example :

                                    int xtn [* ];

                                    xtn[0:2]={10,20,30};

                                    xtn.delete( ); // deletes entire array

 

2.b)delete(index);

                      –> Associative arrays provides a facility to delete particular element when needed.

                      –> For deleting a particular entry in the array we will call the inbuilt delete( ) method by passing index as argument to it.

                      –> Based on the index which is passed delete( ) method will delete the entry inside the index.

                     Syntax : array_name.delete(index);

                     Example :

                                int xtn[*];

                                xtn[0:2]={10,20,30};

                                xtn.delete(1); // deletes entry inside index 1

 

Simulated_Example:

module tb();

       int array_1[*];

       int array_2[*];

       initial

        begin

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

           begin

            array_1 [i]= i;

           end

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

           begin

            array_2 [i]= i+5;

           end

       $display(“elements in array_1 before using delete( )  = %p “, array_1);

       array_1.delete();

       $display(” elements in array_1 after delete( ) method = %p”,array_1);

       $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( ) = ‘{0x0:0, 0x1:1, 0x2:2, 0x3:3, 0x4:4} 

   elements in array_1 after using delete( ) method  = ‘{}

   elements in array_2 before using delete(index) method='{0x0:5, 0x1:6, 0x2:7, 0x3:8,  0x4:9} 

  elements in array_2 after using delete(index) method = ‘{0x0:5, 0x1:6, 0x2:7, 0x4:9}

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