annotate DEPENDENCIES/generic/include/boost/icl/detail/set_algo.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*-----------------------------------------------------------------------------+
Chris@16 2 Copyright (c) 2007-2010: Joachim Faulhaber
Chris@16 3 +------------------------------------------------------------------------------+
Chris@16 4 Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
Chris@16 5 +------------------------------------------------------------------------------+
Chris@16 6 Distributed under the Boost Software License, Version 1.0.
Chris@16 7 (See accompanying file LICENCE.txt or copy at
Chris@16 8 http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 +-----------------------------------------------------------------------------*/
Chris@16 10 #ifndef BOOST_ICL_SET_ALGO_HPP_JOFA_990225
Chris@16 11 #define BOOST_ICL_SET_ALGO_HPP_JOFA_990225
Chris@16 12
Chris@16 13 #include <boost/type_traits/remove_const.hpp>
Chris@16 14 #include <boost/icl/detail/notate.hpp>
Chris@16 15 #include <boost/icl/concept/container.hpp>
Chris@16 16 #include <boost/icl/concept/set_value.hpp>
Chris@16 17 #include <boost/icl/concept/map_value.hpp>
Chris@16 18
Chris@16 19
Chris@16 20 namespace boost{namespace icl
Chris@16 21 {
Chris@16 22
Chris@16 23 namespace Set
Chris@16 24 {
Chris@16 25
Chris@16 26 template<class ObjectT, class ConstObjectT, class IteratorT>
Chris@16 27 bool common_range(IteratorT& lwb, IteratorT& upb, ObjectT& x1, const ConstObjectT& x2)
Chris@16 28 {
Chris@16 29 // lwb and upb are iterators of x1 marking the lower and upper bound of
Chris@16 30 // the common range of x1 and x2.
Chris@16 31 typedef typename ConstObjectT::const_iterator ConstObject_iterator;
Chris@16 32 // ObjectT may be const or non const.
Chris@16 33 typedef typename remove_const<ObjectT>::type PureObjectT;
Chris@16 34
Chris@16 35 lwb = x1.end();
Chris@16 36 upb = x1.end();
Chris@16 37
Chris@16 38 if(icl::is_empty(x1) || icl::is_empty(x2))
Chris@16 39 return false;
Chris@16 40
Chris@16 41 IteratorT x1_fst_ = x1.begin();
Chris@16 42 IteratorT x1_lst_ = x1.end(); x1_lst_--;
Chris@16 43
Chris@16 44 ConstObject_iterator x2_fst_ = x2.begin();
Chris@16 45 ConstObject_iterator x2_lst_ = x2.end(); x2_lst_--;
Chris@16 46
Chris@16 47 typename ObjectT::key_compare key_less;
Chris@16 48 if(key_less(icl::key_value< PureObjectT>(x1_lst_),
Chris@16 49 icl::key_value<ConstObjectT>(x2_fst_))) // {x1} {x2}
Chris@16 50 return false;
Chris@16 51 if(key_less(icl::key_value<ConstObjectT>(x2_lst_),
Chris@16 52 icl::key_value< PureObjectT>(x1_fst_))) // {x2} {x1}
Chris@16 53 return false;
Chris@16 54
Chris@16 55 // We do have a common range
Chris@16 56 lwb = x1.lower_bound(icl::key_value<ConstObjectT>(x2_fst_));
Chris@16 57 upb = x1.upper_bound(icl::key_value<ConstObjectT>(x2_lst_));
Chris@16 58
Chris@16 59 return true;
Chris@16 60 }
Chris@16 61
Chris@16 62
Chris@16 63 /** Function template <tt>contained_in</tt> implements the subset relation.
Chris@16 64 <tt>contained_in(sub, super)</tt> is true if <tt>sub</tt> is contained in <tt>super</tt> */
Chris@16 65 template<class SetType>
Chris@16 66 inline bool within(const SetType& sub, const SetType& super)
Chris@16 67 {
Chris@16 68 if(&super == &sub) return true;
Chris@16 69 if(icl::is_empty(sub)) return true;
Chris@16 70 if(icl::is_empty(super)) return false;
Chris@16 71
Chris@16 72 typename SetType::const_iterator common_lwb_, common_upb_;
Chris@16 73 if(!common_range(common_lwb_, common_upb_, sub, super))
Chris@16 74 return false;
Chris@16 75
Chris@16 76 typename SetType::const_iterator sub_ = common_lwb_, super_;
Chris@16 77 while(sub_ != common_upb_)
Chris@16 78 {
Chris@16 79 super_ = super.find(*sub_++);
Chris@16 80 if(super_ == super.end())
Chris@16 81 return false;
Chris@16 82 }
Chris@16 83 return true;
Chris@16 84 }
Chris@16 85
Chris@16 86 template<class SetType>
Chris@16 87 bool intersects(const SetType& left, const SetType& right)
Chris@16 88 {
Chris@16 89 typename SetType::const_iterator common_lwb_right_, common_upb_right_;
Chris@16 90 if(!common_range(common_lwb_right_, common_upb_right_, right, left))
Chris@16 91 return false;
Chris@16 92
Chris@16 93 typename SetType::const_iterator right_ = common_lwb_right_, found_;
Chris@16 94 while(right_ != common_upb_right_)
Chris@16 95 {
Chris@16 96 found_ = left.find(*right_++);
Chris@16 97 if(found_ != left.end())
Chris@16 98 return true; // found a common element
Chris@16 99 }
Chris@16 100 // found no common element
Chris@16 101 return false;
Chris@16 102 }
Chris@16 103
Chris@16 104
Chris@16 105 #ifdef BOOST_MSVC
Chris@16 106 #pragma warning(push)
Chris@16 107 #pragma warning(disable:4996) //'std::equal': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
Chris@16 108 #endif // I do guarantee here that I am using the parameters correctly :)
Chris@16 109
Chris@16 110 /** Function template <tt>lexicographical_equal</tt> implements
Chris@16 111 lexicographical equality. */
Chris@16 112 template<class SetType>
Chris@16 113 inline bool lexicographical_equal(const SetType& left, const SetType& right)
Chris@16 114 {
Chris@16 115 if(&left == &right)
Chris@16 116 return true;
Chris@16 117 else return left.iterative_size() == right.iterative_size()
Chris@16 118 && std::equal(left.begin(), left.end(), right.begin());
Chris@16 119 }
Chris@16 120
Chris@16 121 #ifdef BOOST_MSVC
Chris@16 122 #pragma warning(pop)
Chris@16 123 #endif
Chris@16 124
Chris@16 125
Chris@16 126 } // namespace Set
Chris@16 127
Chris@16 128 }} // namespace icl boost
Chris@16 129
Chris@16 130 #endif
Chris@16 131