|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r79807 - in sandbox/icl: boost/icl boost/icl/concept libs/icl/test/test_casual_
From: afojgo_at_[hidden]
Date: 2012-07-30 18:10:48
Author: jofaber
Date: 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
New Revision: 79807
URL: http://svn.boost.org/trac/boost/changeset/79807
Log:
interval_map concept refactoring. Addition.
Text files modified:
sandbox/icl/boost/icl/_flat_interval_map.hpp | 3
sandbox/icl/boost/icl/_interval_map.hpp | 9 ++-
sandbox/icl/boost/icl/_interval_map_traits.hpp | 11 +++-
sandbox/icl/boost/icl/concept/_interval_map.hpp | 90 +++++++++++++++++++++++----------------
sandbox/icl/libs/icl/test/test_casual_/test_casual.cpp | 13 ++++-
5 files changed, 77 insertions(+), 49 deletions(-)
Modified: sandbox/icl/boost/icl/_flat_interval_map.hpp
==============================================================================
--- sandbox/icl/boost/icl/_flat_interval_map.hpp (original)
+++ sandbox/icl/boost/icl/_flat_interval_map.hpp 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
@@ -45,7 +45,6 @@
typedef ICL_IMPL_SPACE::vector< std::pair<DomainT, CodomainT> > impl_type;
typedef _interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval,impl_type> base_type;
typedef flat_interval_map<DomainT,CodomainT,Traits,Compare,Combine,Section,Interval> type;
- typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type;
typedef typename base_type::interpair_iterator interpair_iterator;
typedef typename base_type::interpair_const_iterator interpair_const_iterator;
@@ -60,6 +59,8 @@
//JODO typedef typename base_type::size_type size_type;
typedef typename Compare<DomainT> domain_compare;
typedef typename Combine<CodomainT> codomain_combine;
+ typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type;
+ typedef std::pair<interval_type, interval_type> segment_type;
enum { fineness = 1 };
Modified: sandbox/icl/boost/icl/_interval_map.hpp
==============================================================================
--- sandbox/icl/boost/icl/_interval_map.hpp (original)
+++ sandbox/icl/boost/icl/_interval_map.hpp 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
@@ -52,15 +52,16 @@
typedef typename impl_type::const_iterator interpair_const_iterator;
typedef typename impl_type::value_type value_type;
typedef typename DomainT element_type;
- //JODO typedef typename impl_type::segment_type segment_type;
typedef typename DomainT domain_type;
- typedef typename impl_type::value_type::second_type codomain_type;
+ typedef typename CodomainT codomain_type;
//JODO typedef typename impl_type::domain_mapping_type domain_mapping_type;
//JODO typedef typename impl_type::interval_mapping_type interval_mapping_type;
//JODO typedef typename impl_type::size_type size_type;
- typedef typename Compare<DomainT> domain_compare;
- typedef typename Combine<CodomainT> codomain_combine;
+ typedef typename Compare<DomainT> domain_compare;
+ typedef typename Combine<CodomainT> codomain_combine;
+ typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) interval_type;
+ typedef std::pair<interval_type, codomain_type> segment_type;
enum { fineness = 1 };
Modified: sandbox/icl/boost/icl/_interval_map_traits.hpp
==============================================================================
--- sandbox/icl/boost/icl/_interval_map_traits.hpp (original)
+++ sandbox/icl/boost/icl/_interval_map_traits.hpp 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
@@ -22,13 +22,15 @@
typedef interval_map_traits type;
typedef interval_map_traits concept_mapping;
typedef Model model_type;
- typedef typename model_type::key_type domain_type;
- typedef typename model_type::value_type::second_type codomain_type;
+ typedef typename model_type::domain_type domain_type;
+ typedef typename model_type::codomain_type codomain_type;
typedef typename model_type::key_compare domain_compare;
typedef typename model_type::codomain_combine codomain_combine;
typedef typename model_type::interpair_type interpair_type;
typedef typename model_type::iterator interpair_iterator;
typedef typename model_type::const_iterator interpair_const_iterator;
+ typedef typename model_type::interval_type interval_type;
+ typedef typename model_type::segment_type segment_type;
BOOST_STATIC_CONSTANT(bool, value = false);
@@ -43,7 +45,6 @@
}} // namespace boost icl
-//#define ICL_REFINED_TYPE(base, type_name) typedef typename base::type_name type_name ;
#define ICL_INTERVAL_MAP_TRAIT_TYPES(base_type)\
typedef typename base_type::domain_type domain_type;\
@@ -52,7 +53,9 @@
typedef typename base_type::codomain_combine codomain_combine;\
typedef typename base_type::value_type interpair_type;\
typedef typename base_type::interpair_iterator interpair_iterator;\
- typedef typename base_type::interpair_const_iterator interpair_const_iterator;
+ typedef typename base_type::interpair_const_iterator interpair_const_iterator;\
+ typedef typename base_type::interval_type interval_type;\
+ typedef typename base_type::segment_type segment_type;
#define ICL_INTERVAL_MAP_TRAIT_FUNCTIONS(model_type)\
static interpair_iterator interpairs_begin (model_type& model) { return model.begin(); };\
Modified: sandbox/icl/boost/icl/concept/_interval_map.hpp
==============================================================================
--- sandbox/icl/boost/icl/concept/_interval_map.hpp (original)
+++ sandbox/icl/boost/icl/concept/_interval_map.hpp 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
@@ -27,7 +27,7 @@
}
template<class Type> //JODO different interval_map-Types
-typename interval_map_traits<Type>::codomain_type
+typename interval_map_traits<Type>::codomain_type&
co_combine( typename interval_map_traits<Type>::interpair_const_iterator left
, typename interval_map_traits<Type>::interpair_const_iterator right )
{
@@ -38,7 +38,7 @@
}
template<class Type>
-typename interval_map_traits<Type>::codomain_type
+typename const interval_map_traits<Type>::codomain_type&
co_value( typename interval_map_traits<Type>::interpair_iterator iter )
{
return (*iter).second;
@@ -83,14 +83,41 @@
return interval_map_traits<Type>::insert(object, position, value);
}
+template<class Type, int fineness> struct on_combining_style;
+template<class Type>
+struct on_combining_style<Type, 1>
+{
+ typedef typename interval_map_traits<Type>::type Concept;
+ typedef typename Concept::codomain_type codomain_type;
+ typedef typename Concept::interpair_iterator interpair_iterator;
+ typedef typename Concept::interpair_const_iterator interpair_const_iterator;
+
+ static void insert_shifted( Type& sum
+ , interpair_const_iterator it1_, interpair_const_iterator it2_
+ , interpair_iterator& last_in_)
+ {
+ codomain_type co_val = co_combine<Type>(it1_, it2_);
+ if((*last_in_).second != co_val)
+ last_in_ = icl::insert(sum, interpairs_end(sum), make_pair((*it1_).first, co_val));
+ }
+
+ static void insert_even( Type& sum
+ , interpair_const_iterator it1_, interpair_const_iterator it2_
+ , interpair_iterator& last_in_)
+ {
+ codomain_type co_val = co_combine<Type>(it1_, it2_);
+ if((*last_in_).second != co_val)
+ last_in_ = icl::insert(sum, interpairs_end(sum), make_pair((*it1_).first, co_val));
+ }
+};
template<class Type>
typename enable_if<interval_map_traits<Type>, Type>::type
-joining_add(const Type& map1, const Type& map2, bool join=true)
+joining_add(const Type& map1, const Type& map2)
{
- typedef typename interval_map_traits<Type>::type Concept;
+ typedef typename interval_map_traits<Type>::type Concept;
typedef typename Concept::codomain_type codomain_type;
typedef typename Concept::domain_compare domain_compare;
typedef typename Concept::interpair_iterator interpair_iterator;
@@ -110,8 +137,10 @@
interpair_iterator last_in_ = interpairs_begin(sum);
codomain_type co_val = co_combine<Type>(it1_, it2_);
- last_in_ = insert(sum, interpairs_end(sum), make_pair((*it1_).first, co_val));
- //JODO *sum_ = construct<interpair>(it1_, co_val);
+
+ last_in_ = icl::insert(sum, last_in_, make_pair((*it1_).first, co_val));
+
+ //JODO? *sum_ = construct<interpair>(it1_, co_val);
pred1_ = it1_++;
pred2_ = it2_++;
@@ -119,63 +148,50 @@
{
if( domain_less_<Type>(it1_,it2_) )
{
- codomain_type co_val = co_combine<Type>(it1_, pred2_);
- if(!join || (*last_in_).second != co_val)
- last_in_ = sum.insert(interpairs_end(sum), make_pair((*it1_).first, co_val));
-
+ on_combining_style<Type,1>::insert_shifted(sum, it1_, pred2_, last_in_);
pred1_ = it1_++;
}
else if ( domain_less_<Type>(it2_,it1_) )
{
- codomain_type co_val = co_combine<Type>(it2_, pred1_);
- if(!join || (*last_in_).second != co_val)
- last_in_ = sum.insert(interpairs_end(sum), make_pair((*it2_).first, co_val));
-
+ on_combining_style<Type,1>::insert_shifted(sum, it2_, pred1_, last_in_);
pred2_ = it2_++;
}
else //( domain_equal(it1_,it2_) )
{
- codomain_type co_val = co_combine<Type>(it1_, it2_);
- if(!join || (*last_in_).second != co_val)
- last_in_ = sum.insert(interpairs_end(sum), make_pair((*it1_).first, co_val));
-
- pred1_ = it1_++;
- pred2_ = it2_++;
+ on_combining_style<Type,1>::insert_even(sum, it1_, it2_, last_in_);
+ pred1_ = it1_++; pred2_ = it2_++;
}
}
while(it1_ != interpairs_cend(map1))
{
- codomain_type co_val = co_combine<Type>(it1_, pred2_);
- if(!join || (*last_in_).second != co_val)
- last_in_ = sum.insert(interpairs_end(sum), make_pair((*it1_).first, co_val));
-
+ on_combining_style<Type,1>::insert_shifted(sum, it1_, pred2_, last_in_);
pred1_ = it1_++;
}
while(it2_ != interpairs_cend(map2))
{
- codomain_type co_val = co_combine<Type>(it2_, pred1_);
- if(!join || (*last_in_).second != co_val)
- last_in_ = sum.insert(interpairs_end(sum), make_pair((*it2_).first, co_val));
-
+ on_combining_style<Type,1>::insert_shifted(sum, it2_, pred1_, last_in_);
pred2_ = it2_++;
}
return sum;
}
-/*CONTINUE
template<class Type>
-typename enable_if<interval_map_traits<Type>, Type>::type
-add_interval( const Type& map1
- , const typename Type::segment_type& segment
- , bool join=true)
+typename enable_if<interval_map_traits<Type>, Type>::type&
+add_interval( Type& object, const typename Type::segment_type& segment)
{
- Type sum;
- sum.insert(sum.end(), make_pair(0, 0));
- sum.insert(sum.end(), make_pair(inter_val.lower(), 0));
+ typename Type::codomain_type co_val = segment.second;
+ Type addend;
+ if(0 < segment.first.lower()) //JODO GEN
+ addend.insert(addend.end(), make_pair(0, 0));
+
+ addend.insert(addend.end(), make_pair(segment.first.lower(), segment.second));
+ addend.insert(addend.end(), make_pair(segment.first.upper(), 0));
+ object = joining_add(object, addend);
+ return object;
}
-*/
+
template<class Type>
void new_show(const Type& object)
Modified: sandbox/icl/libs/icl/test/test_casual_/test_casual.cpp
==============================================================================
--- sandbox/icl/libs/icl/test/test_casual_/test_casual.cpp (original)
+++ sandbox/icl/libs/icl/test/test_casual_/test_casual.cpp 2012-07-30 18:10:47 EDT (Mon, 30 Jul 2012)
@@ -57,13 +57,18 @@
IntervalMapT m1;
m1.insert(make_pair(0, 1));
- m1.insert(make_pair(6, 2));
+ m1.insert(make_pair(6, 0));
IntervalMapT m2;
m2.insert(make_pair(0, 1));
m2.insert(make_pair(4, 3));
+ m2.insert(m2.end(), make_pair(6, 0));
IntervalMapT m3 = joining_add(m1, m2);
+ //JODO if the interval starts with the minimum: failue, will not overwrite first
+ //add_interval( m3, make_pair(interval<int>::right_open(0,6), 1) );
+ add_interval( m3, make_pair(interval<int>::right_open(0,6), 1) );
+
new_show(m3);
BOOST_CHECK_EQUAL(true, true);
@@ -79,10 +84,11 @@
FlatIntervalMapT m1;
m1.insert(m1.end(), make_pair(0, 1));
- m1.insert(m1.end(), make_pair(6, 2));
+ m1.insert(m1.end(), make_pair(6, 0));
FlatIntervalMapT m2;
m2.insert(m2.end(), make_pair(0, 1));
m2.insert(m2.end(), make_pair(4, 3));
+ m2.insert(m2.end(), make_pair(6, 0));
FlatIntervalMapT m3 = joining_add(m1, m2);
@@ -97,10 +103,11 @@
FlatIntervalMapT m1;
m1.insert(m1.end(), make_pair(0, 1));
- m1.insert(m1.end(), make_pair(6, 2));
+ m1.insert(m1.end(), make_pair(6, 0));
FlatIntervalMapT m2;
m2.insert(m2.end(), make_pair(0, 1));
m2.insert(m2.end(), make_pair(4, 3));
+ m2.insert(m2.end(), make_pair(6, 0));
FlatIntervalMapT m3 = joining_add(m1, m2);
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