Saurabh
Saurabh

Reputation: 47

Checking for value already stored in associative array

I want to tap a signal and enter into an associative array.Also,I need to make sure every time I am tapping a value,it should be different from what's already stored in the associative array.

 logic [31:0] addr[int]; 

    eg.if addr[0]=1
          addr[1]=2
          addr[2]=3

If the the next value is again 1,2 or 3.I should not assign it to my associative array and go to the next iteration.

Is it possible to accomplish using a associative array or any other type of array should be more convenient. If it's possible, can some please provide some logic on how to achieve it.

Let me know if something is unclear.Any help is greatly appreciable.

Upvotes: 1

Views: 3891

Answers (1)

dave_59
dave_59

Reputation: 42673

You want to use the find() array locator method. And since you will adding one array element at a time in sequential index ordering, you should use a queue.

logic [31:0] adds[$];


if ( addr.find() with (item == value) == {} ) addr.push_back(value);

Upvotes: 2

Related Questions