What I want to do is handling interval efficiently. For example, in my example, intervals are like the following:
[10, 20], [15, 25], [40, 100], [5, 14]
Intervals are closed and integers, and some of intervals may be ovelapped. I want to find overlapped intervals for a given query efficiently. For example, if [16, 22]
is given:
[10, 20], [15, 25]
The above intervals should be computed as overalpped intervals.
I'm currently writing an interval tree based on Red-Black Tree (reference: CLRS, Introduction to Algorithms). Although finding all overlapped intervals can be O(n), the running time should be faster. Note that intervals can be deleted and inserted.
However, I just found that Boost has interval_map
and interval_set
:
http://www.boost.org/doc/libs/1_46_1/libs/icl/doc/html/index.html
I tried it, but the behavior is very strange for me. For example, if [2, 7]
is inserted first and then [3, 8]
is inserted, then the resulting map will have [2, 3)
, [3, 7]
, and (7, 8]
. That is, when a new interval is inserted, splitting is automatically done.
Can I turn off this feature? Or, Boost's interval_map
is right for my purpose?