Changeset 2360
- Timestamp:
- Dec 4, 2010, 2:04:45 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/segment_test.cc
r2358 r2360 214 214 avoid_pedantic_warning(x); 215 215 Map::key_type key = Segment<double>(1.0,2.0); 216 avoid_pedantic_warning(key);217 216 Map::mapped_type mapped = "foofana"; 218 avoid_pedantic_warning(mapped); 217 218 map.insert(Map::value_type(key, mapped)); 219 suite.add(map.find(1.5) != map.end()); 220 suite.add(map.find(1.5)->second == "foofana"); 219 221 } 220 222 -
trunk/yat/utility/SegmentMap.h
r2358 r2360 25 25 #include "Segment.h" 26 26 #include "SegmentTree.h" 27 #include "stl_utility.h" 27 28 28 29 #include <map> … … 43 44 : public SegmentTree<std::map<Segment<T, Compare>, Tp, 44 45 SegmentCompare<T, Compare> >, 45 Compare> 46 Compare, 47 PairFirst<const std::pair<const Segment<T, Compare>, Tp> > > 46 48 { 47 49 public: -
trunk/yat/utility/SegmentSet.h
r2358 r2360 25 25 #include "Segment.h" 26 26 #include "SegmentTree.h" 27 27 #include "stl_utility.h" 28 28 #include "yat_assert.h" 29 29 … … 46 46 : public SegmentTree<std::set<Segment<T, Compare>, 47 47 SegmentCompare<T, Compare> >, 48 Compare> 48 Compare, 49 Identity<const Segment<T, Compare>&> > 49 50 { 50 51 typedef SegmentSet<T, Compare> me; -
trunk/yat/utility/SegmentTree.h
r2358 r2360 36 36 /** 37 37 \brief Base Class for SegmentSet and SegmentMap 38 39 - Container: underlying container (set or map) 40 - Compare: functor comparing elements (same as in Segment) 41 - Value2Key: functor translating a \c const_reference to \c 42 key_type (or \c const&) 38 43 */ 39 template<class Container, class Compare >44 template<class Container, class Compare, class Value2Key> 40 45 class SegmentTree 41 46 { … … 206 211 }; 207 212 208 template<class Container, class Compare >209 typename SegmentTree<Container, Compare >::size_type210 SegmentTree<Container, Compare>::count(const element_type& element) const213 template<class Container, class Compare, class Value2Key> 214 typename SegmentTree<Container, Compare, Value2Key>::size_type 215 SegmentTree<Container,Compare,Value2Key>::count(const element_type& element) const 211 216 { 212 217 if (find(element)==end()) … … 216 221 217 222 218 template<class Container, class Compare >219 typename SegmentTree<Container, Compare >::const_iterator220 SegmentTree<Container, Compare >::find(const element_type& vt) const223 template<class Container, class Compare, class Value2Key> 224 typename SegmentTree<Container, Compare, Value2Key>::const_iterator 225 SegmentTree<Container, Compare, Value2Key>::find(const element_type& vt) const 221 226 { 222 227 const_iterator iter = lower_bound(vt); 223 228 element_compare comp; 224 if (iter==end() || comp(vt, iter->begin())) 229 // if (iter==end() || comp(vt, iter->begin())) 230 if (iter==end() || comp(vt, Value2Key()(*iter).begin())) 225 231 return end(); 226 232 return iter; … … 228 234 229 235 230 template<typename T, class Compare >231 std::pair<typename SegmentTree<T, Compare >::iterator, bool>232 SegmentTree<T, Compare >::insert(const value_type& segment)236 template<typename T, class Compare, class Value2Key> 237 std::pair<typename SegmentTree<T, Compare, Value2Key>::iterator, bool> 238 SegmentTree<T, Compare,Value2Key>::insert(const value_type& segment) 233 239 { 234 240 return container_.insert(segment); … … 236 242 237 243 238 template<typename T, class Compare >239 typename SegmentTree<T, Compare >::iterator240 SegmentTree<T, Compare >::lower_bound(const element_type& element)244 template<typename T, class Compare, class Value2Key> 245 typename SegmentTree<T, Compare, Value2Key>::iterator 246 SegmentTree<T, Compare,Value2Key>::lower_bound(const element_type& element) 241 247 { 242 248 key_type segment(element, element); 243 249 iterator result = container_.lower_bound(segment); 244 250 // result is larger or overlapping with segment (i.e.! result<segment) 245 YAT_ASSERT(result==end() || !compare(*result,segment)); 251 YAT_ASSERT(result==end() 252 || !compare(Value2Key()(*result),segment)); 246 253 return result; 247 254 } 248 255 249 256 250 template<typename T, class Compare >251 typename SegmentTree<T, Compare >::const_iterator252 SegmentTree<T, Compare >::lower_bound(const element_type& element) const257 template<typename T, class Compare, class Value2Key> 258 typename SegmentTree<T, Compare, Value2Key>::const_iterator 259 SegmentTree<T, Compare,Value2Key>::lower_bound(const element_type& element) const 253 260 { 254 261 key_type segment(element, element); 255 262 const_iterator result = container_.lower_bound(segment); 256 263 // result is larger or overlapping with segment (i.e.! result<segment) 257 YAT_ASSERT(result==end() || !compare(*result,segment)); 264 YAT_ASSERT(result==end() 265 || !compare(Value2Key()(*result),segment)); 258 266 return result; 259 267 } 260 268 261 269 262 template<typename T, class Compare >263 typename SegmentTree<T, Compare >::iterator264 SegmentTree<T, Compare >::upper_bound(const element_type& element)270 template<typename T, class Compare, class Value2Key> 271 typename SegmentTree<T, Compare, Value2Key>::iterator 272 SegmentTree<T, Compare,Value2Key>::upper_bound(const element_type& element) 265 273 { 266 274 key_type segment(element, element); … … 276 284 277 285 278 template<typename T, class Compare >279 typename SegmentTree<T, Compare >::const_iterator280 SegmentTree<T, Compare >::upper_bound(const element_type& element) const286 template<typename T, class Compare, class Value2Key> 287 typename SegmentTree<T, Compare, Value2Key>::const_iterator 288 SegmentTree<T, Compare,Value2Key>::upper_bound(const element_type& element) const 281 289 { 282 290 Segment<T, Compare> segment(element, element);
Note: See TracChangeset
for help on using the changeset viewer.