title: interval_map boost library
body: <p>In response to question: <a href="https://stackoverflow.com/questions/23264651/rectangles-intersection-vertical-line">Previous Answer: rectangle overlap</a></p>
  <p>I am using the <code>interval_map</code> as follows:
  I have a set of rectangles defined by <code>R = [int start, int end, (int Top, int bottom,string id)]</code>
  <strong>N.B: Rectangles are projected onto the x-axis==&gt;line segments</strong></p>
  <ul>
  <li>I want to store these Line segments in an inverval_map structure</li>
  <li>For a query line segment I want to find all the line segments that overlap with it</li>
  </ul>
  <hr />
  <p>Source code:</p>
  <pre><code>#include &quot;boost/icl/interval.hpp&quot;
  #include &quot;boost/icl/interval_map.hpp&quot;
  #include &lt;set&gt;
  using namespace std;
  
  struct Position{
      int top;
      int bottom;
      string id;
  };
  
  int main(int argc, char* argv[])
  {
      std::set&lt;Position&gt; ids1;
      ids1.insert({10,10,&quot;line1&quot;});
      std::set&lt;Position&gt; ids2;
      ids2.insert({200,10,&quot;line2&quot;});
      boost::icl::interval_map&lt;int, std::set&lt;Position&gt;&gt; mymap;
      auto i1 = boost::icl::interval&lt;int&gt;::closed(2, 7);
      auto i2 = boost::icl::interval&lt;int&gt;::closed(3, 8);
      mymap += make_pair(i1, ids1);
      mymap += make_pair(i2, ids2);
  
      return 0;
  }
  </code></pre>
  <hr />
  <h1>Another Library, and a solution but by not using the icl boost library</h1>
  <p>I found the following library which does the same work as the icl boost library but must simpler:
  download site: <a href="https://github.com/ekg/intervaltree" rel="nofollow noreferrer">Interval Tree</a></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &quot;IntervalTree.h&quot;
  
  using namespace std;
  
  struct Position
  {
      int x;
      int y;
      string id;
  };
  
  int main()
  {
      vector&lt;Interval&lt;Position&gt;&gt; intervals;
      intervals.push_back(Interval&lt;Position&gt;(4,10,{1,2,&quot;r1&quot;}));
      intervals.push_back(Interval&lt;Position&gt;(6,10,{-6,-3,&quot;r2&quot;}));
      intervals.push_back(Interval&lt;Position&gt;(8,10,{5,6,&quot;r3&quot;}));
  
      vector&lt;Interval&lt;Position&gt; &gt; results;
      vector&lt;string&gt; value;
      int start = 4;
      int stop = 10;
  
      IntervalTree&lt;Position&gt; tree(intervals);
     // tree.findContained(start, stop, results);
      tree.findOverlapping(start, stop, results);
      cout &lt;&lt; &quot;found &quot; &lt;&lt; results.size() &lt;&lt; &quot; overlapping intervals&quot; &lt;&lt; endl;
  }
  </code></pre>
  <hr />
  <h1>Example</h1>
  <ul>
  <li>start = 4;</li>
  <li>Stop = 10;</li>
  <li>structure {1,2,&quot;rc1&quot;};</li>
  </ul>
  <p>intervals.push_back(Interval(4,10,{1,2,&quot;r1&quot;}));</p>