Boost logo

Boost Users :

Subject: Re: [Boost-users] [ICL] Specific interval_map
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2012-09-29 07:04:49


2012/9/27 A G <heyji2_at_[hidden]>:
> Hello,
>
> I am trying to see whether I can use interval_map for my project. I was
> initially amazed with interval_map and thought this would be it, but then I
> have some doubts:
>
> I need a interval tree like interval_map, but the aggregated values have the
> following equivalent property: equal to the length of the interval it is
> aggregated with. An example:
>
> [0:3] -> 3
> [4:8] -> 4
>
> Then if I add the interval [2:5] with aggregated value 3 (step 1) to this
> container, this should end up with:
>
> [0:1] -> 1
> [2:3] -> 1
> [4:5] -> 1
> [6:8] -> 2
>
> which I would later need to change into (step 2) :
>
> [0:1] -> 1
> [2:5] -> 3 ([2:3] and [4:5] are merged because what matter is the last
> inserted interval: [2:3]).
> [6:8] -> 2
>
> I am not sure I can do step 1 in just overloading the operator+= over my
> aggregated values. Could you please confirm ? If so, is there any part of
> the library I can reuse to do this task (like a function overloading, but
> which one) or do I have to rewrite an ad-hoc insert-like method myself ?
>
> Thank you for your hints.

The use case you are suggesting is probably beyond the idea of
aggregating associated values on overlap. Moreover the value you
intend to associate to intervals, their size, is already available via
the icl::size function on intervals.

I think the behavior that you intend can be obtained using an
icl::split_interval_set in the following way:

=========================================================
#include <boost/icl/split_interval_set.hpp>

void A_G_case()
{
    split_interval_set<int> splis;

    splis += interval<int>::right_open(0,3);
    splis += interval<int>::right_open(4,8);

    // Get rid of interval borders within [2,5)
    splis -= interval<int>::right_open(2,5);
    splis += interval<int>::right_open(2,5);

    split_interval_set<int>::iterator it = splis.begin();
    while(it != splis.end())
    {
        cout << *it << " -> " << icl::size(*it) << endl;
        ++it;
    }
}
=========================================================

HTH,
Joachim

-- 
Interval Container Library [Boost.Icl]
http://www.joachim-faulhaber.de

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net