Iterator index querying

The iterator index querying method iterates over array indexes or elements at each iteration.

find method

q = arr.find(x) with (x == x.index);


q = arr.find with (item == item.index);

As mentioned above, the find method compares the index value with the element and pushes it into the queue. Thus, queue size represents matched value count for the same index and element value.

find method Example

module iterator_index_ex;
  int arr[8] = '{5,6,9,2,4,4,6,7};
  int q[$], qsize;
  initial begin
    q = arr.find(x) with (x == x.index);
    //q = arr.find with (item == item.index);
    qsize = q.size();
    $display("Count = %0d having same index and element", qsize);
    $display("same index and elements are %p", q);


Count = 3 having same index and element
same index and elements are '{4, 6, 7}

System Verilog Tutorials