in reply to Efficient algorithm needed to split Set::IntSpan objects

Instead of splitting you could do a sort of accumulating using the set operations of Set::IntSpan:
First create a result-set 0 which would have (in the example) a span of 1,14. Adding set a would create a result-set 1 with span 3-11 and result-set 0 with 1-2,12-14. This is easily done with set operations available in 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.

Before: XXXXXXXXXXXXXX = result-set 0 -------------- = result-set 1 -------------- = result-set 2 After adding a: XX---------XXX = result-set 0 --XXXXXXXXX--- = result-set 1 -------------- = result-set 2 After adding b: XX---------XXX = result-set 0 --XXX---XXX--- = result-set 1 -----XXX------ = 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