示例#1
0
 const_iterator findKey(const KEY& key) const
 {
     // binary search for key
     const_iterator it(std::lower_bound(m_contents.begin(), m_contents.end(), key, KeyCmp()));
     if (it != m_contents.end() && CMP()(key, it->first)) // it > it-1, check ==
         it = m_contents.end();
     return it;
 }
示例#2
0
 const_iterator findValue(const VALUE& value) const
 {
     for (auto&& it = m_contents.begin(); it != m_contents.end(); ++it)
     {
         if (it->second == value)
             return it;
     }
     return m_contents.end();
 }
示例#3
0
 void insert(const KEY &key, const VALUE &value)
 {
     erase(key);
     const pair_t p(key, value);
     auto it = std::lower_bound(m_contents.begin(), m_contents.end(), p);
     m_contents.insert(it, p);
 }
示例#4
0
void write(const std::string& name, const container_t& cont)
{
	std::cout << name << ": ";

	for( container_t::const_iterator it = cont.begin(); it != cont.end(); ++it )
		std::cout << *it << " ";

	std::cout << "\n";
}
示例#5
0
  inline void
  pointmesh2d<point_t>::add_row(container_t const& c)
  {
    std::size_t oldsize(_points.size());

    std::copy(c.begin(), c.end(), std::back_inserter(_points));

    _width = _points.size() - oldsize;
    ++_height;
  }
示例#6
0
 bool tryFind(const KEY& key, const_iterator& returnValue) const
 {
     const_iterator it = findKey(key);
     if (it != m_contents.end())
     {
         returnValue = it;
         return true;
     }
     return false; // not found
 }
示例#7
0
void set_add(container_t& container, typename container_t::value_type value)
{
    auto it = container.begin();
    while (it != container.end() && *it < value)
    {
        ++it;
    }

    if (*it != value)
    {
        container.insert(it, value);
    }
}
示例#8
0
    void erase(const KEY& key)
    {
        const_iterator it = findKey(key);
        if (it != m_contents.end())
        {
            // Avoid std::vector.erase here due to bug in libstdc++ < v4.9
#if PONDER_WORKAROUND_GCC_N2350
            std::size_t pos = it - m_contents.begin();
            const std::size_t sz = m_contents.size() - 1;
            while (pos < sz)
                m_contents[pos] = m_contents[pos + 1], ++pos;
            m_contents.resize(sz);
#else
            m_contents.erase(it);
#endif
        }
    }
  bool compare(container_t const & lhs, container_t const & rhs, typename container_t::value_type precision)
  {
    if (&lhs == &rhs) {
      return true;
    }
    if (lhs.size() != rhs.size()) {
      return false;
    }
    typename container_t::const_iterator il(lhs.begin());
    typename container_t::const_iterator ir(rhs.begin());
    typename container_t::const_iterator il_end(lhs.end());
    for (/**/; il != il_end; ++il, ++ir) {
      if (fabs(*il - *ir) > precision) {
	return false;
      }
    }
    return true;
  }
 void zero(container_t & vv)
 {
   std::fill(vv.begin(), vv.end(), 0);
 }
示例#11
0
文件: solution.cpp 项目: cvalka4/cupt
	const_iterator_t end() const { return &*__container.end(); }
示例#12
0
 const_iterator end() const      { return m_contents.end(); }
示例#13
0
 bool containsValue(const VALUE& value) const
 {
     return findValue(value) != m_contents.end();
 }
示例#14
0
 bool containsKey(const KEY& key) const
 {
     return findKey(key) != m_contents.end();
 }