Reputation: 4975
I am trying to use Boost.Icl to find the size of overlapping intervals.
For example: Given intervals [0, 20], [10, 30], [35, 40]
interval_set<int> iset;
iset += interval<int>::open(0, 20);
iset += interval<int>::open(10, 30);
iset += interval<int>::open(35, 40);
I want to query the overlapping length for the interval [20, 40] compared with those in the tree, which should be 15 (20->30 and 35->40)
I can only find a contains() function which checks if a point is inside the interval, but is there another function that does what I want?
Upvotes: 2
Views: 1460
Reputation: 486
Have a look at the equal_range member function:
auto itRes = iset.equal_range( boost::icl::interval<int>::closed( 20, 40 ) );
for( auto it = itRes.first; it != itRes.second; ++it )
{
std::cout << "(" << it->lower() << ", " << it->upper() << ")\n";
}
itRes.first is an iterator to (20, 30)
and itRes->second an iterator to (35, 40)
Small sidenote: writing [0, 20]
means a closed interval, wheras (0, 20)
means open.
Upvotes: 2