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会转换成二进制,然后进行)