Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65239 - in sandbox/itl: boost/itl boost/itl/detail libs/validate/example/labat_signed_quantifier_
From: afojgo_at_[hidden]
Date: 2010-09-04 08:17:11


Author: jofaber
Date: 2010-09-04 08:17:09 EDT (Sat, 04 Sep 2010)
New Revision: 65239
URL: http://svn.boost.org/trac/boost/changeset/65239

Log:
Refactoring: Refactoring for interval_map::add_ complete. Stable{msvc-9.0, gcc-3.4.4}
Text files modified:
   sandbox/itl/boost/itl/detail/interval_map_algo.hpp | 169 +++++++++++++++++++++++++++++++++++++++
   sandbox/itl/boost/itl/detail/interval_set_algo.hpp | 8 +
   sandbox/itl/boost/itl/interval_base_map.hpp | 14 +-
   sandbox/itl/boost/itl/interval_map.hpp | 139 +-------------------------------
   sandbox/itl/libs/validate/example/labat_signed_quantifier_/labat_signed_quantifier.cpp | 2
   5 files changed, 190 insertions(+), 142 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-04 08:17:09 EDT (Sat, 04 Sep 2010)
@@ -171,7 +171,6 @@
 namespace detail
 {
 
-
 template <class Type, class Combiner>
 inline typename Type::iterator
 gap_insert( Type& object,
@@ -188,6 +187,86 @@
 }
 
 
+
+//------------------------------------------------------------------------------
+template<class Type, class Combiner, bool abosorbs_neutrons>
+struct last_segment
+{
+ typedef last_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&, 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>
+{
+ typedef last_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)
+ {
+ join_neighbours(object, it_);
+ }
+
+ static void insert_at(Type& object, iterator& it_, iterator,
+ const interval_type& end_gap, const codomain_type& co_val)
+ {
+ 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>
+{
+ typedef last_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_)
+ {
+ if(it_->second == Combiner::neutron())
+ {
+ object.erase(it_);
+ it_ = inserted_;
+ }
+ else
+ join_neighbours(object, it_);
+ }
+
+ 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
+ {
+ 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>
 void add_segment( Type& object,
                  const typename Type::interval_type& inter_val,
@@ -215,13 +294,99 @@
         object.erase(it_++);
     else
     {
- detail::join_left(object, it_);
+ join_left(object, it_);
         ++it_;
     }
 }
 
 
 
+template<class Type, class Combiner>
+void add_main( Type& object,
+ typename Type::interval_type& rest_interval,
+ const typename Type::codomain_type& co_val,
+ typename Type::iterator& it_,
+ const typename Type::iterator& last_ )
+{
+ typedef typename Type::interval_type interval_type;
+ typedef typename Type::iterator iterator;
+
+ interval_type cur_interval;
+ while(it_!=last_)
+ {
+ cur_interval = it_->first ;
+ add_segment<Type,Combiner>(object, rest_interval, co_val, it_);
+ // shrink interval
+ rest_interval = left_subtract(rest_interval, cur_interval);
+ }
+}
+
+
+
+template<class Type, class Combiner>
+void add_rear( Type& object,
+ typename Type::interval_type& inter_val,
+ const typename Type::codomain_type& co_val,
+ typename Type::iterator& it_ )
+{
+ 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_;
+
+ iterator prior_ = object.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_ ...
+ 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_);
+ }
+
+ interval_type end_gap = left_subtract(inter_val, cur_itv);
+ if(!itl::is_empty(end_gap))
+ {
+ // [----------------end_gap)
+ // . . . -- it_ --)
+ Combiner()(it_->second, co_val);
+ last_segment_::insert_at(object, it_, prior_, end_gap, co_val);
+ }
+ else
+ {
+ // only for the last there can be a right_resid: a part of *it_ right of x
+ interval_type right_resid = left_subtract(cur_itv, inter_val);
+
+ if(itl::is_empty(right_resid))
+ {
+ // [---------------)
+ // [-- it_ ---)
+ Combiner()(it_->second, co_val);
+ last_segment_::join(object, 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_ = object._insert(it_, value_type(right_resid, it_->second));
+ join_right(object, insertion_);
+
+ Combiner()(it_->second, co_val);
+ last_segment_::join(object, it_, insertion_);
+ }
+ }
+}
+
+
+
+
 } // namespace detail
 
 }} // namespace itl boost

Modified: sandbox/itl/boost/itl/detail/interval_set_algo.hpp
==============================================================================
--- sandbox/itl/boost/itl/detail/interval_set_algo.hpp (original)
+++ sandbox/itl/boost/itl/detail/interval_set_algo.hpp 2010-09-04 08:17:09 EDT (Sat, 04 Sep 2010)
@@ -517,15 +517,17 @@
     // 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_, inter_val);
+ interval_type left_resid = right_subtract(Type::key_value(first_), inter_val);
 
     if(!itl::is_empty(left_resid))
     { // [------------ . . .
         // [left_resid---first_ --- . . .
         iterator prior_ = object.prior(first_);
- const_cast<interval_type&>(*first_) = left_subtract(*first_, left_resid);
+ const_cast<interval_type&>(Type::key_value(first_))
+ = left_subtract(Type::key_value(first_), left_resid);
         //NOTE: Only splitting
- iterator insertion_ = object._insert(prior_, left_resid);
+ //CL iterator insertion_ =
+ object._insert(prior_, Type::make_value(left_resid, Type::co_value(first_)));
     }
 
     //POST:

Modified: sandbox/itl/boost/itl/interval_base_map.hpp
==============================================================================
--- sandbox/itl/boost/itl/interval_base_map.hpp (original)
+++ sandbox/itl/boost/itl/interval_base_map.hpp 2010-09-04 08:17:09 EDT (Sat, 04 Sep 2010)
@@ -673,6 +673,13 @@
     const_reverse_iterator rbegin()const { return _map.rbegin(); }
     const_reverse_iterator rend()const { return _map.rend(); }
 
+ iterator prior(iterator it_)
+ { return it_ == this->_map.begin() ? this->_map.end() : --it_; }
+
+ const_iterator prior(const_iterator it_)const
+ { return it_ == this->_map.begin() ? this->_map.end() : --it_; }
+
+
     //==========================================================================
     //= Element iterator related
     //==========================================================================
@@ -740,6 +747,7 @@
     { codomain_type total; sum(total); return total; }
 
 
+
     //==========================================================================
     //= Algorithm unifiers
     //==========================================================================
@@ -766,12 +774,6 @@
 
 protected:
 
- iterator prior(iterator it_)
- { return it_ == this->_map.begin() ? this->_map.end() : --it_; }
-
- const_iterator prior(const_iterator it_)const
- { return it_ == this->_map.begin() ? this->_map.end() : --it_; }
-
     template <class Combiner>
     bool combine(iterator& it_, const codomain_type& co_val)
     {

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-04 08:17:09 EDT (Sat, 04 Sep 2010)
@@ -146,6 +146,7 @@
             && !(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_);
@@ -154,7 +155,7 @@
     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_ );
 
@@ -201,9 +202,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 (*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_ );
     }
 }
 
@@ -236,139 +237,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 (*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 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))
- { // [------------ . . .
- // [prior) [left_resid---first_ --- . . .
- iterator prior_ = this->prior(first_);
- const_cast<interval_type&>(first_->first) = left_subtract(first_->first, left_resid);
- //NOTE: Only splitting
- 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 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 ;
- detail::add_segment<type,Combiner>(*this, 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 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_ ...
- iterator inserted_ = this->template gap_insert<Combiner>(prior_, lead_gap, co_val);
- if(prior_ != this->_map.end() && detail::joinable(*this, prior_, inserted_))
- detail::join_on_left(*this, prior_, inserted_);
- }
-
- 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);
- detail::join_right(*this, it_);
- }
- else
- {
- detail::join_left(*this, it_);
- iterator inserted_ = this->template gap_insert<Combiner>(it_, end_gap, co_val);
- it_ = detail::join_neighbours(*this, inserted_);
- }
- }
- else
- {
- // only for the last there can be a right_resid: a part of *it_ right of x
- 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
- detail::join_neighbours(*this, it_);
- }
- 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));
- detail::join_right(*this, insertion_);
-
- Combiner()(it_->second, co_val);
-
- if(Traits::absorbs_neutrons && it_->second == Combiner::neutron())
- {
- this->_map.erase(it_);
- it_ = insertion_;
- }
- else
- detail::join_neighbours(*this, it_);
- }
- }
-}
-
-
 //-----------------------------------------------------------------------------
 // subtract<Combinator>(pair(interval,value)):
 //-----------------------------------------------------------------------------

Modified: sandbox/itl/libs/validate/example/labat_signed_quantifier_/labat_signed_quantifier.cpp
==============================================================================
--- sandbox/itl/libs/validate/example/labat_signed_quantifier_/labat_signed_quantifier.cpp (original)
+++ sandbox/itl/libs/validate/example/labat_signed_quantifier_/labat_signed_quantifier.cpp 2010-09-04 08:17:09 EDT (Sat, 04 Sep 2010)
@@ -28,6 +28,8 @@
     GentorProfileSgl::it()->set_std_profile(16,1);
     GentorProfileSgl::it()->set_range_double(-1.0, 1.0);
     GentorProfileSgl::it()->report_profile();
+
+ //validater.set_information_level(inform::never);
     validater.validate();
 };
 


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