Changeset 2611


Ignore:
Timestamp:
Nov 5, 2011, 12:03:50 AM (10 years ago)
Author:
Peter
Message:

fixes #680 and #679

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/segment.cc

    r2370 r2611  
    3030void test_compare(test::Suite& suite);
    3131void test_count(test::Suite&);
     32void test_erase(test::Suite&);
    3233void test_insert(test::Suite&);
    3334void test_insert_merge(test::Suite&);
     
    4546  test_compare(suite);
    4647  test_count(suite);
     48  test_erase(suite);
    4749  test_insert(suite);
    4850  test_insert_merge(suite);
     
    99101  test_compare(suite, 0, 0, 0, 0, 0);
    100102  test_compare(suite, 0, 0, -1, -1, 1);
     103}
     104
     105
     106void test_erase(test::Suite& suite)
     107{
     108  suite.out() << "test_erase\n";
     109  suite.out() << "  SegmentSet\n";
     110  SegmentSet<double> set;
     111  set.insert(Segment<double>(0,2));
     112  set.insert(Segment<double>(10,20));
     113  set.insert(Segment<double>(30,50));
     114  SegmentSet<double>::iterator iter = set.find(15);
     115  set.erase(iter);
     116  if (!suite.add(set.size()==2))
     117    suite.err() << "size: " << set.size() << " expected 2\n";
     118  set.erase(set.begin(), set.end());
     119  if (!suite.add(set.size()==0))
     120    suite.err() << "size: " << set.size() << " expected 0\n";
     121  suite.out() << "  SegmentMap\n";
     122  typedef SegmentMap<double, std::string> Map;
     123  Map map;
     124  Map::key_type s(0,2);
     125  map.insert(Map::value_type(s, "aha"));
     126  map.erase(map.begin());
     127  map.erase(map.begin(), map.end());
    101128}
    102129
  • trunk/yat/utility/SegmentTree.h

    r2610 r2611  
    121121
    122122    /**
     123       erase segments in range [first, last)
     124
     125       \since New in yat 0.8
     126     */
     127    void erase(iterator first, iterator last) { container_.erase(first, last);}
     128
     129    /**
     130       erase segment pointed to by \a pos
     131
     132       \since New in yat 0.8
     133     */
     134    void erase(iterator pos) { container_.erase(pos); }
     135
     136    /**
     137       \return an iterator pointing to the Segment that contains \a
     138       vt. If no Segment contains \a vt, end() is returned.
     139
     140       \since New in yat 0.8
     141     */
     142    iterator find(const element_type& vt);
     143
     144    /**
    123145       \return an iterator pointing to the Segment that contains \a
    124146       vt. If no Segment contains \a vt, end() is returned.
     
    233255
    234256
     257  template<class Container, class Compare, class Value2Key>
     258  typename SegmentTree<Container, Compare, Value2Key>::iterator
     259  SegmentTree<Container, Compare, Value2Key>::find(const element_type& vt)
     260  {
     261    iterator iter = lower_bound(vt);
     262    element_compare comp;
     263    if (iter==end() || comp(vt, Value2Key()(*iter).begin()))
     264      return end();
     265    return iter;
     266  }
     267
     268
    235269  template<typename T, class Compare, class Value2Key>
    236270  std::pair<typename SegmentTree<T, Compare, Value2Key>::iterator, bool>
Note: See TracChangeset for help on using the changeset viewer.