Changeset 2357 for trunk/yat/utility/Segment.h
- Timestamp:
- Dec 1, 2010, 10:08:29 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/Segment.h
r2321 r2357 23 23 */ 24 24 25 #include "yat_assert.h" 26 25 27 #include <algorithm> 26 28 #include <functional> … … 33 35 \brief a class for a Segment or Interval 34 36 35 A class for a Segment [begin, end). 37 A Segment is defined by its \a begin and \a end. The end is not 38 included in the Segment, i.e., you could write the Segment as 39 [begin, end). Type T must be comparable, optionally with a 40 comparator Compare, which should implement <a 41 href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html"> 42 Strict Weak Ordering.</a>. 36 43 37 44 \since new in yat 0.7 … … 89 96 90 97 /** 91 \return true if all elements in \a lhs is less than all elements 92 in \a rhs, i.e., returns false if rhs.begin() is less than 93 lhs.end() 98 This function takes two Segment and compare them with comparator 99 Compare. If all elements in \a lhs is less than all elements in 100 \a rhs, \c true is returned. In other words, \c false is returned 101 if \a rhs.begin() is less than \a lhs.end(). 102 103 The exception is if both \a lhs and \a rhs are empty Segment 104 (i.e. begin equals end) and their begins and ends are equal, in 105 which case \c false is returned. This exception implies that 106 compare(x,x) always returns false. 94 107 95 108 \relates Segment … … 101 114 { 102 115 Compare c; 116 // begin <= end 117 YAT_ASSERT(!c(lhs.end(), lhs.begin())); 118 YAT_ASSERT(!c(rhs.end(), rhs.begin())); 119 // take care of case when both sides are zero segments 120 if (!c(lhs.begin(), lhs.end()) && !c(rhs.begin(), rhs.end())) { 121 return c(lhs.begin(), rhs.begin()); 122 } 123 103 124 return ! c(rhs.begin(), lhs.end()); 104 125 } 105 126 106 127 /** 107 \return -1 if all elements in lhs is less than all elements in 108 rhs; +1 if all elements in rhs is less than all elements in lhs; 109 and 0 if lhs and rhs overlap. 128 \return -1 if compare(lhs, rhs) is \c true, +1 if compare(rhs, 129 lhs) is \c true, and 0 otherwise 110 130 111 131 \relates Segment 132 133 \see compare(const Segment<T, Compare>&, const Segment<T, Compare>&) 112 134 113 135 \since new in yat 0.7 … … 115 137 template<typename T, class Compare> 116 138 int compare_3way(const Segment<T, Compare>& lhs, 117 139 const Segment<T, Compare>& rhs) 118 140 { 119 141 if (compare(lhs, rhs)) … … 125 147 126 148 /** 127 \return -1 if lhs is less than all elements in rhs; +1 if all128 elements in rhs is less than lhs; and 0 if lhs and rhs overlap149 \return -1 if \a element is less than all elements in \a segment, 150 0 if \a element overlaps with \a segment, and 1 otherwise. 129 151 130 152 \relates Segment … … 133 155 */ 134 156 template<typename T, class Compare> 135 int compare_3way(const T& lhs,136 const Segment<T, Compare>& rhs)157 int compare_3way(const T& element, 158 const Segment<T, Compare>& segment) 137 159 { 138 160 Compare comp; 139 if (comp( lhs, rhs.begin()))161 if (comp(element, segment.begin())) 140 162 return -1; 141 if (comp( lhs, rhs.end()))163 if (comp(element, segment.end())) 142 164 return 0; 143 165 return 1; … … 145 167 146 168 /** 147 \return intersection of \a a and \a b. If \a a and \ b do not169 \return intersection of \a a and \a b. If \a a and \a b do not 148 170 overlap an empty Section is returned (begin==end), but the exact 149 171 value of begin is undefined. … … 161 183 162 184 result.begin() = std::max(a.begin(), b.begin(), comp); 185 // the first max is needed in case a and b don't overlap 163 186 result.end() = std::max(result.begin(), 164 187 std::min(a.end(), b.end(), comp),
Note: See TracChangeset
for help on using the changeset viewer.