Array Iterator index querying

SystemVerilog Array Iterator index querying

Methods discussed before works on an index or an element, but Array iterator index querying methods shall operate on both index and element.

Find array element with index example

Below example shows two types of conditions,

array_1.find with ( item == item.index );

returns the array element whose value is equal to the index value.

array_1.find(item) with ( item > item.index);

returns the array element whose value is greater than the index value.

module fixedsize_array;
  
  //declaration of array’s
  int array_1[6],array_2[6];
  int temp_qu[$],temp_cnt,temp_value;
  
  initial begin
    //array initialization
    array_1  = '{10,20,2,40,67,5};
    array_2  = '{80,4,2,40,67,5};
    
    //Type-1
    temp_qu = array_1.find with ( item == item.index );
    
    temp_cnt = temp_qu.size();
    $display("Index and Elments are same for %0d index's.",temp_cnt);
    
    for(int i=0;i<temp_cnt;i++) begin //{
      temp_value = temp_qu.pop_front();
      $display("\tsame for value %0d",temp_value);
    end //}
    
    //Type-2
    temp_qu = array_1.find(item) with ( item > item.index);
    
    temp_cnt = temp_qu.size();
    $display("Index and Elments conndition satisfied for %0d index's.",temp_cnt);
    
    for(int i=0;i<temp_cnt;i++) begin //{
      temp_value = temp_qu.pop_front();
      $display("\tfor value %0d",temp_value);
    end //}
           
  end
  
endmodule 

Simulator Output

Index and Elments are same for 2 index's.
 same for value 2
 same for value 5
Index and Elments conndition satisfied for 4 index's.
 for value 10
 for value 20
 for value 40
 for value 67

Click to execute on   

❮ Previous Next ❯