我是靠谱客的博主 瘦瘦果汁,这篇文章主要介绍SV数组方法1.数组递减方法 (用于非合并数组:固定数组、动态数组、队列和联合数组)2.数组排序操作3.数组定位操作4.数组定位操作,现在分享给大家,希望可以做个参考。
1.数组递减方法 (用于非合并数组:固定数组、动态数组、队列和联合数组)
- 求和sum,求积product,与and,或or,异或xor
- a.sum单比特数组的求和返回单比特的数值
- 求最大值max,求最小值min,唯一化unique
复制代码
1
2
3
4
5
6
7
8
9bit on[10]; int summ; initial begin foreach(on[i]) on[i]=i;//0,1,0,1,0,1,0,1,0,1 $display(on.sum);//1 summ=on.sum;//summ=1 end
复制代码
1
2
3
4
5
6
7int q[$]={1,3,5,7},tq[$]; int f[6] = '{1,6,2,6,8,6}; $display(q.sum,q.product);//16,105 tq = q.min();//{1} tq = q.max();//{7} tq = f.unique;//{1,6,2,8}
2.数组排序操作
- 翻转:reverse
- 乱序:shuffle
- 升序排列:sort
- 降序排列:rsort
复制代码
1
2
3
4
5
6
7int d[]='{9,1,8,3,4,4}; int td[$]; td = d.reverse();//{4,4,3,8,1,9} td = d.shuffle();//{9,8,4,3,4,1}随机的,每次都不同 td = d.sort();//{1,3,4,4,8,9} td = d.rsort();//{9,8,4,4,3,1}
3.数组定位操作
- 查找元素:find
- 查找第一个元素:find_first
- 查找第一个元素的索引:find_first_with_index
复制代码
1
2
3
4
5
6
7int d[] = '{9,1,8,3,4,4},tq[$]; tq = d.find with(item>3);//{9,8,4,4} tq = d.find_index with(item>99);//{}无 tq = d.dind_dirst_index with(item==8);//{2} tq = d.find_index with(item==4);//{4,5} tq = d.find_last_index with(item==4);//{5}
4.数组定位操作
复制代码
1
2
3
4
5
6
7
8
9
10int count,total,d[] = '{9,1,8,3,4,4}; count = d.sum(x) with(x>7);//返回逻辑值0 count = d.sum(x) with((x>7)*1);//2=sum{1,0,1,0,0,0} total = d.sum(x) with((x>7)*x);//17=sum{9,0,8,0,0,0} count = d.sum(x) with(x<8);//返回逻辑值0 count = d.sum(x) with((x<8)*1);//4=sum{0,1,0,1,1,1} total = d.sum(x) with(x<8?x:0);//12=sum{0,1,0,3,4,4} count = d.sum(x) with(x==4);//返回逻辑值0 count = d.sum(x) with((x==4)*1);//2=sum{0,0,0,0,1,1}
最后
以上就是瘦瘦果汁最近收集整理的关于SV数组方法1.数组递减方法 (用于非合并数组:固定数组、动态数组、队列和联合数组)2.数组排序操作3.数组定位操作4.数组定位操作的全部内容,更多相关SV数组方法1.数组递减方法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复