/** Update the console messages. This function will remove messages that are overdue. */ void updateConsoleMessages(void) { // If there are no messages or we're on permanent (usually for scripts) then exit if ((!getNumberConsoleMessages() && !InfoMessages.size()) || mainConsole.permanent) { return; } for (auto i = InfoMessages.begin(); i != InfoMessages.end();) { if (realTime - i->timeAdded > messageDuration) { i = InfoMessages.erase(i); } else { ++i; } } // Time to kill all expired ones for (auto i = ActiveMessages.begin(); i != ActiveMessages.end();) { if (realTime - i->timeAdded > messageDuration) { i = ActiveMessages.erase(i); } else { ++i; } } }
void next(std::deque<std::deque<match_t *> > *last_round, std::deque<player_t *> &tournament_players) { int half = tournament_players.size()/2; /** "Rotates clockwise" */ tournament_players.insert(tournament_players.begin() + 1, tournament_players[half]); tournament_players.erase(tournament_players.begin() + half + 1); tournament_players.insert(tournament_players.end(), tournament_players[half]); tournament_players.erase(tournament_players.begin() + half); }
void bad_erase_deque1(std::deque<int> &D) { auto i2 = D.cbegin(), i0 = i2++, i1 = i2++; D.erase(i1); *i0; // expected-warning{{Invalidated iterator accessed}} *i1; // expected-warning{{Invalidated iterator accessed}} *i2; // expected-warning{{Invalidated iterator accessed}} }
bool remove(std::deque<RHNode> &vec, RHNode &element) { std::deque<RHNode>::iterator it = std::find(vec.begin(), vec.end(), element); if(it == vec.end()) return true; vec.erase(it); return true; }
bool deactive(thread_control_block *tcb){ threads.erase(std::find(threads.begin(), threads.end(), tcb)); threads.push_back(tcb); sem_post(&service_count); int v; sem_getvalue(&service_count, &v); return true; }
void UserPhotosSliceBuilder::sliceToLimits() { auto aroundIt = ranges::find(_ids, _key.photoId); auto removeFromBegin = (aroundIt - _ids.begin() - _limitBefore); auto removeFromEnd = (_ids.end() - aroundIt - _limitAfter - 1); if (removeFromEnd > 0) { _ids.erase(_ids.end() - removeFromEnd, _ids.end()); _skippedAfter += removeFromEnd; } if (removeFromBegin > 0) { _ids.erase(_ids.begin(), _ids.begin() + removeFromBegin); if (_skippedBefore) { *_skippedBefore += removeFromBegin; } } else if (removeFromBegin < 0 && (!_skippedBefore || *_skippedBefore > 0)) { _insufficientPhotosAround.fire(_ids.empty() ? 0 : _ids.front()); } }
void EndSockWatch(SOCKET sock) { std::deque<SOCKET>::iterator it = std::find( socketwatches.begin(), socketwatches.end(), sock ); if (it != socketwatches.end()) socketwatches.erase(it); }
///Method to remove a symbol bool remove_symbol(const char* symbol_name) { for( typename std::deque<std::pair<std::string, T> >::iterator it = symbols.begin() ; it != symbols.end() ; it++ ){ if( it->first.compare(symbol_name) == 0 ){ symbols.erase(it); return true; } } return false; }
T popAt(int index) { if (index >= stacks.size()) { throw; } std::stack<T> &stack = *(stacks.begin() + index); T ret = stack.top(); stack.pop(); if (stack.size() == 0) { stacks.erase(stacks.begin() + index); } return ret; }
void deleteTrailingZeros() { auto reverse_it = std::find_if( pos_vec.rbegin(), pos_vec.rend(), [](int i) {return i != 0;} ); pos_vec.erase(reverse_it.base(),pos_vec.end()); };
CInputReceiver::~CInputReceiver(void) { std::deque<CInputReceiver*>::iterator ri; for(ri=inputReceivers.begin();ri!=inputReceivers.end();++ri){ if(*ri==this){ inputReceivers.erase(ri); break; } } }
void processTask(int position) { auto task = tasks[position]; tasks.erase(tasks.begin() + position); task->setTile(std::make_shared<Tile>(task->tileId(), s_projection, &task->source())); pendingTiles = true; processedCount++; }
void zZone::RemoveFromZoneList(void) { std::deque<zZone *>::iterator pos_found = std::find_if( sz_Zones.begin(), sz_Zones.end(), std::bind2nd( std::equal_to<zZone *>(), this) ); if(pos_found != sz_Zones.end()) sz_Zones.erase(pos_found); }
std::vector<T> FlowMath::dequeToVector(std::deque<T>& deq) { // convert the std::deque into a std::vector // std::vector<T> vec; typename std::deque<T>::iterator it = deq.begin(); while (deq.empty() == false) { vec.push_back(*it); deq.erase(it); it = deq.begin(); } return vec; }
/* * Removes outdated challenges * PRE: The caller has acquired a lock on mutex */ static void Cleanup() { auto now = Challenge::Clock::now(); challenges.erase( std::remove_if( challenges.begin(), challenges.end(), [&now]( const Challenge& challenge ) { return !challenge.ValidAt( now ); } ), challenges.end() ); }
void deque_erase (std::deque<T> d, T elt) { typename std::deque<T>::iterator iter = d.begin(); while (iter != d.end()) { T k = *iter; if (k == elt) { d.erase(iter); break; } } }
// ------------------------------------------------------------------------ void addAndSetTime(uint32_t ping, uint64_t server_time) { if (m_synchronised.load() == true) return; if (m_force_set_timer.load() == true) { m_force_set_timer.store(false); m_synchronised.store(true); STKHost::get()->setNetworkTimer(server_time + (uint64_t)(ping / 2)); return; } const uint64_t cur_time = StkTime::getMonoTimeMs(); // Discard too close time compared to last ping // (due to resend when packet loss) // 10 packets per second as seen in STKHost const uint64_t frequency = (uint64_t)((1.0f / 10.0f) * 1000.0f) / 2; if (!m_times.empty() && cur_time - std::get<2>(m_times.back()) < frequency) return; // Take max 20 averaged samples from m_times, the next addAndGetTime // is used to determine that server_time if it's correct, if not // clear half in m_times until it's correct if (m_times.size() >= 20) { uint64_t sum = std::accumulate(m_times.begin(), m_times.end(), (uint64_t)0, [cur_time](const uint64_t previous, const std::tuple<uint32_t, uint64_t, uint64_t>& b)->uint64_t { return previous + (uint64_t)(std::get<0>(b) / 2) + std::get<1>(b) + cur_time - std::get<2>(b); }); const int64_t averaged_time = sum / 20; const int64_t server_time_now = server_time + (uint64_t)(ping / 2); int difference = (int)std::abs(averaged_time - server_time_now); if (std::abs(averaged_time - server_time_now) < UserConfigParams::m_timer_sync_difference_tolerance) { STKHost::get()->setNetworkTimer(averaged_time); m_times.clear(); m_force_set_timer.store(false); m_synchronised.store(true); Log::info("NetworkTimerSynchronizer", "Network " "timer synchronized, difference: %dms", difference); return; } m_times.erase(m_times.begin(), m_times.begin() + 10); } m_times.emplace_back(ping, server_time, cur_time); }
void CFolderCrawler::RemoveDuplicate(std::deque<CTGitPath> &list,const CTGitPath &path) { for (auto it = list.cbegin(); it != list.cend(); ++it) { if(*it == path) { list.erase(it); it = list.cbegin(); /* search again*/ if (it == list.cend()) break; } } }
void Timer::update(gdl::GameClock const& gameClock, gdl::Input& input, std::deque<AObject*>& map) { (void)gameClock; (void)input; (void)map; this->_timer->update(); float elapsedTime = (this->_timer->getTotalElapsedTime()); float eltm = _timer->getElapsedTime(); std::stringstream tmp; if (123 - elapsedTime < 0) { while (map.size() > 0) if (map[0]->getType() != TIMER) map.erase(map.begin()); else map.erase(map.begin() + 1); map.push_front(new MyCursor(0, 0)); map.push_front(new MyMenu("libgdl_gl/images/bomber-accueil.png", 0, 0)); for (unsigned int i = 0; i < map.size(); ++i) map[i]->initialize(); } else if (120 - elapsedTime < 0 && 123 - elapsedTime >= 2) { while (map.size() > 0) map.erase(map.begin()); map.push_front(new MyMenu("libgdl_gl/images/bomber-gameover.png", 0, 0)); for (unsigned int i = 0; i < map.size(); ++i) map[i]->initialize(); } else { if (eltm < 0.0333) usleep((int)((0.0333 - eltm) * 1000000)); tmp << (120 - (int)elapsedTime); _time->setText(tmp.str()); } }
void CFolderCrawler::RemoveDuplicate(std::deque<CTGitPath> &list,const CTGitPath &path) { std::deque<CTGitPath>::iterator it, lastit; for(it = list.begin(); it != list.end(); ++it) { if(*it == path) { list.erase(it); it = list.begin(); /* search again*/ if(it == list.end()) break; } } }
std::vector<T> filter(const std::vector<T> & in) { assert(in.size() > 0); //--------------------------------------------------------------------- // init state unsigned hist_ptr = 0; std::fill(_history.begin(), _history.end(), in[0]); std::fill(_pool.begin(), _pool.end(), in[0]); // pool is keep sorted //--------------------------------------------------------------------- // filter input std::vector<T> out; out.reserve(in.size()); for(auto x : in) { // step 1, remove oldest value from the pool. auto last = _history[hist_ptr]; auto last_pos = std::lower_bound(_pool.begin(), _pool.end(), last); _pool.erase(last_pos); // step 2, insert new value into pool auto insert_pos = std::lower_bound(_pool.begin(), _pool.end(), x); _pool.insert(insert_pos, x); // step 3, write input value into history. _history[hist_ptr] = x; hist_ptr = (hist_ptr + 1) % _history.size(); // median is always the middle of the pool out.push_back(*(_pool.begin() +_median)); } return out; }
void OptimizeAndOutputSets(std::deque<GCodeSet> &vSets, unsigned int &uiLinesOut, FILE *pfOutput = stdout) { double dDepth = 0.0f; if (vSets.empty() == false) { dDepth = vSets[0].GetZStart(); } fprintf(stderr, "Sorting %u sets at depth %.02f\n", vSets.size(), dDepth); // // // SLOW sort algorithm, but the idea is to find the nearest place to jump to after completing // one operation (set). So we calculate the absolute nearest over and over as we move. The result // is very few long jumps (linear G0)! double dXLast = 0.0f; double dYLast = 0.0f; std::deque<GCodeSet> vOptimizedSet; while (vSets.empty() == false) { // // Search for nearest to dXLast, dYLast std::deque<std::pair<std::vector<GCodeSet>::size_type, double> > vDistance; std::deque<GCodeSet>::size_type index = 0; for (auto entry : vSets) { double dXDelta = entry.GetXStart() - dXLast; double dYDelta = entry.GetYStart() - dYLast; vDistance.push_back(std::make_pair(index, abs(dXDelta) + abs(dYDelta))); ++index; } std::sort(vDistance.begin(), vDistance.end(), SortLessPair); std::deque<GCodeSet>::size_type szIndex = vDistance.front().first; vOptimizedSet.push_back(vSets[szIndex]); auto erasey = vSets.begin() + szIndex; vSets.erase(erasey); dXLast = vOptimizedSet.back().GetXEnd(); dYLast = vOptimizedSet.back().GetYEnd(); } for (auto entry : vOptimizedSet) { fprintf(stderr, "\tOutputing set with %u lines\n", entry.GetLines().size()); for (auto line : entry.GetLines()) { ++uiLinesOut; fprintf(pfOutput, line.c_str()); } } }
void FreeGlobal(int count) { for (int i = 0; i < count; ++i) { std::size_t size = 0; size += g_globalFunction.size(); size += g_globalClosure.size(); size += g_globalString.size(); size += g_globalTable.size(); if (size == 0) return ; auto index = RandomNum(size); if (index < g_globalFunction.size()) { g_globalFunction.erase(g_globalFunction.begin() + index); } else if (index < g_globalFunction.size() + g_globalClosure.size()) { index -= g_globalFunction.size(); g_globalClosure.erase(g_globalClosure.begin() + index); } else if (index < g_globalFunction.size() + g_globalClosure.size() + g_globalString.size()) { index -= g_globalFunction.size() + g_globalClosure.size(); g_globalString.erase(g_globalString.begin() + index); } else { index -= g_globalFunction.size() + g_globalClosure.size() + g_globalString.size(); g_globalTable.erase(g_globalTable.begin() + index); } } }
bool Find(T &elem,const char *CallID) { std::deque<T>::iterator pos; for (pos = m_PreDataList.begin();pos < m_PreDataList.end();) { if (strcmp(CallID,(*pos).CallID) == 0) { strcpy(elem.CallID,CallID); strcpy(elem.ANI,(*pos).ANI); strcpy(elem.StationID,(*pos).StationID); m_PreDataList.erase(pos++); return true; } pos++; } return false; }
void CVideoBufferPoolDRMPRIME::Return(int id) { CSingleLock lock(m_critSection); m_all[id]->Unref(); auto it = m_used.begin(); while (it != m_used.end()) { if (*it == id) { m_used.erase(it); break; } else ++it; } m_free.push_back(id); }
Case lowest_node () { Case min = ouvert[0]; unsigned int i; int indice = 0; for(i = 1 ; i < ouvert.size(); i++) { if(ouvert[i].F < min.F) { min = ouvert[i]; indice = i; } } ouvert.erase(ouvert.begin() + indice); return min; }
void smoothTraj(){ if(!planned || current_path.size()<2) return; int i=1; State<2> a=startState; State<2> b=current_path[i]; while(i<current_path.size()){ // situtation always is of type a->m->b->n //if a->b feasible, remove m and set b=n to try to remove b if(segmentFeasibility(a,b)){ current_path.erase(current_path.begin()+i-1); b=current_path[i]; }else{ // if a->b unfeasible, we need to keep a->m, so a becomes m, b becomes n to try to remove the previous b a=current_path[i-1]; i++; b=current_path[i]; } } }
/** * Find best matching solutions to send to a slave from free slaves list. * Modify free slaves list accordingly. Form solutions vector and a destination * free slave number. * @param freeSlaves list of free slaves * @param sv vector of solutions * @param s pointer to the free slave to send * @return true if best match was found false otherwise */ bool findBestMatch(std::deque<int> &freeSlaves , std::vector<Solution> &sv, int &s) { bool rv = false; std::deque<int>::iterator i; if(BASE::mHasBestSolution && (!mNotServed.empty())){ for(i = freeSlaves.begin(); i != freeSlaves.end(); i ++) { std::vector<int>::iterator p; p = std::find(mNotServed.begin(), mNotServed.end(), *i); if(p != mNotServed.end()) { rv = true; s = *p; freeSlaves.erase(i); mNotServed.erase(p); sv.push_back(BASE::mBestSolution); break; } } } return rv; }
bool JsFile::AttemptOutput() { std::stable_sort(m_events.begin(), m_events.end(), EventOrder()); assert(m_readReq); size_t eventsWanted = m_readSize/sizeof(js_event); size_t eventsToSend = std::min(eventsWanted, m_events.size()); if (eventsToSend > 0) { std::deque<js_event>::iterator i = m_events.begin() + eventsToSend; // need events in a contiguous area of memory std::vector<js_event> buf(m_events.begin(), i); m_events.erase(m_events.begin(), i); fuse_reply_buf(m_readReq, (char*)buf.data(), buf.size()*sizeof(js_event)); m_readReq = 0; return true; } return false; }
std::deque<tgt::ivec2> Flow2D::flowPosToSlicePos(std::deque<tgt::vec2>& fps, const tgt::ivec2& sliceSize, const tgt::ivec2& offset) const { std::deque<tgt::ivec2> sps; // slice positions while (fps.empty() == false) { std::deque<tgt::vec2>::iterator it = fps.begin(); // no call to overloaded flowPosToViewportPos() for performance // tgt::vec2 aux(*it / static_cast<tgt::vec2>(dimensions_)); tgt::ivec2 sp( (static_cast<int>(tgt::round(aux.x * sliceSize.x)) + offset.x) % sliceSize.x, (static_cast<int>(tgt::round(aux.y * sliceSize.y)) + offset.y) % sliceSize.y); sps.push_back(sp); fps.erase(it); } return sps; }