I've got a HashSet,
var universe = new HashSet<int>();
And a bunch of subsets,
var sets = new List<HashSet<int>>(numSets);
I want to subtract a chunk, which I can do like this:
var remaining = universe.ExceptWith(sets[0]);
But ExceptWith
works in-place. I don't want to modify the universe
. Should I clone it first, or is there a better way?
I guess I should clone it first? How do I do that?
var universe = new HashSet<int>();
var subset = new HashSet<int>();
...
// clone the universe
var remaining = new HashSet<int>(universe);
remaining.ExceptWith(subset);
Not as simple as with the Except
extension method, but probably faster (you should run a few performance tests to make sure)