Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53944 - sandbox/itl/boost/itl
From: afojgo_at_[hidden]
Date: 2009-06-15 18:40:18


Author: jofaber
Date: 2009-06-15 18:40:18 EDT (Mon, 15 Jun 2009)
New Revision: 53944
URL: http://svn.boost.org/trac/boost/changeset/53944

Log:
Refactoring: Simplified split_interval_map::add 2. Stable {msvc-9.0 r+d}

Text files modified:
   sandbox/itl/boost/itl/split_interval_map.hpp | 102 ++++++++++++++++++---------------------
   1 files changed, 48 insertions(+), 54 deletions(-)

Modified: sandbox/itl/boost/itl/split_interval_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/split_interval_map.hpp (original)
+++ sandbox/itl/boost/itl/split_interval_map.hpp 2009-06-15 18:40:18 EDT (Mon, 15 Jun 2009)
@@ -139,12 +139,14 @@
     void fill_gap(const value_type&);
 
     template<class Combiner>
- void add_main(interval_type& x_itv, const CodomainT& x_val,
+ void add_main(const interval_type& x_itv, const CodomainT& x_val,
                  iterator& it, iterator& end_it);
 
     template<class Combiner>
- void add_rear(const interval_type& x_itv, const CodomainT& x_val,
- iterator& it);
+ void add_front(const interval_type& x_itv, const CodomainT& x_val, iterator& it);
+
+ template<class Combiner>
+ void add_rear(const interval_type& x_itv, const CodomainT& x_val, iterator& it);
 
     template<class Combiner>
     void subtract_rest(const interval_type& x_itv, const CodomainT& x_val,
@@ -225,8 +227,7 @@
 void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
     ::add_(const value_type& addend)
 {
- const interval_type& inter_val = addend.KEY_VALUE;
-
+ interval_type inter_val = addend.KEY_VALUE;
     if(inter_val.empty())
         return;
 
@@ -235,73 +236,43 @@
         return;
 
     std::pair<iterator,bool> insertion = this->template map_insert<Combiner>(inter_val, co_val);
-
     if(!insertion.WAS_SUCCESSFUL)
     {
         // Detect the first and the end iterator of the collision sequence
         iterator fst_it = this->_map.lower_bound(inter_val),
- lst_it = insertion.ITERATOR,
- end_it = insertion.ITERATOR;
- if(end_it != this->_map.end())
- end_it++;
- //assert(end_it == this->_map.upper_bound(inter_val));
-
- interval_type fst_itv = (*fst_it).KEY_VALUE ;
- CodomainT cur_val = (*fst_it).CONT_VALUE ;
-
-
- // handle the beginning of the sequence of intervals of *this
- // overlapped by insertee interval 'inter_val'
- interval_type lead_gap = right_subtract(inter_val, fst_itv);
- // this is a new Interval that is a gap in the current map
- if(!lead_gap.empty())
- fill_gap<Combiner>(value_type(lead_gap, co_val));
- else
- {
- interval_type left_resid = right_subtract(fst_itv, inter_val);
- if(!left_resid.empty())
- {
- const_cast<interval_type&>(fst_it->KEY_VALUE).left_subtract(left_resid);
- fill(value_type(left_resid, cur_val));
- }
- }
-
- interval_type interSec = fst_itv & inter_val;
- CodomainT cmb_val = cur_val;
- Combiner()(cmb_val, co_val);
-
- iterator snd_it = fst_it; snd_it++;
- if(snd_it == end_it)
- add_rear<Combiner>(inter_val, co_val, lst_it);
- else
- {
- this->template combine<Combiner>(fst_it, co_val);
+ lst_it = insertion.ITERATOR;
+ //assert((++lst_it) == this->_map.upper_bound(inter_val));
 
- // shrink interval
- interval_type x_rest(inter_val);
- x_rest.left_subtract(fst_itv);
-
- add_main<Combiner>(x_rest, co_val, snd_it, end_it);
- add_rear<Combiner>(x_rest, co_val, lst_it);
- }
+ add_front<Combiner>(inter_val, co_val, fst_it);
+ add_main<Combiner> (inter_val, co_val, fst_it, lst_it);
+ add_rear<Combiner> (inter_val, co_val, lst_it);
     }
 }
 
 template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc>
     template<class Combiner>
 void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::add_main(interval_type& inter_val, const CodomainT& co_val,
- iterator& it, iterator& end_it)
+ ::add_main(const interval_type& inter_val, const CodomainT& co_val,
+ iterator& fst_it, iterator& lst_it)
 {
+ if(fst_it == lst_it)
+ return;
+
+ iterator it = fst_it; ++it;
+ iterator end_it = lst_it; ++end_it;
+
     iterator pred_it, nxt_it = it; ++nxt_it;
     interval_type left_gap, common, cur_itv;
+ interval_type rest_itv = left_subtract(inter_val, fst_it->KEY_VALUE);
+
+ this->template combine<Combiner>(fst_it, co_val);
 
     while(nxt_it!=end_it)
     {
                 // [----- . . . . . ------) inter_val->co_val
                 // [prior_) [ it_ ) . . .
         cur_itv = it->KEY_VALUE;
- left_gap = right_subtract(inter_val, cur_itv);
+ left_gap = right_subtract(rest_itv, cur_itv);
 
         Combiner()(it->CONT_VALUE, co_val);
                 if(!left_gap.empty())
@@ -315,16 +286,39 @@
         else ++it;
 
         // shrink interval
- inter_val.left_subtract(cur_itv);
+ rest_itv.left_subtract(cur_itv);
         ++nxt_it;
     }
 
         cur_itv = it->KEY_VALUE;
- left_gap = right_subtract(inter_val, cur_itv);
+ left_gap = right_subtract(rest_itv, cur_itv);
         if(!left_gap.empty())
                 fill_gap<Combiner>(value_type(left_gap, co_val));
+}
 
 
+template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, template<class,ITL_COMPARE>class Interval, ITL_ALLOC Alloc>
+ template<class Combiner>
+void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
+ ::add_front(const interval_type& inter_val, const CodomainT& co_val, iterator& fst_it)
+{
+ interval_type fst_itv = fst_it->KEY_VALUE ;
+
+ // handle the beginning of the sequence of intervals of *this
+ // overlapped by insertee interval 'inter_val'
+ interval_type lead_gap = right_subtract(inter_val, fst_itv);
+ // this is a new Interval that is a gap in the current map
+ if(!lead_gap.empty())
+ fill_gap<Combiner>(value_type(lead_gap, co_val));
+ else
+ {
+ interval_type left_resid = right_subtract(fst_itv, inter_val);
+ if(!left_resid.empty())
+ {
+ const_cast<interval_type&>(fst_it->KEY_VALUE).left_subtract(left_resid);
+ fill(value_type(left_resid, fst_it->CONT_VALUE));
+ }
+ }
 }
 
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk