Boost logo

Boost Users :

Subject: Re: [Boost-users] [ICL] interval_map::find returns only const iterator
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2013-01-27 11:38:34


Hi Carlos,

sorry for the late answer. Basically, I can't add much to the respose
that I already gave to Marc's offlist mail to the same topic:

(1) We are used to think find returns an iterator to an *element* but
in the icl it does not, it returns an iterator to an interval. In
prior versions
of the icl I didn't provide find functions at all.
The generalized find is intersection, because
"finding" an interval in an icl interval container may result in a
whole interval container as a result: The part of the icl interval
container that intersects the interval to be "found".

(2) While almost all functions in the icl are formally defined by
axioms (see section Semantics
http://www.boost.org/doc/libs/1_52_0/libs/icl/doc/html/boost_icl/semantics.html),
find is only there because it is expected from container interfaces of
the STL. But it is misleading to think it works exactly the same as
its std counterparts.

(3) Almost all functions defined on icl interval containers including
free standing function templates preserve the semantic properties that
are defined in section Semantics. Selectively manipulating segments
via non const iterators may spoil those properties. It is therefore
discouraged to do so.

2013/1/8 CarlosRoVe <crodveg_at_[hidden]>:
> I am using boost v.1.49.0 and I have a question about ICL. We are building a
> system that stores information associated with time intervals. For this we
> are using the interval_map container, and every element that we insert in
> the map contains a right_open interval as the key, and an instance of the
> structure that holds the information as the value. Some of the features of
> the system are:
>
> 1. Minimum interval length is one second.
> 2. We have seen that the default behavior for interval_map is aggregate on
> overlap, but in our case we enforce that overlapping time intervals are not
> allowed. To achieve this, every time we try to insert an element we perform
> a check if the time interval overlaps with any of the existing intervals in
> the map, and if so, we ignore the element.

If you don't use aggregation on overlap and control the collisions on
insert yourself, I can not see how you benefit from icl::interval_map
instead of using std::maps of intervals.

> 3. We should be able to modify the data associated with a time interval. We
> have seen that the find method of the interval_map container returns only a
> const iterator, but we would like to have a version of find that returns a
> non-const iterator as well. We want to be able to search for an element
> whose time interval contains a certain timestamp, and change its content.
>
> With the given requirements, find should return one element at most. For us
> it would be handy if ICL could also provide a version of find that returns a
> non-const iterator, but maybe I this would break the philosophy behind the
> design of ICL. We would be glad to hear ideas suggesting what we could do,
> or alternatives ways of dealing with other problem.

You may of course patch the find function or add a non const variant
in your copy of the icl. Your use case does not convince me to add a
non-const find though.

Best regards,
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