[/ Copyright (c) 2008-2010 Joachim Faulhaber Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ] [section Introduction] [/ note [* The Interval Container Library is accepted into Boost] The [*Interval Container Library] (formerly /Interval Template Library/) underwent a formal review on the boost developer's list from February 18, 2010 to March 08, 2010 and has been accepted by declaration of review manager Hartmut Kaiser into the boost library collection on April 18, 2010. The library has been refactored for the suggestions and requests that came up during the review. The current version is now ready for inclusion into the next boost release. The name ['*Interval Template Library (ITL)*] has been changed to ['*Interval Container Library (ICL)*]. If you find bugs in the library or typos or other shortcomings in the documentation please send reports to the boost developers list boost@lists.boost.org the boost users list or boost-users@lists.boost.org to `[afojgogmail dot com]`. ] ["A bug crawls across the boost docs on my laptop screen. Let him be! We need all the readers we can get.] -- Freely adapted from [@http://en.wikipedia.org/wiki/Jack_Kornfield Jack Kornfield] Intervals are almost ubiquitous in software development. Yet they are very easily coded into user defined classes by a pair of numbers so they are only /implicitly/ used most of the time. The meaning of an interval is simple. They represent all the elements between their lower and upper bound and thus a set. But unlike sets, intervals usually can not be added to a single new interval. If you want to add intervals to a collection of intervals that does still represent a /set/, you arrive at the idea of /interval_sets/ provided by this library. Interval containers of the *ICL* have been developed initially at [@http://www.cortex-software.de/desktopdefault.aspx Cortex Software GmbH] to solve problems related to date and time interval computations in the context of a Hospital Information System. Time intervals with associated values like ['amount of invoice] or ['set of therapies] had to be manipulated in statistics, billing programs and therapy scheduling programs. So the *ICL* emerged out of those industrial use cases. It extracts generic code that helps to solve common problems from the date and time problem domain and can be beneficial in other fields as well. One of the most advantageous aspects of interval containers is their very compact representation of sets and maps. Working with sets and maps /of elements/ can be very inefficient, if in a given problem domain, elements are typically occurring in contiguous chunks. Besides a compact representation of associative containers, that can reduce the cost of space and time drastically, the ICL comes with a universal mechanism of aggregation, that allows to combine associated values in meaningful ways when intervals overlap on insertion. For a condensed introduction and overview you may want to look at the [@http://www.herold-faulhaber.de/boost_icl/doc/libs/icl/doc/boostcon09/intro_to_itl.pdf presentation material on the *ICL* from ['*BoostCon2009*]]. [section Definition and Basic Example] The [*Interval Container Library (ICL)] provides __itvs__ and two kinds of interval containers: __itv_sets__ and __itv_maps__. * An __itv_bset__ is a *set* that is implemented as a set of intervals. * An __itv_bmap__ is a *map* that is implemented as a map of interval value pairs. [h4 Two Aspects] __Itv_bsets__ and __itv_bmaps__ expose two different aspects in their interfaces: (1) The functionality of a set or a map, which is the more ['*abstract aspect*]. And (2) the functionality of a container of intervals which is the more specific and ['*implementation related aspect*]. In practice both aspects are useful and are therefore supported. The first aspect, that will be called __bi_conceptual__ ['*aspect*], is the more important one. It means that we can use an __itv_set__ or __itv_map__ like a set or map ['*of elements*]. It exposes the same functions. `` interval_set mySet; mySet.insert(42); bool has_answer = contains(mySet, 42); `` The second aspect, that will be called __bi_iterative__ ['*aspect*], allows to exploit the fact, that the elements of __itv_sets__ and __itv_maps__ are clustered in ['*intervals*] or ['*segments*] that we can iterate over. `` // Switch on my favorite telecasts using an interval_set interval::type news(make_seconds("20:00:00"), make_seconds("20:15:00")); interval::type talk_show(make_seconds("22:45:30"), make_seconds("23:30:50")); interval_set myTvProgram; myTvProgram.add(news).add(talk_show); // Iterating over elements (seconds) would be silly ... for(interval_set::iterator telecast = myTvProgram.begin(); telecast != myTvProgram.end(); ++telecast) //...so this iterates over intervals TV.switch_on(*telecast); `` Working with __itv_bsets__ and __itv_bmaps__ can be beneficial whenever the elements of sets appear in contiguous chunks: __itvs__. This is obviously the case in many problem domains, particularly in fields that deal with computations related to date and time. [h4 Addabitlity and Subtractability] Unlike `std::sets` and `maps`, __itv_bsets__ and __itv_bmaps__ implement concept `Addable` and `Subtractable`. So __itv_bsets__ define an `operator +=` that is naturally implemented as ['*set union*] and an `operator -=` that is consequently implemented as ['*set difference*]. In the *Icl* __itv_bmaps__ are addable and subtractable as well. It turned out to be a very fruitful concept to propagate the addition or subtraction to the __itv_bmap_s__ associated values in cases where the insertion of an interval value pair into an __itv_map__ resulted in a collision of the inserted interval value pair with interval value pairs, that are already in the __itv_map__. This operation propagation is called ['*aggregate on overlap*]. [h4 Aggregate on Overlap] This is a first motivating example of a very small party, demonstrating the ['*aggregate on overlap*] principle on __itv_maps__: In the example Mary enters the party first. She attends during the time interval `[20:00,22:00)`. Harry enters later. He stays within `[21:00,23:00)`. `` typedef std::set guests; interval_map party; party += make_pair(interval