sv中的数组基本操作:

/*    
  Exercsise platform :     Questa Sim 10.1b
*/
class Array;
  int array[9:0] ;
  
  function new();
     for( int i = 0 ; i < 10 ; i++ )
         array[i] = i ;
      /*
          array = '{'{1,2,3},'{5{5}},default:0};
          无法使用这种基本的赋值方式,可能是编译器的版本过低了
      */
  endfunction:new
  
   function void print();
    foreach(array[i]) begin
      $display(" array[%d] = %d ",i,array[i]);
    end
    for ( int i = 0 ; i < 10 ; i++ )begin
      $write(" ** ");
    end
    $display();
  endfunction:print
  
  function void funcs();
      int pos[$] ;
    //   缩减操作 xor , or , and ,  xnor  , sum , product 等
    $display("the sum is %d ",array.sum());
    $display("the and is %d ",array.and());
    $display("the  or is %d ",array.or() );
    $display("the xor is %d ",array.xor());
    $display("the product is %d ",array.product());
    
    //   索引操作:取得相应的所需要的数组原素位置
    $display(" max value is %d ",array.max()[0]);
    $display(" min value is %d ",array.min()[0]);
    array = array.unique();
    print();       //  在类中时,调用自己类的函数,可以直接调用。这点与cpp相同
    pos = array.find with ( item == 7 ) ; 
    //  find 有多种变体: find_first   find_last  find_first_index   find_last_index
    $display(" pos : %d ? value: %d ",pos[0],array[pos[0]]);
    
    //  排序操作: sort ,  rsort  , reverse , shuffle , 
    // 其中 sort ,rsort  可以与with相结合,根据with后的条件排序
    array.shuffle();
    $display("shuffled:");
    print();
    array.sort();
    $display("Sorted:");
    print();
    array.rsort();
    $display("Resorted:");
    print();
    array.reverse();
    $display("Reversed:");
    print();  
  endfunction:funcs
endclass:Array
module top;
  Array array;
  int arr[] ;     //