Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65292 - in sandbox/itl/boost/itl: . detail
From: afojgo_at_[hidden]
Date: 2010-09-05 09:52:54


Author: jofaber
Date: 2010-09-05 09:52:50 EDT (Sun, 05 Sep 2010)
New Revision: 65292
URL: http://svn.boost.org/trac/boost/changeset/65292

Log:
Refactoring: Refactoring for split_interval_map::add_ complete. Stable{msvc-9.0, gcc-3.4.4}
Text files modified:
   sandbox/itl/boost/itl/detail/interval_map_algo.hpp | 217 ++++++++++++++++++++++++++++-----------
   sandbox/itl/boost/itl/interval_map.hpp | 11 --
   sandbox/itl/boost/itl/split_interval_map.hpp | 159 +----------------------------
   3 files changed, 162 insertions(+), 225 deletions(-)

Modified: sandbox/itl/boost/itl/detail/interval_map_algo.hpp
==============================================================================
--- sandbox/itl/boost/itl/detail/interval_map_algo.hpp (original)
+++ sandbox/itl/boost/itl/detail/interval_map_algo.hpp 2010-09-05 09:52:50 EDT (Sun, 05 Sep 2010)
@@ -17,6 +17,7 @@
 #include <boost/itl/detail/relation_state.hpp>
 #include <boost/itl/type_traits/neutron.hpp>
 #include <boost/itl/interval.hpp>
+#include <boost/itl/interval_combining_style.hpp>
 #include <boost/itl/detail/element_comparer.hpp>
 #include <boost/itl/detail/interval_subset_comparer.hpp>
 
@@ -187,84 +188,183 @@
 }
 
 
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+/*JODO or CL?
+template<class Type, class Combiner, int combining_style>
+struct style_dependent;
+
+template<class Type, class Combiner, int combining_style>
+struct style_dependent<Type, Combiner, interval_combine::splitting>
+{
+ static void handle_reinserted(Type& object, iterator insertion_){}
+};
 
+template<class Type, class Combiner, int combining_style>
+struct style_dependent<Type, Combiner, interval_combine::joining>
+{
+ static void handle_reinserted(Type& object, iterator insertion_)
+ { join_right(object, insertion_); }
+};
+*/
+
+//------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
-template<class Type, class Combiner, bool abosorbs_neutrons>
-struct last_segment
+template<class Type, class Combiner, bool abosorbs_neutrons, int combining_style>
+struct on_segment;
+
+template<class Type, class Combiner>
+struct on_segment<Type, Combiner, false, interval_combine::splitting>
 {
- typedef last_segment type;
+ typedef on_segment type;
+ typedef typename Type::iterator iterator;
+ typedef typename Type::interval_type interval_type;
+ typedef typename Type::codomain_type codomain_type;
+
+ static void handle_combined(Type&, iterator){}
+ static void handle_preceeded_combined(Type&, iterator, iterator&){}
+ static void handle_inserted(Type&, iterator, iterator){}
+ static void handle_reinserted(Type&, iterator insertion_){}
+
+ static void insert_at(Type& object, iterator& it_, iterator,
+ const interval_type& end_gap, const codomain_type& co_val)
+ {
+ it_ = gap_insert<Type,Combiner>(object, it_, end_gap, co_val);
+ }
 
- typedef typename Type::iterator iterator;
- typedef typename Type::interval_type interval_type;
- typedef typename Type::codomain_type codomain_type;
-
- static void join(Type&, iterator&, iterator);
- static void insert_at(Type&, iterator&, iterator,
- const interval_type&, const codomain_type&);
 };
 
 template<class Type, class Combiner>
-struct last_segment<Type, Combiner, false>
+struct on_segment<Type, Combiner, true, interval_combine::splitting>
 {
- typedef last_segment type;
+ typedef on_segment type;
+ typedef typename Type::iterator iterator;
+ typedef typename Type::interval_type interval_type;
+ typedef typename Type::codomain_type codomain_type;
+
+ static void handle_combined(Type& object, iterator it_)
+ {
+ if(it_->second == Combiner::neutron())
+ object.erase(it_);
+ }
 
- typedef typename Type::iterator iterator;
- typedef typename Type::interval_type interval_type;
- typedef typename Type::codomain_type codomain_type;
+ static void handle_preceeded_combined(Type& object, iterator prior_, iterator& it_)
+ {
+ if(it_->second == Combiner::neutron())
+ {
+ object.erase(it_);
+ it_ = prior_;
+ }
+ }
+
+ static void handle_inserted(Type&, iterator, iterator){}
+ static void handle_reinserted(Type&, iterator insertion_){}
+
+ static void insert_at(Type& object, iterator& it_, iterator prior_,
+ const interval_type& end_gap, const codomain_type& co_val)
+ {
+ if(it_->second == Combiner::neutron())
+ {
+ object.erase(it_);
+ it_ = gap_insert<Type,Combiner>(object, prior_, end_gap, co_val);
+ }
+ else
+ it_ = gap_insert<Type,Combiner>(object, it_, end_gap, co_val);
+ }
+
+};
+
+template<class Type, class Combiner>
+struct on_segment<Type, Combiner, false, interval_combine::joining>
+{
+ typedef on_segment type;
+ typedef typename Type::iterator iterator;
+ typedef typename Type::interval_type interval_type;
+ typedef typename Type::codomain_type codomain_type;
 
- static void join(Type& object, iterator& it_, iterator)
+ static void handle_combined(Type& object, iterator it_)
         {
- join_neighbours(object, it_);
+ detail::join_left(object, it_);
         }
 
- static void insert_at(Type& object, iterator& it_, iterator,
- const interval_type& end_gap, const codomain_type& co_val)
+ static void handle_preceeded_combined(Type& object, iterator, iterator& it_)
+ {
+ join_neighbours(object, it_);
+ }
+
+ static void handle_inserted(Type& object, iterator prior_, iterator inserted_)
         {
- join_left(object, it_);
+ if(prior_ != object.end() && joinable(object, prior_, inserted_))
+ join_on_right(object, prior_, inserted_);
+ }
+ static void handle_reinserted(Type& object, iterator insertion_)
+ { join_right(object, insertion_); }
+
+ static void insert_at(Type& object, iterator& it_, iterator,
+ const interval_type& end_gap, const codomain_type& co_val)
+ {
+ detail::join_left(object, it_);
         iterator inserted_ = gap_insert<Type,Combiner>(object, it_, end_gap, co_val);
         it_ = join_neighbours(object, inserted_);
- }
+ }
 };
 
-
 template<class Type, class Combiner>
-struct last_segment<Type, Combiner, true>
+struct on_segment<Type, Combiner, true, interval_combine::joining>
 {
- typedef last_segment type;
-
- typedef typename Type::iterator iterator;
- typedef typename Type::interval_type interval_type;
- typedef typename Type::codomain_type codomain_type;
+ typedef on_segment type;
+ typedef typename Type::iterator iterator;
+ typedef typename Type::interval_type interval_type;
+ typedef typename Type::codomain_type codomain_type;
 
- static void join(Type& object, iterator& it_, iterator inserted_)
+ static void handle_combined(Type& object, iterator it_)
         {
                 if(it_->second == Combiner::neutron())
- {
                         object.erase(it_);
- it_ = inserted_;
- }
- else
- join_neighbours(object, it_);
+ else
+ detail::join_left(object, it_);
         }
 
- static void insert_at(Type& object, iterator& it_, iterator prior_,
- const interval_type& end_gap, const codomain_type& co_val)
+ static void handle_preceeded_combined(Type& object, iterator prior_, iterator& it_)
+ {
+ if(it_->second == Combiner::neutron())
+ {
+ object.erase(it_);
+ it_ = prior_;
+ }
+ else // After a new combination (e.g. combiner=max) joining neighbours may be possible
+ join_neighbours(object, it_);
+ }
+
+
+
+ static void handle_inserted(Type& object, iterator prior_, iterator inserted_)
         {
- if(it_->second == Combiner::neutron())
- {
+ if(prior_ != object.end() && joinable(object, prior_, inserted_))
+ join_on_right(object, prior_, inserted_);
+ }
+
+ static void handle_reinserted(Type& object, iterator insertion_)
+ { join_right(object, insertion_); }
+
+ static void insert_at(Type& object, iterator& it_, iterator prior_,
+ const interval_type& end_gap, const codomain_type& co_val)
+ {
+ if(it_->second == Combiner::neutron())
+ {
             object.erase(it_);
             it_ = gap_insert<Type,Combiner>(object, prior_, end_gap, co_val);
             join_right(object, it_);
- }
- else
+ }
+ else
         {
- join_left(object, it_);
+ detail::join_left(object, it_);
             iterator inserted_ = gap_insert<Type,Combiner>(object, it_, end_gap, co_val);
             it_ = join_neighbours(object, inserted_);
         }
- }
+ }
 };
-
+//------------------------------------------------------------------------------
 
 
 template<class Type, class Combiner>
@@ -275,6 +375,9 @@
 {
     typedef typename Type::interval_type interval_type;
     typedef typename Type::iterator iterator;
+ typedef typename on_segment<Type,Combiner,
+ absorbs_neutrons<Type>::value,
+ Type::fineness>::type on_segment_;
 
     interval_type lead_gap = right_subtract(inter_val, it_->first);
     if(!itl::is_empty(lead_gap))
@@ -283,20 +386,13 @@
         // [-- it_ ...
         iterator prior_ = prior(it_);
         iterator inserted_ = gap_insert<Type,Combiner>(object, prior_, lead_gap, co_val);
- if(prior_ != object.end() && joinable(object, prior_, inserted_))
- join_on_right(object, prior_, inserted_);
+ on_segment_::handle_inserted(object, prior_, inserted_);
     }
 
     // . . . --------- . . . addend interval
     // [-- it_ --) has a common part with the first overval
     Combiner()(it_->second, co_val);
- if(absorbs_neutrons<Type>::value && it_->second == Combiner::neutron())
- object.erase(it_++);
- else
- {
- join_left(object, it_);
- ++it_;
- }
+ on_segment_::handle_combined(object, it_++);
 }
 
 
@@ -332,7 +428,9 @@
     typedef typename Type::interval_type interval_type;
     typedef typename Type::value_type value_type;
     typedef typename Type::iterator iterator;
- typedef typename last_segment<Type,Combiner,absorbs_neutrons<Type>::value>::type last_segment_;
+ typedef typename on_segment<Type,Combiner,
+ absorbs_neutrons<Type>::value,
+ Type::fineness>::type on_segment_;
 
     iterator prior_ = object.prior(it_);
     interval_type cur_itv = it_->first ;
@@ -342,8 +440,7 @@
     { // [lead_gap--- . . .
         // [prior) [-- it_ ...
         iterator inserted_ = gap_insert<Type,Combiner>(object, prior_, lead_gap, co_val);
- if(prior_ != object.end() && joinable(object, prior_, inserted_))
- join_on_left(object, prior_, inserted_);
+ on_segment_::handle_inserted(object, prior_, inserted_);
     }
 
     interval_type end_gap = left_subtract(inter_val, cur_itv);
@@ -352,7 +449,7 @@
         // [----------------end_gap)
         // . . . -- it_ --)
         Combiner()(it_->second, co_val);
- last_segment_::insert_at(object, it_, prior_, end_gap, co_val);
+ on_segment_::insert_at(object, it_, prior_, end_gap, co_val);
     }
     else
     {
@@ -364,7 +461,7 @@
             // [---------------)
             // [-- it_ ---)
             Combiner()(it_->second, co_val);
- last_segment_::join(object, it_, prior_);
+ on_segment_::handle_preceeded_combined(object, prior_, it_);
         }
         else
         {
@@ -376,17 +473,15 @@
             // the Combiner functor. It only reestablished that state after splitting the
             // 'it_' interval value pair. Using _map_insert<Combiner> does not work here.
             iterator insertion_ = object._insert(it_, value_type(right_resid, it_->second));
- join_right(object, insertion_);
+ on_segment_::handle_reinserted(object, insertion_);
 
             Combiner()(it_->second, co_val);
- last_segment_::join(object, it_, insertion_);
+ on_segment_::handle_preceeded_combined(object, insertion_, it_);
         }
     }
 }
 
 
-
-
 } // namespace detail
 
 }} // namespace itl boost

Modified: sandbox/itl/boost/itl/interval_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_map.hpp (original)
+++ sandbox/itl/boost/itl/interval_map.hpp 2010-09-05 09:52:50 EDT (Sun, 05 Sep 2010)
@@ -146,16 +146,6 @@
             && !(Traits::absorbs_neutrons && value.second == codomain_combine::neutron());
     }
 
- /*CL
- template<class Combiner>
- void add_main(interval_type& inter_val, const CodomainT& co_val,
- iterator& it_, const iterator& last_);
-
- template<class Combiner>
- void add_rear(const interval_type& inter_val, const CodomainT& co_val, iterator& it_);
-
- void add_front(const interval_type& inter_val, iterator& first_);
- */
     template<class Combiner>
     void subtract_main(const CodomainT& co_val, iterator& it_, iterator& end_ );
 
@@ -278,7 +268,6 @@
 }
 
 
-
 template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, ITL_INTERVAL(ITL_COMPARE) Interval, ITL_ALLOC Alloc>
 inline void interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
     ::subtract_front(const interval_type& inter_val, const CodomainT&, iterator& it_)

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 2010-09-05 09:52:50 EDT (Sun, 05 Sep 2010)
@@ -139,18 +139,6 @@
     void handle_neighbours(const iterator& it_){}
     
     template<class Combiner>
- void add_main(interval_type& inter_val, const CodomainT& co_val,
- iterator& it_, const iterator& end_ );
- template<class Combiner>
- void add_segment(const interval_type& inter_val, const CodomainT& co_val,
- iterator& it_);
-
- void add_front(const interval_type& inter_val, iterator& it_);
-
- template<class Combiner>
- void add_rear(const interval_type& inter_val, const CodomainT& co_val, iterator& it_);
-
- template<class Combiner>
     void subtract_main(const CodomainT& co_val, iterator& it_, iterator& end_ );
 
     void subtract_front(const interval_type& inter_val, iterator& it_);
@@ -191,9 +179,9 @@
         iterator it_ = first_;
         interval_type rest_interval = inter_val;
 
- add_front (rest_interval, it_);
- add_main<Combiner>(rest_interval, co_val, it_, last_);
- add_rear<Combiner>(rest_interval, co_val, it_);
+ detail::add_front<type> (*this, rest_interval, it_);
+ detail::add_main <type,Combiner>(*this, rest_interval, co_val, it_, last_);
+ detail::add_rear <type,Combiner>(*this, rest_interval, co_val, it_);
     }
 }
 
@@ -225,150 +213,15 @@
                  --last_;
         interval_type rest_interval = inter_val;
 
- add_front (rest_interval, it_);
- add_main<Combiner>(rest_interval, co_val, it_, last_);
- add_rear<Combiner>(rest_interval, co_val, it_);
+ detail::add_front<type> (*this, rest_interval, it_);
+ detail::add_main <type,Combiner>(*this, rest_interval, co_val, it_, last_);
+ detail::add_rear <type,Combiner>(*this, rest_interval, co_val, it_);
 
         return it_;
     }
 }
 
 
-template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, ITL_INTERVAL(ITL_COMPARE) Interval, ITL_ALLOC Alloc>
-inline void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::add_front(const interval_type& inter_val, iterator& first_)
-{
- // If the collision sequence has a left residual 'left_resid' it will
- // be split, to provide a standardized start of algorithms:
- // The addend interval 'inter_val' covers the beginning of the collision sequence.
-
- // only for the first there can be a left_resid: a part of *first_ left of inter_val
- interval_type left_resid = right_subtract(first_->first, inter_val);
-
- if(!itl::is_empty(left_resid))
- { // [------------ . . .
- // [left_resid---first_ --- . . .
- iterator prior_ = this->prior(first_);
- const_cast<interval_type&>(first_->first) = left_subtract(first_->first, left_resid);
- //NOTE: Only splitting
- iterator insertion_ = this->_map.insert(prior_, value_type(left_resid, first_->second));
- }
-
- //POST:
- // [----- inter_val ---- . . .
- // ...[-- first_ --...
-}
-
-
-template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, ITL_INTERVAL(ITL_COMPARE) Interval, ITL_ALLOC Alloc>
- template<class Combiner>
-inline void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::add_main(interval_type& x_rest, const CodomainT& co_val, iterator& it_, const iterator& last_)
-{
- interval_type cur_interval;
- while(it_!=last_)
- {
- cur_interval = it_->first ;
- add_segment<Combiner>(x_rest, co_val, it_);
- // shrink interval
- x_rest = left_subtract(x_rest, cur_interval);
- }
-}
-
-
-template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, ITL_INTERVAL(ITL_COMPARE) Interval, ITL_ALLOC Alloc>
- template<class Combiner>
-inline void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::add_segment(const interval_type& inter_val, const CodomainT& co_val, iterator& it_)
-{
- interval_type lead_gap = right_subtract(inter_val, it_->first);
- if(!itl::is_empty(lead_gap))
- // [lead_gap--- . . .
- // [prior_) [-- it_ ...
- this->template gap_insert<Combiner>(prior(it_), lead_gap, co_val);
-
- // . . . --------- . . . addend interval
- // [-- it_ --) has a common part with the first overval
- Combiner()(it_->second, co_val);
- if(Traits::absorbs_neutrons && it_->second == Combiner::neutron())
- this->_map.erase(it_++);
- else
- ++it_;
-}
-
-
-
-template <typename DomainT, typename CodomainT, class Traits, ITL_COMPARE Compare, ITL_COMBINE Combine, ITL_SECTION Section, ITL_INTERVAL(ITL_COMPARE) Interval, ITL_ALLOC Alloc>
- template<class Combiner>
-inline void split_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::add_rear(const interval_type& inter_val, const CodomainT& co_val, iterator& it_)
-{
- iterator prior_ = this->prior(it_);
- interval_type cur_itv = (*it_).first ;
-
- interval_type lead_gap = right_subtract(inter_val, cur_itv);
- if(!itl::is_empty(lead_gap))
- // [lead_gap--- . . .
- // [prior_) [-- it_ ...
- this->template gap_insert<Combiner>(prior_, lead_gap, co_val);
-
-
- interval_type end_gap = left_subtract(inter_val, cur_itv);
- if(!itl::is_empty(end_gap))
- {
- // [---------------end_gap)
- // [-- it_ --)
- Combiner()(it_->second, co_val);
-
- if(Traits::absorbs_neutrons && it_->second == Combiner::neutron())
- {
- this->_map.erase(it_);
- it_ = this->template gap_insert<Combiner>(prior_, end_gap, co_val);
- }
- else
- it_ = this->template gap_insert<Combiner>(it_, end_gap, co_val);
- }
- else
- {
- // only for the last there can be a right_resid: a part of *it_ right of addend
- interval_type right_resid = left_subtract(cur_itv, inter_val);
-
- if(itl::is_empty(right_resid))
- {
- // [---------------)
- // [-- it_ ---)
- Combiner()(it_->second, co_val);
-
- if(Traits::absorbs_neutrons && it_->second == Combiner::neutron())
- {
- this->_map.erase(it_);
- it_ = prior_;
- }
- }
- else
- {
- // [--------------)
- // [-- it_ --right_resid)
- const_cast<interval_type&>(it_->first) = right_subtract(it_->first, right_resid);
-
- //NOTE: This is NOT an insertion that has to take care for correct application of
- // the Combiner functor. It only reestablished that state after splitting the
- // 'it_' interval value pair. Using _map_insert<Combiner> does not work here.
- iterator insertion_ = this->_map.insert(it_, value_type(right_resid, it_->second));
-
- Combiner()(it_->second, co_val);
-
- if(Traits::absorbs_neutrons && it_->second == Combiner::neutron())
- this->_map.erase(it_);
-
- it_ = insertion_;
- }
- }
-}
-
-
-
-
 //-----------------------------------------------------------------------------
 // subtract<Combinator>(pair(interval,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