sv中数组的一些function

int  arr[10];

int  q[$];

1. find() with (); 返回满足条件的元素;

// Find all items greater than 5

q = arr.find( x ) with ( x > 5 );

2. find_index() with (); 返回满足条件的index;

// Find indices of all items equal to 3

q = arr.find_index with ( item == 3 );

3. find_first with (); 返回满足条件的第一个元素,一般用在数组元素为class时,根据条件取出满足条件时整个指针;

    e.g. arr.find_first with(item.id == 'h3);

4. find_first_index() with (); 返回满足条件的第一个元素的index;

5. find_last with (); 同3;

6. find_last_index with(); 同4;

7. .min; 获取数组中的最小值;

    q = arr.min();

    q = arr.min() with {item.id }; //根据各个元素的id值来获取最小值;

8. .max(); 获取数组中的最大值;

9. .unique(); 去除数组中的重复部分;

   arr.unique(item) with (item.id);//也可以通过元素的某个属性来去重;

10. reverse(); 倒序;

     arr.reverse(); //{"as","df"}  <=> {"df","as"};

11. sort(); 排序;//支持sort with (), 满足某些条件的元素进行排序

     //支持多次排序;

        c.sort with ( item.red ); // sort c using the red field only

        c.sort( x ) with ( {x.blue, x.green} ); // sort by blue then green

12. rsort(); 倒排;//支持rsort with();

13. shuffle(); 打乱;

14. sum(); 求和

    //所有元素求和;

     byte b[] = { 1, 2, 3, 4 };

     int y;

     y = b.sum ; // y becomes 10 => 1 + 2 + 3 + 4

    //多维数组求和;

        logic [7:0] m [2][2] = '{ '{5, 10}, '{15, 20} };

        int y;

        y = m.sum with (item.sum with (item)); // y becomes 50 => 5+10+15+20

    //元素做类型转换后再求和

        logic bit_arr [1024];

        int y;

        y = bit_arr.sum with ( int'(item) ); // forces result to be 32-bit

15. product(); 所有元素求乘积;

16. and(); 所有元素按位&,可以添加with();(每个element会转换成二进制,然后进行)

17. or();所有元素按位or,可以添加with();(每个element会转换成二进制,然后进行)

18. xor(); 所有元素求异或,可以添加with();(每个element会转换成二进制,然后进行)

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值