tags:

views:

234

answers:

1

I work with a bunch of sets in order to generate constrained random traffic, but I want to be able to call a Specman macro that computes the complement of a set with syntax like:

COMPLEMENT begin domain=[0..10,24..30], complmenting_set=[2..3,27..30] end

and have it generate:

[0..1,4..10,24..26]

Every time I need the complement of a set I'm using fully populated lists (e.g. {0;1;2;3....} ) and then removing elements, instead of using Specman's built-in int_range_list object. And I'm also doing a lot of these set calculations at run-time instead of compile-time.

+2  A: 

You can try this:

var domain: list of int = {0..10, 24..30}; 
var complementing_set: list of int = {2..3, 27..30};
var complement: list of int = domain.all(it in complementing set);

The all pseudo-method generates a sublist of the parent list of all the elements in the parent list for which the condition in the parentheses holds.

Nathan Fellman
That's a really great way to do unions with a list of int! My goal is to *not* use list_of_int's, because it consumes too much memory. We have 16+ nodes in our design and the nodes are of varying types. I want to use int_range_list because Specman is quicker when testing if a val is in the set.
Ross Rogers
I also don't want to do a lot of computation dynamically. I'm looking at tons of packet fields on the fly, and I want to speed up the testing of whether a certain integer lives within some set ( or union of different sets).
Ross Rogers
Thanks for the response. I don't think there is a solution, because Specman doesn't have a very good pre-processor. I was mostly just testing to see if stackoverflow could help me generate answers tough, obscure-language questions.
Ross Rogers