std::vector<std::vector<T> > subsets(std::vector<T> set,std::size_t k){
	if(set.size() == k){
		return {set};
	}
	if(k== 1){
		std::vector<std::vector<T> > result;
		for(auto const& point: set){
			result.push_back({point});
		}
		return result;
	}
	T point = set.back();
	set.pop_back();
	auto km1subsets = subsets(set,k-1);
	auto result = subsets(set,k);
	for(auto & s: km1subsets){
		s.push_back(point);
		result.push_back(std::move(s));
	}
	return result;
}
		thread_pool_executor(uint32_t aThreadCount) :
			mWorkerThreads(new std::thread[aThreadCount]),
			mThreadCount(aThreadCount),
			mExit(false)
		{
			const auto threadFn = [this]() {
				while(! mExit) {
					std::unique_lock<std::mutex> lock(mTasksLock);
					mTaskAdded.wait(lock);
					if(! mTasks.empty()) {
						std::function<void()> task = mTasks.back();
						mTasks.pop_back();
						lock.unlock();
						task();
					}
				}
			};

			for(uint32_t i = 0; i < aThreadCount; ++i) mWorkerThreads[i] = std::thread(threadFn);

		}
/**
**  Find all units to draw in viewport.
**
**  @param vp     Viewport to be drawn.
**  @param table  Table of units to return in sorted order
**
*/
int FindAndSortUnits(const CViewport &vp, std::vector<CUnit *> &table)
{
	//  Select all units touching the viewpoint.
	const Vec2i offset(1, 1);
	const Vec2i vpSize(vp.MapWidth, vp.MapHeight);
	const Vec2i minPos = vp.MapPos - offset;
	const Vec2i maxPos = vp.MapPos + vpSize + offset;

	Select(minPos, maxPos, table);

	size_t n = table.size();
	for (size_t i = 0; i < table.size(); ++i) {
		if (!table[i]->IsVisibleInViewport(vp)) {
			table[i--] = table[--n];
			table.pop_back();
		}
	}
	Assert(n == table.size());
	std::sort(table.begin(), table.begin() + n, DrawLevelCompare);
	return n;
}
Exemple #4
0
void NamingContextHelper::appendBindingList(CosNaming::BindingList_var& bList, std::vector<ObjectPath> pathList, ObjectInfoList& objects)
{
    for (CORBA::ULong i = 0; i < bList->length(); ++i) {
        ObjectInfo info;
        info.id_ = bList[i].binding_name[0].id;
        info.kind_ = bList[i].binding_name[0].kind;
        info.hostAddress_ = host_;
        info.portNo_ = port_;

        ObjectPath path(info.id_, info.kind_);
        pathList.push_back(path);

        CORBA::Object_ptr obj = findObjectSub(pathList);
        info.isAlive_ = isObjectAlive(obj);
        info.ior_ = orb->object_to_string(obj);
        copy(pathList.begin(), pathList.end(), std::back_inserter(info.fullPath_));
        pathList.pop_back();
        CORBA::release(obj);
        objects.push_back(info);
    }
}
gl_sframe grouped_sframe::get_group(std::vector<flexible_type> key) {
  if(!m_inited) {
    log_and_throw("The 'group' operation needs to occur before getting a "
        "group!");
  }
  //TODO: This is a HUGE hack. From the Python side, a list of ints is turned
  //in to a list of floats unless there's a None in it. We add a None so this
  //doesn't happen and take it away to look up the group. We'll actually fix
  //the problem soon.
  if((key.size() > 1) && (key.back().get_type() == flex_type_enum::UNDEFINED)) {
    key.pop_back();
  }
  auto ret = m_key2range.find(key);
  if(ret == m_key2range.end()) {
    log_and_throw("Group not found!");
  }

  size_t range_dir_idx = ret->second;

  return this->get_group_by_index(range_dir_idx);
}
Exemple #6
0
void RegionalTerrain_3r::TestAndSwapEdges(std::vector<QuadEdge::Edge*>& edges,
        const Point_3r& sample) {
    while (!edges.empty()) {
        QuadEdge::Edge *e1 = edges.back();
        edges.pop_back();
        QuadEdge::Vertex *v1 = e1->Org(), *v2 = e1->Dest();
        QuadEdge::Edge *e2 = e1->Lnext();
        QuadEdge::Edge *e3 = e1->Lprev();
        QuadEdge::Vertex *v3 = e2->Dest();
        QuadEdge::Edge *e4 = e1->Rnext();
        QuadEdge::Edge *e5 = e1->Rprev();

        if (Predicate::InCircle(*v1->pos, *v2->pos, *v3->pos, sample) > 0) {
            QuadEdge::Face *left = e1->Left();
            KillFaceEdge(e1);
            MakeFaceEdge(left, e2->Dest(), e5->Dest());
            edges.push_back(e2->Sym());
            edges.push_back(e3->Sym());
        }
    }
}
Exemple #7
0
/**
**  Cleanup the upgrade module.
*/
void CleanUpgrades(void)
{
	//
	//  Free the upgrades.
	//
	while (AllUpgrades.size()) {
		CUpgrade *upgrade = AllUpgrades.back();
		AllUpgrades.pop_back();
		delete upgrade;
	}
	Upgrades.clear();

	//
	//  Free the upgrade modifiers.
	//
	for (int i = 0; i < NumUpgradeModifiers; ++i) {
		delete[] UpgradeModifiers[i]->Modifier.Variables;
		delete UpgradeModifiers[i];
	}
	NumUpgradeModifiers = 0;
}
Exemple #8
0
void dfs(int depth,int last,int left){
    if(left == 1 ){
        int size = ans.size();
        long double temp  = 1.0;
        for(int i=0;i<size;i++){
            temp  *= (long double)pow(prime[i],ans[i]-1);
        }
        if( temp < result )
            result = temp;
    }
    else {
        int len = nd[left].size();
        for(int i=0;i<len;i++){
            if(nd[left][i] <=last ) {
                ans.push_back(nd[left][i]);
                dfs(depth+1,nd[left][i],left / nd[left][i]);
                ans.pop_back();
            }
        }
    }
}
Exemple #9
0
        T* getInstance()
        {
          if (pool.empty())
          {
            // we don't care about locking here since it is not dangerous to get a false answer
            return new T();
          }

          T* impl;

          {
            MutexLock lock(poolMutex);
            if (pool.empty())
              return new T();

            impl = pool.back();
            pool.pop_back();
          }

          return impl;
        }
Exemple #10
0
void RequestWorkloadStats::requestShutdown() {
  if (m_s.empty()) return;
  end(m_php);
  assertx(m_s.back() == State::InRequest);
  m_s.pop_back();
  assertx(m_s.empty());

  const auto php = m_php.acc;
  const auto interp = m_interp.acc;

  s_interpNanos->addValue(interp);
  s_requestNanos->addValue(php);

  if (php > 0) {
    s_interpVMRatio->addValue(interp * 10000 / php);
  }

  // Log state change counts.
  s_trans->addValue(m_transitionCounts[State::InTrans]);
  s_interps->addValue(m_transitionCounts[State::InInterp]);
}
Exemple #11
0
      /**
      * Try to merge region with same level
      * @param nextLevel Level used to limit search
      * @param pixel_x X-coord of the base of the merged region
      * @param pixel_y Y-coord of the base of the merged region
      */
      void MSERExtractor::ProcessStack( const int nextLevel , const int pixel_x , const int pixel_y , std::vector<MSERRegion * > & regionStack ) const
      {
        do
        {
          MSERRegion * top = regionStack.back();
          regionStack.pop_back();

          if (nextLevel < regionStack.back()->m_level )
          {
            regionStack.push_back( new MSERRegion( nextLevel , pixel_x , pixel_y ) );

            regionStack.back()->MergeRegion( top );
            return;
          }

          regionStack.back()->MergeRegion( top );


        }
        while (nextLevel > regionStack.back()->m_level);
      }
Exemple #12
0
    // If board[w] becomes T() again, we need to update who
    inline void decrement(size_type w)
    {
      assert(w < board.size());

      if (board[w] == T()) {
        who.push_back(w);
        //assert(std::set<size_type>(who.begin(),who.end()).size() == who.size());
      }

      -- board[w];
    
      // To make sure we keep the uniqueness invariant,
      // might be costly if not very sparse?
      if (board[w] == T()) {
        size_type i = 0;
        while (who[i] != w)
          ++i;
        std::swap(who[i], who[who.size()-1]);
        who.pop_back();
      }
    }
void LLKeywords::insertSegment(std::vector<LLTextSegmentPtr>& seg_list, LLTextSegmentPtr new_segment, S32 text_len, const LLColor4 &defaultColor )
{
	LLTextSegmentPtr last = seg_list.back();
	S32 new_seg_end = new_segment->getEnd();
	llassert(new_seg_end <= text_len);

	if( new_segment->getStart() == last->getStart() )
	{
		seg_list.pop_back();
	}
	else
	{
		last->setEnd( new_segment->getStart() );
	}
	seg_list.push_back( new_segment );

	if( new_seg_end < text_len )
	{
		seg_list.push_back( new LLTextSegment( defaultColor, new_seg_end, text_len ) );
	}
}
Exemple #14
0
		void popControlStack(bool isElse = false)
		{
			VALIDATE_UNLESS("stack was not empty at end of control structure: ",stack.size() > controlStack.back().outerStackSize);

			if(isElse && controlStack.back().type == ControlContext::Type::ifThen)
			{
				controlStack.back().type = ControlContext::Type::ifElse;
				controlStack.back().isReachable = true;
			}
			else
			{
				VALIDATE_UNLESS("else only allowed in if context: ",isElse);
				const ResultType resultType = controlStack.back().resultType;
				if(controlStack.back().type == ControlContext::Type::ifThen && resultType != ResultType::none)
				{
					throw ValidationException("else-less if may not yield a result");
				}
				controlStack.pop_back();
				if(controlStack.size()) { pushOperand(resultType); }
			}
		}
void LightWeightStaticOrderMCS::ProcessOrderAfterRecursion(std::vector<int> &vVertexOrder, std::vector<int> &P, std::vector<int> &vColors, int const chosenVertex)
{
    if (chosenVertex == -1) return;
#if 1
    vVertexOrder.erase(find(vVertexOrder.begin(), vVertexOrder.end(), chosenVertex));
#else
    // try searching from end, might be faster in general...
    size_t indexAfterVertex(0);
    for (indexAfterVertex = vVertexOrder.size(); indexAfterVertex >= 1; indexAfterVertex--) {
        if (vVertexOrder[indexAfterVertex-1] == chosenVertex) {
            break;
        }
    }

    for (; indexAfterVertex < vVertexOrder.size(); indexAfterVertex++) {
        vVertexOrder[indexAfterVertex-1] = vVertexOrder[indexAfterVertex];
    }
    vVertexOrder.pop_back();
#endif // 0
    R.pop_back();
}
Exemple #16
0
bool prev_vector_by_left_first( std::vector< T >& iv,
				T fst, T lst ) {
  std::vector< T > v_tmp;
  while ( !iv.empty() ) {
    if ( iv.back() > fst ) {
      iv.back()--;
      while ( !v_tmp.empty() ) {
	v_tmp.pop_back();
	iv.push_back( lst );
      }
      return true;
    }
    v_tmp.push_back( iv.back() );
    iv.pop_back();
  }
  while ( !v_tmp.empty() ) {
    iv.push_back( v_tmp.back() );
    v_tmp.pop_back();
  }
  return false;
}
Exemple #17
0
void R53(std::vector<Dynamic>& __ret) {
	//arguments
 Dynamic  hllr__7 =  Dynamic (__ret.back()); __ret.pop_back();
Dynamic hllr__6 = __ret.back(); __ret.pop_back();
 Dynamic  hllr__5 =  Dynamic (__ret.back()); __ret.pop_back();
Dynamic hllr__4 = __ret.back(); __ret.pop_back();
 Dynamic  hllr__3 =  Dynamic (__ret.back()); __ret.pop_back();
Dynamic hllr__2 = __ret.back(); __ret.pop_back();
 Dynamic  hllr__1 =  Dynamic (__ret.back()); __ret.pop_back();
 Dynamic  hllr__0 =  Dynamic (__ret.back()); __ret.pop_back();
	 Dynamic  retval;

        States& pre = (States&) hllr__1;
        ptr<State> x = pre.back(); pre.pop_back();
        int name = ptr<StateSymbol>(x)->data;
        retval = StateDefine(dMacro(sLocal,pre,name,(std::vector</*Symbol*/int>&)hllr__3, (States&)hllr__5));
    
	__ret.push_back(retval);
}
/*
 *****************************************************************************
 * The main function
 */
void changehome( bool to, bool linuxhome = true )
{
    static std::vector< std::string >paths;
    if (to) {
        char mycurpath[8192];
        getcwd( mycurpath, 8191 );
        mycurpath[8191] = '\0';
        paths.push_back( std::string( mycurpath ) );
#ifndef _WIN32
        if (linuxhome) {
            struct passwd *pwent;
            pwent = getpwuid( getuid() );
            chdir( pwent->pw_dir );
        }
#endif
        chdir( ".vegastrike" );
    } else if ( !paths.empty() ) {
        chdir( paths.back().c_str() );
        paths.pop_back();
    }
}
Exemple #19
0
/*!
 * Algorithm Tarjan to find strongly connected components
 */
void tarjan(NodePtr x){
  
  x->_index = INDEX;
  x->_llink = INDEX;
  STACK.push_back(x); // put into STACK
  x->_isStack = true; // put into STACK


  ++INDEX;

  for (std::vector<NodePtr>::iterator i = NodeVec.begin(); 
       i != NodeVec.end(); ++i){

    NodePtr node = *i;
    
    if (!graph[x->_id][node->_id]) continue;
   
    if (node->_index <0){
      tarjan(node);
      x->_llink = std::min(x->_llink,node->_llink);
    }else if(node->_isStack){
      x->_llink = std::min(x->_llink,node->_index);
    }   
  
  }
    
  if (x->_index == x->_llink){
    while(true){
      NodePtr node = STACK.back();
      STACK.pop_back();
      node->_isStack = false;
      node->_group = GROUP;
      if (node->_id == x->_id){
	++GROUP;
	break;
      }
    }
  }

}
Exemple #20
0
void ModelNode_Witcher::evaluateTextures(int n, std::vector<Common::UString> &textures,
		const Common::UString *staticTextures, const uint32 *tVertsCount,
		bool lightMapDayNight, const Common::UString &lightMapName) {

	textures.resize(n);

	for (int t = 0; t < n; t++) {
		if (textures[t].empty() && staticTextures)
			textures[t] = staticTextures[t];

		if (tVertsCount[t] == 0)
			textures[t].clear();

		if (textures[t].empty())
			continue;

		if (lightMapDayNight && (textures[t] == lightMapName)) {
			// Day (dzień)
			if      (ResMan.hasResource(textures[t] + "!d", ::Aurora::kResourceImage))
				textures[t] += "!d";
			// Morning (rano)
			else if (ResMan.hasResource(textures[t] + "!r", ::Aurora::kResourceImage))
				textures[t] += "!r";
			// Noon (południe)
			else if (ResMan.hasResource(textures[t] + "!p", ::Aurora::kResourceImage))
				textures[t] += "!p";
			// Evening (wieczór)
			else if (ResMan.hasResource(textures[t] + "!w", ::Aurora::kResourceImage))
				textures[t] += "!w";
			// Night (noc)
			else if (ResMan.hasResource(textures[t] + "!n", ::Aurora::kResourceImage))
				textures[t] += "!n";
			else
				textures[t].clear();
		}
	}

	while (!textures.empty() && textures.back().empty())
		textures.pop_back();
}
Exemple #21
0
void audio_update (const Vector3& position, const Vector3& velocity, const Quaternion& rotation)
{
    ALfloat pos[] = { position.x, position.y, position.z };
    ALfloat vel[] = { velocity.x, velocity.y, velocity.z };
    ALfloat zeros[] = { 0.0f, 0.0f, 0.0f };

    Vector3 at = rotation * Vector3(0.0f, 1.0f, 0.0f);
    Vector3 up = rotation * Vector3(0.0f, 0.0f, 1.0f);

    ALfloat ori[] = { at.x, at.y, at.z, up.x, up.y, up.z };

    alcSuspendContext(alContext);
    alListenerfv(AL_POSITION, pos);
    alListenerfv(AL_VELOCITY, audio_option(AUDIO_DOPPLER_ENABLED) ? vel : zeros);
    alListenerfv(AL_ORIENTATION, ori);
    float volume = audio_option(AUDIO_MUTE) ? 0 : audio_option(AUDIO_MASTER_VOLUME);
    alListenerfv(AL_GAIN, &volume);
    alcProcessContext(alContext);

    // destroy any one-shot sounds that finished playing
    // NOTE: this won't account for cases where there's still a sound playing when the game exits

    for (unsigned i=0 ; i<one_shot_sounds.size() ; ++i) {
        OneShotSound &oss = one_shot_sounds[i];
        ALuint &src = oss.sound;

        ALint playing;
        alGetSourcei(src, AL_SOURCE_STATE, &playing);

        if (playing != AL_PLAYING) {

            alDeleteSources(1, &src);

            one_shot_sounds[i] = one_shot_sounds[one_shot_sounds.size()-1];
            one_shot_sounds.pop_back();
            i--; // re-examine index i again, next iteration

        }
    }
}
Exemple #22
0
static bool ApplyPathStringToComponentsVector(std::vector<std::string> &vector, const std::string &pathString)
{
	size_t len = pathString.length();
	size_t start = 0;

	while (start < len)
	{
		size_t i = pathString.find('/', start);
		if (i == std::string::npos)
			i = len;

		if (i > start)
		{
			std::string component = pathString.substr(start, i - start);
			if (component != ".")
			{
				if (component == "..")
				{
					if (vector.size() != 0)
					{
						vector.pop_back();
					}
					else
					{
						// The PSP silently ignores attempts to .. to parent of root directory
						WARN_LOG(HLE, "RealPath: ignoring .. beyond root - root directory is its own parent: \"%s\"", pathString.c_str());
					}
				}
				else
				{
					vector.push_back(component);
				}
			}
		}

		start = i + 1;
	}

	return true;
}
Exemple #23
0
void Template::commitElement(Element *_element, std::vector<Element*> &stack_elem)
{
	if ( _element )
	{
		if ( ! m_branching )
			m_elem->m_next = _element;
		else
			m_elem->m_branch = _element;

		m_elem = _element;

		m_branching = ((Element::Type::IF == m_elem->m_type) || (Element::Type::FOREACH == m_elem->m_type));
		if ( m_branching )
			stack_elem.push_back( m_elem );
	}
	else {
		if ( stack_elem.size() ) {
			m_elem = stack_elem.back();
			stack_elem.pop_back();
		}
	}
}
Exemple #24
0
void run(std::vector<int>& primes, std::vector<int>& vec, int depth, int& max, int sum)
{
	if (depth == 5) {
		max = sum;
		return;
	}
	if (max != 0 && max <= sum)
		return;

	for (size_t i = vec[depth-1]+1; i < primes.size(); ++i) {
		int j = 0;
		for (j = 0; j < depth; ++j) {
			if (isPrimePair(primes[vec[j]], primes[i]) == false)
				break;
		}
		if (j == depth) {
			vec.push_back(i);
			run(primes, vec, depth+1, max, sum + primes[i]);
			vec.pop_back();
		}
	}
}
Exemple #25
0
  static T* get_instance()
  {
    while(1)
    {
      while(1)
      {
        boost::mutex::scoped_lock llock(lock);
        {/** 锁作用域 */
          if( arr.empty() )
          {
            break;
          }

          T* ret = *arr.rbegin();
          arr.pop_back();
          return ret;
        }/** 锁作用域 */
      }
      mo_semls.wait();
    }
    
  }
  void SequenceAnalyzer::keepOnlyCorrectMatches(
    std::vector<TrackOfPoints>& tracks,
    unsigned int min_matches, unsigned int min_consistance )
  {
    unsigned int tracks_size = tracks.size( );
    unsigned int index=0;

    while ( index < tracks_size )
    {
      if( ( tracks[ index ].getNbTrack( ) < min_matches ) ||
        ( tracks[ index ].track_consistance < (int)min_consistance ) )
      {
        //problem with this track, too small to be consistent
        // or inconsistant...
        tracks_size--;
        tracks[ index ]=tracks[ tracks_size ];
        tracks.pop_back( );
        index--;
      }
      index++;
    }
  }
Exemple #27
0
void Advance()
{
    MoveEvents();

    int cyclesExecuted = g_slice_length - DowncountToCycles(PowerPC::ppcState.downcount);
    g_global_timer += cyclesExecuted;
    s_last_OC_factor = SConfig::GetInstance().m_OCEnable ? SConfig::GetInstance().m_OCFactor : 1.0f;
    g_last_OC_factor_inverted = 1.0f / s_last_OC_factor;
    g_slice_length = MAX_SLICE_LENGTH;

    s_is_global_timer_sane = true;

    while (!s_event_queue.empty() && s_event_queue.front().time <= g_global_timer)
    {
        Event evt = std::move(s_event_queue.front());
        std::pop_heap(s_event_queue.begin(), s_event_queue.end(), std::greater<Event>());
        s_event_queue.pop_back();
        // NOTICE_LOG(POWERPC, "[Scheduler] %-20s (%lld, %lld)", evt.type->name->c_str(),
        //            g_global_timer, evt.time);
        evt.type->callback(evt.userdata, g_global_timer - evt.time);
    }

    s_is_global_timer_sane = false;

    // Still events left (scheduled in the future)
    if (!s_event_queue.empty())
    {
        g_slice_length = static_cast<int>(
                             std::min<s64>(s_event_queue.front().time - g_global_timer, MAX_SLICE_LENGTH));
    }

    PowerPC::ppcState.downcount = CyclesToDowncount(g_slice_length);

    // Check for any external exceptions.
    // It's important to do this after processing events otherwise any exceptions will be delayed
    // until the next slice:
    //        Pokemon Box refuses to boot if the first exception from the audio DMA is received late
    PowerPC::CheckExternalExceptions();
}
    void popControlStack(bool isElse = false)
    {
        if(controlStack.back().isReachable)
        {
            VALIDATE_UNLESS("stack was not empty at end of control structure: ",stack.size() > controlStack.back().outerStackSize);
        }

        if(isElse && controlStack.back().type == ControlContext::Type::ifThen)
        {
            controlStack.back().type = ControlContext::Type::ifElse;
            controlStack.back().isReachable = true;
        }
        else
        {
            VALIDATE_UNLESS("else only allowed in if context: ",isElse);
            const ResultType resultType = controlStack.back().resultType;
            controlStack.pop_back();
            if(controlStack.size()) {
                push(resultType);
            }
        }
    }
bool CallGraphCFG::findBBPath(CallGraphNode *n, std::vector<BasicBlock*> &path, std::string srcFile, int srcLine)
{
    if (n == NULL) return false;

    Function *F = n->getFunction();

    std::cerr << "Processing " << F->getNameStr() << "\n";

    // Are we on a leaf?
    if (n->size() == 0) {
        BasicBlock *bb=NULL;
        if (findLineInFunction(F,&bb,srcFile,srcLine)) {
            path.push_back(bb);
            return true;
        }
    }

    for (CallGraphNode::iterator it = n->begin(); it != n->end(); ++it) {
        CallSite cs = it->first;
        CallGraphNode *tCGN = it->second;
        Instruction *tI = cs.getInstruction();
        if (tI == NULL) return false;
        BasicBlock *bb = tI->getParent();
        Function *tF = tCGN->getFunction();

        path.push_back(bb);
        if (findLineInBB(bb,srcFile,srcLine))
            return true;

        if (tF != F) {    // Dont get stuck in recursion
            if (findBBPath(tCGN,path,srcFile,srcLine))
                return true;
        }

        std::cerr << " Dead end, reverting...\n";  // FIX: This is misleading, not really correct.
        path.pop_back();
    }
    return false;
}
Exemple #30
0
CValue::~CValue()
/*
pre:
effect: deletes the object
*/
{
	ClearProperties();

	assertd (m_refcount==0);
#ifdef CVALUE_DEBUG
	std::vector<SmartCValueRef>::iterator it;
	for (it=gRefList.begin(); it!=gRefList.end(); it++)
	{
		if (it->m_ref == this)
		{
			*it = gRefList.back();
			gRefList.pop_back();
			break;
		}
	}
#endif
}