void test<CONTAINER,HANDLER>::iterate(unsigned count, bool warm, bool write) { CONTAINER container; unsigned unused = 0; for(unsigned ii = 0; ii != count; ++ii) container.push_back(ii); if (warm) { for(typename CONTAINER::const_iterator iter = container.begin(); iter != container.end(); ++iter) { unused += *iter; } } boost::timer::cpu_timer timer; timer.start(); for(typename CONTAINER::const_iterator iter = container.begin(); iter != container.end(); ++iter) { unused += *iter; } timer.stop(); if (unused == 1234) { // won't happen std::cout << "YEAH RIGHT!"; } if (write) { dump(timer, "iterate", count, warm); } }
void test<CONTAINER,HANDLER>::insert(unsigned count, bool warm, bool write) { CONTAINER container; if (warm) { container.push_back(0); container.push_back(0); typename CONTAINER::iterator iter = ++container.begin(); for(unsigned ii = 0; ii != count; ++ii) { iter = _handler.insert(container, iter, 1); if (ii & 1) ++iter; } container.clear(); } container.push_back(0); container.push_back(0); boost::timer::cpu_timer timer; timer.start(); typename CONTAINER::iterator iter = ++container.begin(); for(unsigned ii = 0; ii != count; ++ii) { iter = _handler.insert(container, iter, 1); if (ii & 1) ++iter; } timer.stop(); if (write) { dump(timer, "middle insert", count, warm); } }
bool compare_map_pointers( const CONTAINER& lhs, const CONTAINER& rhs ) { typename CONTAINER::const_iterator i = lhs.begin(); typename CONTAINER::const_iterator j = rhs.begin(); while ( i != lhs.end() && j != rhs.end() && i->first == j->first && (i->second == 0 && j->second == 0 || i->second != 0 && j->second != 0 && *i->second == *j->second) ) { ++i; ++j; } return i == lhs.end() && j == rhs.end(); }
bool compare( const CONTAINER& lhs, const CONTAINER& rhs ) { typename CONTAINER::const_iterator i = lhs.begin(); typename CONTAINER::const_iterator j = rhs.begin(); while ( i != lhs.end() && j != rhs.end() && *i == *j ) { ++i; ++j; } return i == lhs.end() && j == rhs.end(); }
bool compare_map_weak_ptrs( const CONTAINER& lhs, const CONTAINER& rhs ) { typename CONTAINER::const_iterator i = lhs.begin(); typename CONTAINER::const_iterator j = rhs.begin(); while ( i != lhs.end() && j != rhs.end() && (i->second.lock().get() == 0 && j->second.lock().get() == 0 || i->second.lock() != 0 && j->second.lock() != 0 && *(i->second.lock()) == *(j->second.lock())) ) { ++i; ++j; } return i == lhs.end() && j == rhs.end(); }
bool compare_pointer_types( const CONTAINER& lhs, const CONTAINER& rhs ) { typename CONTAINER::const_iterator i = lhs.begin(); typename CONTAINER::const_iterator j = rhs.begin(); while ( i != lhs.end() && j != rhs.end() && (*i == 0 && *j == 0 || *i != 0 && *j != 0 && (*(*i) == *(*j) && SWEET_TYPEID(*(*i)) == SWEET_TYPEID(*(*j)))) ) { ++i; ++j; } return i == lhs.end() && j == rhs.end(); }
bool compare_container_of_containers( const CONTAINER& lhs, const CONTAINER& rhs ) { typename CONTAINER::const_iterator i = lhs.begin(); typename CONTAINER::const_iterator j = rhs.begin(); while ( i != lhs.end() && j != rhs.end() && compare(*i, *j) ) { ++i; ++j; } return i == lhs.end() && j == rhs.end(); }
template< typename CONTAINER > std::clock_t geminate( CONTAINER& cntr ) { const auto start = std::clock() ; for( auto iter = cntr.begin() ; iter != cntr.end() ; ++iter, ++iter ) iter = cntr.insert( iter, *iter ) ; return std::clock() - start ; }
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> void ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove) { // Starting values. ITERATOR iter = container.begin (); ITERATOR end = container.end (); ATTRIBUTES min = (*iter).int_id_.second (); key_to_remove = &(*iter).ext_id_; value_to_remove = &(*iter).int_id_; // The iterator moves thru the container searching for the entry // with the lowest ATTRIBUTES. for (++iter; iter != end; ++iter) { if (min > (*iter).int_id_.second ()) { // Ah! an item with lower ATTTRIBUTES... min = (*iter).int_id_.second (); key_to_remove = &(*iter).ext_id_; value_to_remove = &(*iter).int_id_; } } }
void HazardModule::RemoveExpiredHazardsHelperProcessContainer(CONTAINER& container) { // NOTE: in the future we may want to keep the array sorted based on // expiry time or something. const float nowTimeIndex = gEnv->pTimer->GetCurrTime(); bool expiredFlag = false; typename CONTAINER::iterator iter = container.begin(); while (iter != container.end()) { expiredFlag = false; if (iter->GetExpireTimeIndex() >= 0) { if (iter->GetExpireTimeIndex() <= nowTimeIndex) { expiredFlag = true; } } if (expiredFlag) { iter = ExpireAndDeleteHazardInstance(container, iter); expiredFlag = false; } else { ++iter; } } }
void HazardModule::ProcessCollisionsWithEntityProcessContainer( CONTAINER& container, Agent& agent, const char *signalFunctionName, const EntityId entityID) { assert(signalFunctionName != NULL); HazardCollisionResult collisionResult; // NOTE: for now this will be quick and dirty. If the amount of hazards // becomes too big we should apply some spatial hashing schemes! typename CONTAINER::const_iterator hazardIter; typename CONTAINER::const_iterator hazardEndIter = container.end(); for (hazardIter = container.begin() ; hazardIter != hazardEndIter ; ++hazardIter) { if (hazardIter->ShouldWarnEntityID(entityID)) { hazardIter->CheckCollision(agent, &collisionResult); if (collisionResult.m_CollisionFlag) { if (hazardIter->IsAgentAwareOfDanger(agent, collisionResult.m_HazardOriginPos)) { SendSignalToAgent(agent, signalFunctionName, collisionResult.m_HazardOriginPos, hazardIter->GetNormal()); } } } } }
void HazardModule::PurgeAllHazardsProcessContainer(CONTAINER& container) { typename CONTAINER::iterator iter = container.begin(); while (iter != container.end()) { iter = ExpireAndDeleteHazardInstance(container, iter); } }
void HazardModule::StartRequestedRayCastsProcessContainer(CONTAINER& container) { typename CONTAINER::iterator iter; typename CONTAINER::iterator iterEnd = container.end(); for (iter = container.begin() ; iter != iterEnd ; ++iter) { iter->StartRequestedRayCasts(this); } }
void HazardModule::RenderDebugProcessContainer( const CONTAINER& container, IPersistantDebug& debugRenderer) const { typename CONTAINER::const_iterator iter; typename CONTAINER::const_iterator Enditer = container.end(); for (iter = container.begin() ; iter != Enditer ; ++iter) { iter->DebugRender(debugRenderer); } }
void clear_map_pointers( CONTAINER& container ) { typename CONTAINER::iterator i = container.begin(); while ( i != container.end() ) { delete i->second; ++i; } container.clear(); }
void HazardModule::ExpireHazardProcessContainer( CONTAINER& container, const HazardID hazardInstanceID) { CRY_ASSERT_MESSAGE((m_UpdateLockCount == 0), "Not allowed to unregister hazards to the hazard module while it is updating!"); int index = IndexOfInstanceID(container, hazardInstanceID); if (index < 0) { return; } ExpireAndDeleteHazardInstance(container, container.begin() + index); }
void fillContainer(T min, T max, CONTAINER& randContainer, ::boost::uint32_t seedVal = std::time(NULL)) { SLM_ASSERT("Wrong min/max value", min <= max); SLM_ASSERT("Container type not same as T", (::boost::is_same< T, typename CONTAINER::value_type>::value) ); typedef typename ::boost::mpl::if_< ::boost::is_floating_point<T>, ::boost::uniform_real<>, ::boost::uniform_int<> >::type DistroType; ::boost::mt19937 seed(seedVal); DistroType dist(min, max); ::boost::variate_generator< ::boost::mt19937&, DistroType > random(seed, dist); std::generate(randContainer.begin(), randContainer.end(), random); }
void HazardModule::PurgeHazardsWithPendingRayRequestsProcessContainer(CONTAINER& container) { typename CONTAINER::iterator iter = container.begin(); while (iter != container.end()) { if (iter->HasPendingRayCasts()) { iter = ExpireAndDeleteHazardInstance(container, iter); } else { ++iter; } } }
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> void ACE_Refcounted_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum (CONTAINER &container, KEY *&key_to_remove, VALUE *&value_to_remove) { // Starting values. ITERATOR end = container.end (); ITERATOR iter = container.begin (); ATTRIBUTES min = (*iter).int_id_.second (); key_to_remove = 0; value_to_remove = 0; // Found the minimum entry to be purged? int found = 0; // The iterator moves thru the container searching for the entry // with the lowest ATTRIBUTES. for (; iter != end; ++iter) { // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach // the first entry which can be purged. This is the minimum with // which you will compare the rest of the purgable entries. if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE || (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE) { if (found == 0) { min = (*iter).int_id_.second (); key_to_remove = &(*iter).ext_id_; value_to_remove = &(*iter).int_id_; found = 1; } else { // Ah! an entry with lower ATTTRIBUTES... if (min > (*iter).int_id_.second ()) { min = (*iter).int_id_.second (); key_to_remove = &(*iter).ext_id_; value_to_remove = &(*iter).int_id_; } } } } }
strings( const CONTAINER &other ) : std::deque< string >( other.begin(), other.end() ) {}
bool contains(const CONTAINER& cont, const VALUE& val) { return std::find(cont.begin(), cont.end(), val) != cont.end(); }
bool operator()( const CONTAINER& lhs, const CONTAINER& rhs ) { std::lexicographical_compare( lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), PREDICATE ); }