I have sets of pairs of int like
set<pair<int,int> > x1, x2, ... xn
( n can be between 2 and 20). What is the fastest way to find union of those sets ?
Sorry If I wasn't make clear at the beginning, I meant fast in performance, memory allocation is not a problem.
I assume with fast you mean fast to implement.
Then: std::set_union (*)
Example for two sets:
for n sets, hand writing it might be the most maintainable solution:
though in general, one should prefer standard algorithms and profit from their quality implementation.
If by fast you mean performance, we can't help as we don't have the requirements. Different approaches might give different results for different circumstances.
(*) note: the site is frowned upon sometimes for not being 100% accurate vs. the standard