Reputation: 348
I would like to find the intersection between two lists in SystemVerilog. From Specman there's
var intersect: list of my_enum;
intersect = listA.all(it in listB);
Which I think is rather quaint. But best I've been able to come up with in SystemVerilog is:
typedef enum {A, B, C, D} my_enum;
my_enum listA[$] = {A, B, C};
my_enum listB[$] = {B, C, D};
my_enum intersect[$];
foreach(listA[i])
if(listA[i] inside listB)
intersect.push_back(listA[i]);
IEEE 1800-2012 does mention an intersect keyword but it does not seem to apply to this case. Is there a more elegant way?
Upvotes: 2
Views: 1290
Reputation: 19114
intersect
is a keyword used in SVAs. It is not advised to use any keyword as a variable name.
Check out IEEE Std 1800-2012 § 7.12 Array manipulation methods
I believe this is the desired equivalent function is:
myIntersect = listA.find with ( item inside {listB} );
Upvotes: 3