The stupid question is the question not asked | |
PerlMonks |
Re: Efficient algorithm needed to split Set::IntSpan objectsby jethro (Monsignor) |
on Sep 23, 2009 at 15:03 UTC ( [id://796992]=note: print w/replies, xml ) | Need Help?? |
Instead of splitting you could do a sort of accumulating using the set operations of Set::IntSpan: For adding b you would create the union of result-set 0 and b, which is empty. Then you would create the union of result-set 1 and b, which is 5-8, subtract that from b and result-set 1, and add the range to result-set 2.
Whenever you add another set, you look for the union of your set and all the already created result-sets: If there is a range common to the set and result-set X, that range will be subtracted from both sets and added to the result-set X+1, until your set is empty Naturally this means if you have a value where all sets overlap, this will create lots of result-sets and make the algorithm slow again. If not it should be reasonable fast if set operations in Set::IntSpan are efficient as well
In Section
Seekers of Perl Wisdom
|
|