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()配合使用;