示例#1
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);
 }
示例#2
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;
 }
void UpdaterBoostNoUnits::solar_system_coor::operator()(const container_t& p, container_t& dqdt) const
{
    assert(p.size() == m_masses.size());
    assert(dqdt.size() == m_masses.size());
    const auto n = m_masses.size();
    for(size_t i=0 ; i<n ; ++i)
        dqdt[i] = p[i] / m_masses[i];
}
示例#4
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();
 }
示例#5
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";
}
示例#6
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;
  }
示例#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
        }
    }
示例#9
0
  typename std::enable_if<std::is_class<container_t>::value && sizeof(typename container_t::value_type)!=0
			  //has_member_function size,
			  ,
			  const typename container_t::value_type*>::type
  end(const container_t& _array){

    return &_array[_array.size()];
    
  }
  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;
  }
示例#11
0
 value_t convert2(const container_t& c) {
     try {
         return c.operator value_t();
     }
     catch(const std::exception& e) {
         OH_FAIL("Unable to convert type '" << c.type().name()
             << "' to type '" << typeid(value_t).name() << "' - " << e.what());
     }
 }
示例#12
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
 }
void UpdaterBoostNoUnits::solar_system_momentum::operator()(const container_t& q, container_t& dpdt) const
{
    assert(q.size() == m_masses.size());
    assert(dpdt.size() == m_masses.size());
    const size_t n = q.size();
    for(size_t i=0 ; i<n ; ++i)
    {
        dpdt[i] = Point3D<double>{0};
        for(size_t j=0 ; j<i ; ++j)
        {
            const auto diff = q[j] - q[i];
            const auto d = diff.norm();
            const auto res = diff * ( gravitational_constant * m_masses[i] * m_masses[j] / d / d / d );
            dpdt[i] += res;
            dpdt[j] -= res;

        }
    }
}
示例#14
0
 value_t convert2(const container_t& c, const std::string &parameterName, const value_t& defaultValue) {
     try {
         if(c.missing())    
             return defaultValue;
         return convert2<value_t, container_t>(c);
     }
     catch(const std::exception& e) {
         OH_FAIL("Error converting parameter '" << parameterName << "' : '" << e.what());
     }
 }
示例#15
0
 value_t convert2(const container_t& c, const std::string &parameterName, 
         const value_t& defaultValue, const value_t& errorValue) {
     try {
         if(c.error())    
             return errorValue;
         return convert2<value_t, container_t>(c, parameterName, defaultValue);
     }
     catch(const std::exception&) {
         return errorValue;
     }
 }
示例#16
0
static void makeWeightedOne(float wA,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & a,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & aEnd,
							container_t & result) {
	// Add the elements of the single map.
	while(a != aEnd) {
		const VisibilityVector::benefits_t weightedBenefits = (wA * a->second);
		if(weightedBenefits > 0) {
			result.emplace_back(a->first, weightedBenefits);
		}
		++a;
	}
}
示例#17
0
static void makeWeightedTwo(float wA,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & a,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & aEnd,
							float wB,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & b,
							std::vector<VisibilityVector::node_benefits_pair_t>::const_iterator & bEnd,
							container_t & result) {
	// Compare elements of the two maps.
	while(a != aEnd && b != bEnd) {
		if(a->first < b->first) {           // Object is only in map of vvA.
			const VisibilityVector::benefits_t weightedBenefits = (wA * a->second);
			if(weightedBenefits > 0) {
				result.emplace_back(a->first, weightedBenefits);
			}
			++a;
		} else if(b->first < a->first) {    // Object is only in map of vvB.
			const VisibilityVector::benefits_t weightedBenefits = (wB * b->second);
			if(weightedBenefits > 0) {
				result.emplace_back(b->first, weightedBenefits);
			}
			++b;
		} else {                            // Object is in both maps.
			const VisibilityVector::benefits_t weightedBenefits = (wA * a->second + wB * b->second);
			if(weightedBenefits > 0) {
				result.emplace_back(a->first, weightedBenefits);
			}
			++a;
			++b;
		}
	}
	if(a == aEnd) {
		makeWeightedOne(wB, b, bEnd, result);
	} else {
		makeWeightedOne(wA, a, aEnd, result);
	}
}
 void zero(container_t & vv)
 {
   std::fill(vv.begin(), vv.end(), 0);
 }
示例#19
0
文件: solution.cpp 项目: cvalka4/cupt
	void reserve(size_t size) { __container.reserve(size); }
示例#20
0
 bool containsValue(const VALUE& value) const
 {
     return findValue(value) != m_contents.end();
 }
示例#21
0
 const_iterator end() const      { return m_contents.end(); }
示例#22
0
文件: solution.cpp 项目: cvalka4/cupt
	void erase(const_iterator_t position)
	{
		__container.erase(__position_to_iterator(position));
	}
示例#23
0
文件: solution.cpp 项目: cvalka4/cupt
	void push_back(const data_t& data)
	{
		__container.push_back(data);
	}
示例#24
0
文件: solution.cpp 项目: cvalka4/cupt
	// this insert() is called only for unexisting elements
	iterator_t insert(const_iterator_t position, data_t&& data)
	{
		auto distance = position - begin();
		__container.insert(__position_to_iterator(position), std::move(data));
		return const_cast< iterator_t >(begin()) + distance;
	}
示例#25
0
文件: solution.cpp 项目: cvalka4/cupt
	const_iterator_t end() const { return &*__container.end(); }
示例#26
0
 const_iterator begin() const    { return m_contents.begin(); }
示例#27
0
 bool socket_t::send(const container_t& message, int flags) {
   return send(static_cast<const void*>(message.data()), message.size(), flags);
 }
示例#28
0
文件: solution.cpp 项目: cvalka4/cupt
	size_t size() const { return __container.size(); }
示例#29
0
文件: solution.cpp 项目: cvalka4/cupt
	const_iterator_t begin() const { return &*__container.begin(); }
示例#30
0
 std::size_t size() const { return m_contents.size(); }