关联数组的一些function

1. num() or size(); 返回entry的个数;

int imem[int];

imem[ 3 ] = 1;

imem[ 16'hffff ] = 2;

imem[ 4'b1000 ] = 3; $display( "%0d entries\n", imem.num ); // prints "3 entries"

2. delete(); 删除某个index;

int map[ string ];

map[ "hello" ] = 1;

map[ "sad" ] = 2;

map[ "world" ] = 3;

map.delete( "sad" ); // remove entry whose index is "sad" from "map"

map.delete; // remove all entries from the associative array "map"

3. exists(); 判断某个索引是否存在;

if ( map.exists( "hello" ))

        map[ "hello" ] += 1;

else

        map[ "hello" ] = 0;

4. first(); 返回第一个索引值;

data_as[a] = 20;

data_as[b] = 30;

data_as[c] = 40;

string data_index;
if(data_as.first(data_index))begin//找到了第一个索引,索引值为a, 返回1;

    do begin
          $display(“data_as[%s] is 0x%0h”,data_index,data_as[data_index]);
     end
     while(data_as.next(data_index));
end
data_as[a] is 0x14
data_as[b] is 0x15
data_as[c] is 0x16

5. last(); 同理,找last的索引值;

6. next(); 同上例子,找下一个,只要有,就返回1;

7. 同理,prev(), 找前一个;可以和last()配合使用;


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值