|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65317 - in sandbox/itl/boost/itl: . detail
From: afojgo_at_[hidden]
Date: 2010-09-06 03:00:37
Author: jofaber
Date: 2010-09-06 03:00:36 EDT (Mon, 06 Sep 2010)
New Revision: 65317
URL: http://svn.boost.org/trac/boost/changeset/65317
Log:
Refactoring: Refactoring for split_interval_map::insert_ and interval_map::insert_ complete.
Stable{msvc-9.0, gcc-3.4.4}
Text files modified:
sandbox/itl/boost/itl/detail/interval_map_algo.hpp | 91 +++++++++++++++++++++++++++++++----
sandbox/itl/boost/itl/interval_map.hpp | 48 ------------------
sandbox/itl/boost/itl/split_interval_map.hpp | 101 ---------------------------------------
3 files changed, 84 insertions(+), 156 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-06 03:00:36 EDT (Mon, 06 Sep 2010)
@@ -190,23 +190,38 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
-/*JODO or CL?
-template<class Type, class Combiner, int combining_style>
-struct style_dependent;
+template<class Type, int combining_style>
+struct on_style;
-template<class Type, class Combiner, int combining_style>
-struct style_dependent<Type, Combiner, interval_combine::splitting>
+template<class Type>
+struct on_style<Type, interval_combine::splitting>
{
- static void handle_reinserted(Type& object, iterator insertion_){}
+ typedef on_style type;
+ typedef typename Type::iterator iterator;
+ static void handle_inserted(Type&, iterator, iterator&){}
+ static iterator handle_end_inserted(Type&, iterator it_){ return it_; }
};
-template<class Type, class Combiner, int combining_style>
-struct style_dependent<Type, Combiner, interval_combine::joining>
+template<class Type>
+struct on_style<Type, interval_combine::joining>
{
- static void handle_reinserted(Type& object, iterator insertion_)
- { join_right(object, insertion_); }
+ typedef on_style type;
+ typedef typename Type::iterator iterator;
+
+ static void handle_inserted(Type& object, iterator inserted_, iterator& it_)
+ {
+ join_left(object, inserted_);
+ // after filling that gap there may be another joining opportunity
+ join_left(object, it_);
+ }
+
+ static iterator handle_end_inserted(Type& object, iterator inserted_)
+ {
+ return join_neighbours(object, inserted_);
+ }
+
};
-*/
+
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
@@ -599,6 +614,60 @@
}
}
+//==============================================================================
+//= Insertion
+//==============================================================================
+
+template<class Type>
+void insert_main( Type& object,
+ typename Type::interval_type& inter_val,
+ 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::value_type value_type;
+ typedef typename Type::iterator iterator;
+ typedef typename on_style<Type,Type::fineness>::type on_style_;
+
+ iterator end_ = last_ ; ++end_;
+ iterator prior_ = it_, inserted_;
+ if(prior_ != object.end())
+ --prior_;
+ interval_type rest_interval = inter_val, left_gap, cur_itv;
+ interval_type last_interval = last_ ->first;
+
+ while(it_ != end_ )
+ {
+ cur_itv = it_->first ;
+ left_gap = right_subtract(rest_interval, cur_itv);
+
+ if(!itl::is_empty(left_gap))
+ {
+ inserted_ = object._insert(prior_, value_type(left_gap, co_val));
+ on_style_::handle_inserted(object, inserted_, it_);
+
+
+ }
+
+ // shrink interval
+ rest_interval = left_subtract(rest_interval, cur_itv);
+ prior_ = it_;
+ ++it_;
+ }
+
+ //insert_rear(rest_interval, co_val, last_):
+ interval_type end_gap = left_subtract(rest_interval, last_interval);
+ if(!itl::is_empty(end_gap))
+ {
+ inserted_ = object._insert(prior_, value_type(end_gap, co_val));
+ it_ = on_style_::handle_end_inserted(object, inserted_);
+ }
+ else
+ it_ = prior_;
+}
+
+
} // namespace detail
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-06 03:00:36 EDT (Mon, 06 Sep 2010)
@@ -365,7 +365,7 @@
last_ = insertion.first;
//assert((++last_) == this->_map.upper_bound(inter_val));
iterator it_ = first_;
- insert_range(inter_val, co_val, it_, last_);
+ detail::insert_main(*this, inter_val, co_val, it_, last_);
}
}
@@ -394,55 +394,11 @@
iterator it_ = overlap.first,
last_ = overlap.second;
--last_;
- insert_range(inter_val, co_val, it_, last_);
+ detail::insert_main(*this, inter_val, co_val, it_, last_);
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>
-void interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,Alloc>
- ::insert_range(const interval_type& inter_val, const CodomainT& co_val, iterator& it_, iterator& last_)
-{
- iterator end_ = last_ ; ++end_;
- iterator prior_ = it_, inserted_;
- if(prior_ != this->_map.end())
- --prior_;
- interval_type rest_interval = inter_val, left_gap, cur_itv;
- interval_type last_interval = last_ ->first;
-
- while(it_ != end_ )
- {
- cur_itv = it_->first ;
- left_gap = right_subtract(rest_interval, cur_itv);
-
- if(!itl::is_empty(left_gap))
- {
- inserted_ = this->_map.insert(prior_, value_type(left_gap, co_val));
- detail::join_left(*this, inserted_);
- // after filling that gap there may be another joining opportunity
- detail::join_left(*this, it_);
- }
-
- // shrink interval
- rest_interval = left_subtract(rest_interval, cur_itv);
- prior_ = it_;
- ++it_;
- }
-
- //insert_rear(rest_interval, co_val, last_):
- interval_type end_gap = left_subtract(rest_interval, last_interval);
- if(!itl::is_empty(end_gap))
- {
- inserted_ = this->_map.insert(prior_, value_type(end_gap, co_val));
- it_ = detail::join_neighbours(*this, inserted_);
- }
- else
- it_ = prior_;
-}
-
-
//-----------------------------------------------------------------------------
// erase(pair(interval,value)):
//-----------------------------------------------------------------------------
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-06 03:00:36 EDT (Mon, 06 Sep 2010)
@@ -253,66 +253,6 @@
detail::subtract_rear <type,Combiner>(*this, inter_val, co_val, it_ );
}
-
-/*CL
-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>
- ::subtract_front(const interval_type& inter_val, iterator& it_)
-{
- interval_type left_resid = right_subtract(it_->first, inter_val);
-
- if(!itl::is_empty(left_resid))
- {
- iterator prior_ = it_;
- if(prior_ != this->_map.begin())
- --prior_;
- const_cast<interval_type&>(it_->first) = left_subtract(it_->first, left_resid);
- this->_map.insert(prior_, value_type(left_resid, it_->second));
- }
-}
-
-
-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>
- ::subtract_main(const CodomainT& co_val, iterator& it_, iterator& last_)
-{
- while(it_ != last_)
- {
- 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>
- ::subtract_rear(const interval_type& inter_val, const CodomainT& co_val, iterator& it_)
-{
- interval_type right_resid = left_subtract(it_->first, inter_val);
-
- if(itl::is_empty(right_resid))
- {
- CodomainT& cur_val = it_->second ;
- Combiner()(cur_val, co_val);
- if(Traits::absorbs_neutrons && cur_val==Combiner::neutron())
- this->_map.erase(it_);
- }
- else
- { // . . . ---)
- // . . . ---right_resid) : split it_
- const_cast<interval_type&>(it_->first) = right_subtract(it_->first, right_resid);
- iterator next_ = 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_);
- }
-}
-*/
-
//-----------------------------------------------------------------------------
// insert(pair(interval,value)):
//-----------------------------------------------------------------------------
@@ -338,7 +278,7 @@
last_ = insertion.first;
//assert((++last_) == this->_map.upper_bound(inter_val));
iterator it_ = first_;
- insert_range(inter_val, co_val, it_, last_);
+ detail::insert_main(*this, inter_val, co_val, it_, last_);
}
}
@@ -367,48 +307,11 @@
iterator it_ = overlap.first,
last_ = overlap.second;
--last_;
- insert_range(inter_val, co_val, it_, last_);
+ detail::insert_main(*this, inter_val, co_val, it_, last_);
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>
- ::insert_range(const interval_type& inter_val, const CodomainT& co_val, iterator& it_, iterator& last_)
-{
- iterator end_ = last_ ; ++end_;
- iterator prior_ = it_, inserted_;
- if(prior_ != this->_map.end())
- --prior_;
- interval_type rest_interval = inter_val, left_gap, cur_itv;
- interval_type last_interval = last_ ->first;
-
- while(it_ != end_ )
- {
- cur_itv = it_->first ;
- left_gap = right_subtract(rest_interval, cur_itv);
-
- if(!itl::is_empty(left_gap))
- inserted_ = this->_map.insert(prior_, value_type(left_gap, co_val));
-
- // shrink interval
- rest_interval = left_subtract(rest_interval, cur_itv);
- prior_ = it_;
- ++it_;
- }
-
- //insert_rear(rest_interval, co_val, last_):
- interval_type end_gap = left_subtract(rest_interval, last_interval);
- if(!itl::is_empty(end_gap))
- it_ = this->_map.insert(prior_, value_type(end_gap, co_val));
- else
- it_ = prior_;
-
-}
-
-
//-----------------------------------------------------------------------------
// erase(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