1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2007-2010: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4    Distributed under the Boost Software License, Version 1.0.
5       (See accompanying file LICENCE.txt or copy at
6            http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_MAPALGO_HPP_JOFA_080225
9 #define BOOST_ICL_MAPALGO_HPP_JOFA_080225
10 
11 #include <boost/mpl/and.hpp>
12 #include <boost/mpl/or.hpp>
13 #include <boost/mpl/not.hpp>
14 #include <boost/icl/detail/notate.hpp>
15 #include <boost/icl/detail/set_algo.hpp>
16 
17 #ifdef BOOST_MSVC
18 #pragma warning(push)
19 #pragma warning(disable:4127) // conditional expression is constant
20 #endif
21 
22 namespace boost{namespace icl
23 {
24 namespace Map
25 {
26 
27 template <class ObjectT, class CoObjectT>
intersects(const ObjectT & left,const CoObjectT & right)28 bool intersects(const ObjectT& left, const CoObjectT& right)
29 {
30     typedef typename CoObjectT::const_iterator co_iterator;
31     co_iterator right_common_lower_, right_common_upper_;
32     if(!Set::common_range(right_common_lower_, right_common_upper_, right, left))
33         return false;
34 
35     co_iterator right_ = right_common_lower_;
36     while(right_ != right_common_upper_)
37         if(!(left.find(key_value<CoObjectT>(right_++))==left.end()))
38             return true;
39 
40     return false;
41 }
42 
43 
44 template<class MapT>
next_proton(typename MapT::const_iterator & iter_,const MapT & object)45 typename MapT::const_iterator next_proton(typename MapT::const_iterator& iter_, const MapT& object)
46 {
47     while(   iter_ != object.end()
48           && (*iter_).second == identity_element<typename MapT::codomain_type>::value())
49         ++iter_;
50 
51     return iter_;
52 }
53 
54 /** Function template <tt>lexicographical_equal</tt> implements
55 lexicographical equality except for identity_elementic content values. */
56 template<class MapT>
lexicographical_distinct_equal(const MapT & left,const MapT & right)57 bool lexicographical_distinct_equal(const MapT& left, const MapT& right)
58 {
59     if(&left == &right)
60         return true;
61 
62     typename MapT::const_iterator left_  = left.begin();
63     typename MapT::const_iterator right_ = right.begin();
64 
65     left_  = next_proton(left_,  left);
66     right_ = next_proton(right_, right);
67 
68     while(left_ != left.end() && right_ != right.end())
69     {
70         if(!(left_->first == right_->first && left_->second == right_->second))
71             return false;
72 
73         ++left_;
74         ++right_;
75         left_  = next_proton(left_,  left);
76         right_ = next_proton(right_, right);
77     }
78 
79     return left_ == left.end() && right_ == right.end();
80 }
81 
82 } // namespace Map
83 }} // namespace boost icl
84 
85 #ifdef BOOST_MSVC
86 #pragma warning(pop)
87 #endif
88 
89 #endif
90 
91