User guide

24-27
SystemVerilog Testbench Constructs
first
Assigns the value of the smallest or alphabetically first entry in
the array. Returns 0 if the array is empty and returns 1 if the array
contains a value.
last
Assigns the value of the largest or alphabetically last entry in the
array. Returns 0 if the array is empty and returns 1 if the array
contains a value.
next
Finds the entry whose index is greater than the given index. If
there is a next entry, the index variable is assigned the index of
the next entry, and the function returns 1. Otherwise, variable is
unchanged, and the function returns 0
prev
Finds the entry whose index is smaller than the given index. If
there is a previous entry, the index variable is assigned the index
of the previous entry, and the function returns 1. Otherwise,
variable is unchanged, and the function returns 0.
The following example shows how to use these methods.
program p;
logic [7:0] a[string];
string s_index;
initial begin
a["sa"] = 8;
a["bb"] = 15;
a["ec"] = 29;
a["d"] = 32;
a["e"] = 45;
$display("number of entries = %0d",a.num);
if(a.exists("sa"))
$display("string \"sa\" is in a");
if(a.first(s_index))
begin