~barry/ubuntu/precise/boost1.46/debian-merge

« back to all changes in this revision

Viewing changes to boost/icl/concept/interval_associator.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2011-03-13 00:37:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110313003735-r7j6jdk0hkywfzuw
Tags: 1.46.1-1
* New upstream.

* control: Add libboost-random1.46-dev to depends of -all-dev and
  suggests of -dev.  Closes: #615849.

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
    return dist;
203
203
}
204
204
 
205
 
 
206
205
//==============================================================================
207
206
//= Range<IntervalSet|IntervalMap>
208
207
//==============================================================================
220
219
 
221
220
template<class Type>
222
221
typename enable_if<is_interval_container<Type>, 
223
 
                   typename Type::interval_type>::type
 
222
                   typename domain_type_of<Type>::type>::type
224
223
lower(const Type& object)
225
224
{
 
225
    typedef typename domain_type_of<Type>::type DomainT;
226
226
    return 
227
227
        icl::is_empty(object) 
228
 
            ? identity_element<typename Type::interval_type>::value()
 
228
            ? unit_element<DomainT>::value()
229
229
            : icl::lower( key_value<Type>(object.begin()) );
230
230
}
231
231
 
232
232
template<class Type>
233
233
typename enable_if<is_interval_container<Type>, 
234
 
                   typename Type::interval_type>::type
 
234
                   typename domain_type_of<Type>::type>::type
235
235
upper(const Type& object)
236
236
{
 
237
    typedef typename domain_type_of<Type>::type DomainT;
237
238
    return 
238
239
        icl::is_empty(object) 
239
 
            ? identity_element<typename Type::interval_type>::value()
 
240
            ? identity_element<DomainT>::value()
240
241
            : icl::upper( key_value<Type>(object.rbegin()) );
241
242
}
242
243
 
244
245
template<class Type>
245
246
typename enable_if
246
247
< mpl::and_< is_interval_container<Type>
247
 
           , is_discrete<typename Type::domain_type> >
248
 
, typename Type::interval_type>::type
 
248
           , is_discrete<typename domain_type_of<Type>::type> > 
 
249
, typename domain_type_of<Type>::type>::type
249
250
first(const Type& object)
250
251
{
 
252
    typedef typename domain_type_of<Type>::type DomainT;
251
253
    return 
252
254
        icl::is_empty(object) 
253
 
            ? identity_element<typename Type::interval_type>::value()
 
255
            ? unit_element<DomainT>::value()
254
256
            : icl::first( key_value<Type>(object.begin()) );
255
257
}
256
258
 
257
259
template<class Type>
258
260
typename enable_if
259
261
< mpl::and_< is_interval_container<Type>
260
 
           , is_discrete<typename Type::domain_type> >
261
 
, typename Type::interval_type>::type
 
262
           , is_discrete<typename domain_type_of<Type>::type> >
 
263
, typename domain_type_of<Type>::type>::type
262
264
last(const Type& object)
263
265
{
 
266
    typedef typename domain_type_of<Type>::type DomainT;
264
267
    return 
265
268
        icl::is_empty(object) 
266
 
            ? identity_element<typename Type::interval_type>::value()
 
269
            ? identity_element<DomainT>::value()
267
270
            : icl::last( key_value<Type>(object.rbegin()) );
268
271
}
269
272
 
646
649
//------------------------------------------------------------------------------
647
650
template<class Type, class CoType>
648
651
typename enable_if<mpl::and_< is_interval_container<Type>
649
 
                            , is_same<CoType, domain_type_of<Type> > >, 
 
652
                            , boost::is_same<CoType, typename domain_type_of<Type>::type> >, 
650
653
                   bool>::type
651
654
intersects(const Type& left, const CoType& right)
652
655
{
655
658
 
656
659
template<class Type, class CoType>
657
660
typename enable_if<mpl::and_< is_interval_container<Type>
658
 
                            , is_same<CoType, interval_type_of<Type> > >, 
 
661
                            , boost::is_same<CoType, typename interval_type_of<Type>::type> >, 
659
662
                   bool>::type
660
663
intersects(const Type& left, const CoType& right)
661
664
{
662
665
    return left.find(right) != left.end();
663
666
}
664
667
 
 
668
 
665
669
template<class LeftT, class RightT>
666
670
typename enable_if< mpl::and_< is_intra_combinable<LeftT, RightT> 
667
671
                             , mpl::or_<is_total<LeftT>, is_total<RightT> > >
720
724
    return false; 
721
725
}
722
726
 
723
 
template<class Type, class AssociateT>
724
 
typename enable_if<mpl::and_< is_interval_map<Type>
725
 
                            , is_inter_derivative<Type, AssociateT> >, 
726
 
                   bool>::type
727
 
intersects(const Type& left, const AssociateT& right)
728
 
{
729
 
    return icl::intersects(left, right);
730
 
}
731
 
 
732
727
/** \b Returns true, if \c left and \c right have no common elements.
733
728
    Intervals are interpreted as sequence of elements.
734
729
    \b Complexity: loglinear, if \c left and \c right are interval containers. */
750
745
    return !intersects(left,right);
751
746
}
752
747
 
 
748
 
753
749
//==============================================================================
754
750
//= Symmetric difference<IntervalSet|IntervalSet>
755
751
//==============================================================================
895
891
    return typename Type::element_const_reverse_iterator(object.rend());
896
892
}
897
893
 
898
 
//==============================================================================
899
 
//= Morphisms
900
 
//==============================================================================
901
 
template<class Type>
902
 
typename enable_if<is_interval_container<Type>, Type>::type&
903
 
join(Type& object)
904
 
{
905
 
    typedef typename Type::interval_type interval_type;
906
 
    typedef typename Type::iterator      iterator;
907
 
 
908
 
    iterator it_ = object.begin();
909
 
    if(it_ == object.end()) 
910
 
        return object;
911
 
 
912
 
    iterator next_ = it_; next_++;
913
 
 
914
 
    while(next_ != object.end())
915
 
    {
916
 
        if( segmental::is_joinable<Type>(it_, next_) )
917
 
        {
918
 
            iterator fst_mem = it_;  // hold the first member
919
 
            
920
 
            // Go on while touching members are found
921
 
            it_++; next_++;
922
 
            while(     next_ != object.end()
923
 
                    && segmental::is_joinable<Type>(it_, next_) )
924
 
            { it_++; next_++; }
925
 
 
926
 
            // finally we arrive at the end of a sequence of joinable intervals
927
 
            // and it points to the last member of that sequence
928
 
            const_cast<interval_type&>(key_value<Type>(it_)) 
929
 
                = hull(key_value<Type>(it_), key_value<Type>(fst_mem));
930
 
            object.erase(fst_mem, it_);
931
 
 
932
 
            it_++; next_=it_; 
933
 
            if(next_!=object.end())
934
 
                next_++;
935
 
        }
936
 
        else { it_++; next_++; }
937
 
    }
938
 
    return object;
939
 
}
940
 
 
941
 
 
942
 
 
943
894
}} // namespace boost icl
944
895
 
945
896
#endif