当前位置: 首页>>代码示例>>C++>>正文


C++ priority_queue::empty方法代码示例

本文整理汇总了C++中std::priority_queue::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ priority_queue::empty方法的具体用法?C++ priority_queue::empty怎么用?C++ priority_queue::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::priority_queue的用法示例。


在下文中一共展示了priority_queue::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: scheduler_loop

 // this 
 inline void scheduler_loop() {
     std::unique_ptr<Priority> pCurrentPrty;
     for (;;) {
         std::unique_lock<std::mutex> lock(queue_mutex);
         // wait for some task to get queued or for the atomic 
         // isActive flag to become inactive
         condition.wait(lock, [this, &pCurrentPrty] {
             if (!mTasks.empty() && 
                 pCurrentPrty && pCurrentPrty->getPriorityStr() != 
                 mTasks.top().getPriority().getPriorityStr() && 
                 pCurrentPrty->getPriorityStr().length() != 
                 mTasks.top().getPriority().getPriorityStr().length()) {
                 std::cout << "priority change" << std::endl;
             }
             return (!mTasks.empty() || !isActive.load());
         });
         // only exit when no more tasks on the queue
         if (!isActive.load() && mTasks.empty()) {
             return;
         }
         // update the top priority job that is currently running
         pCurrentPrty = std::make_unique<Priority>(mTasks.top().getPriority());
         // move next task off the priority queue
         auto nextTask(std::move(mTasks.top()));
         pCurrentPrty = std::make_unique<Priority>(nextTask.getPriority());
         // queue housekeeping
         mTasks.pop();
         // release the lock allowing new entries to be queued
         lock.unlock();
         // execute the task forwarding stored arguments with the call
         // this is the magic that works inside a thread pool
         // _Ret operator()(_Types... _Args) const 
         nextTask();
     }
 }
开发者ID:CCJY,项目名称:coliru,代码行数:36,代码来源:main.cpp

示例2: main

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &a, &b, &t);
        adj[a].push_back(std::make_pair(b, t));
        adj[b].push_back(std::make_pair(a, t));
    }
    
    dist[0] = 0;
    q.push(std::make_pair(0, 0));
    for (int i = 1; i < n; i++) {
        dist[i] = 0x3f3f3f3f;
        q.push(std::make_pair(-dist[i], i));
    }
    
    while (!q.empty()) {
        std::tie(cur_dist, cur_index) = q.top(); q.pop();
        cur_dist *= -1;
        vis[cur_index] = 1;
        for (std::pair<int, int> p : adj[cur_index]) {
            if (!vis[p.first]) {
                const int alt = cur_dist + p.second;
                if (alt < dist[p.first]) {
                    dist[p.first] = alt;
                    q.push(std::make_pair(-alt, p.first));
                }
            }
        }
    }

    dist2[0] = 0;
    q.push(std::make_pair(0, n - 1));
    for (int i = 0; i < n - 1; i++) {
        dist2[i] = 0x3f3f3f3f;
        q.push(std::make_pair(-dist2[i], i));
    }

    while (!q.empty()) {
        std::tie(cur_dist, cur_index) = q.top(); q.pop();
        cur_dist *= -1;
        vis2[cur_index] = 1;
        for (std::pair<int, int> p : adj[cur_index]) {
            if (!vis2[p.first]) {
                const int alt = cur_dist + p.second;
                if (alt < dist2[p.first]) {
                    dist2[p.first] = alt;
                    q.push(std::make_pair(-alt, p.first));
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        ans = std::max(ans, dist[i] + dist2[i]);
    }
    printf("%d\n", ans);
}
开发者ID:nathanlo99,项目名称:dmoj_archive,代码行数:57,代码来源:vmss7wc15c4p3.cpp

示例3: while

// preferences should be a member
wns::scheduler::ConnectionID
ProportionalFair::getNextConnection(SchedulerStatePtr schedulerState,
                                    std::priority_queue<UserPreference> preferences)
{
    wns::scheduler::ConnectionID next = -1;

    while (!preferences.empty())
    {
        int priority = schedulerState->currentState->getCurrentPriority();
        const float preference = preferences.top().first;
        const UserID user = preferences.top().second;
        MESSAGE_SINGLE(NORMAL, logger, "Selected user="<<user.getName());

        ConnectionVector currentPrioConns = getConnectionsForPrio(priority, user);

        if(!currentPrioConns.empty())
        {
            next = getRandomConnection(currentPrioConns);
            MESSAGE_SINGLE(NORMAL, logger, "Selected connection with CID="<<next);
            return next;
        }
        preferences.pop();
    }
    return next;
}
开发者ID:freiheitsnetz,项目名称:openwns-library,代码行数:26,代码来源:ProportionalFair.cpp

示例4: rankImages

void DifferenceCut::rankImages (std::vector<RowSpan>& spans, std::priority_queue<Ranker>& ordered) {
  assert(ordered.empty());
  float score, dist;
  const unsigned char *Itest, *Iavoid;
  Vec3i Vtest, Vavoid;
  int x, y, index;

  for (unsigned int i=0; i<_images.size(); ++i) {
    score = 0;
    ImageAbs* im = _images[i];
    for (unsigned int j=0; j<spans.size(); ++j) {
      x = spans[j]._x; y = spans[j]._y;
      for (int s=0; s<spans[j]._num; ++s) {
	index = y*_w + x + s;
	Itest = im->data(x+s,y);
	Iavoid = _imptr(_labels[index], Coord(x+s,y));
	Vtest.Set(Itest[0], Itest[1], Itest[2]);
	Vavoid.Set(Iavoid[0], Iavoid[1], Iavoid[2]);
	dist = sqrt(Vtest.distanceTo2(Vavoid));
	//printf("%f\n",dist);
	if (dist > 25)
	  score += 25.;
	else
	  score += dist;
      }
    }
    printf("Image %d, score %f\n",i, score);
    ordered.push(Ranker(i,score));
  }
}
开发者ID:kobeyuan,项目名称:ImageMerge,代码行数:30,代码来源:differenceCut.cpp

示例5: main

int main(void)
{
	scanf("%u %u", &words, &maxLength);
	for(unsigned int w = 0; w < words; ++ w)
	{
		scanf("%s", word);
		sWord[w] = std::string(word);
		que.push(sWord[w]);
	}

	while(!que.empty() && que.top().length() <= maxLength)
	{
		act = que.top();
		que.pop();
		if(isPalindrome(act))
		{
			++ result;
			if(result == 835454957)
				result = 0;
		}

		for(unsigned int w = 0; w < words; ++ w)
			que.push(act + " " + sWord[w]);
	}

	printf("%u\n", result);


	return 0;
}
开发者ID:Neverous,项目名称:xivlo08-11,代码行数:30,代码来源:zliczpal0.cpp

示例6:

PLUGIN_EXPORT int PLUGIN_CALL
	AmxUnload(AMX * amx) 
{
	std::priority_queue<struct timer_s *, std::deque<struct timer_s *>, TimerCompare>
		cleaned;
	// Destroy all the timers for this mode.
	while (!gTimers.empty())
	{
		struct timer_s *
			next = gTimers.top();
		gTimers.pop();
		if (next->amx == amx)
		{
			// Ending, remove from the map also.
			gHandles.erase(next->id);
		}
		else
		{
			// Not ending, leave it be.
			cleaned.push(next);
		}
	}
	gTimers = cleaned;
	for (int i = 0; i != 17; ++i)
	{
		if (gAMXFiles[i] == amx)
		{
			gAMXFiles[i] = 0;
			break;
		}
	}
	return AMX_ERR_NONE;
}
开发者ID:Open-GTO,项目名称:Fixes2,代码行数:33,代码来源:fixes.cpp

示例7: readAlignment

			/**
			 * decode next alignment
			 *
			 * @param algn reference to alignment object to be filled
			 * @return true iff next alignment could be read, false when no more alignments are available
			 **/
			bool readAlignment(libmaus::bambam::BamAlignment & algn)
			{
				if ( Q.empty() )
					return false;
				
				uint64_t const t = Q.top();
				Q.pop();
				
				libmaus::bambam::BamAlignment::D_array_type T = algn.D;
				
				algn.D = data[t].D;
				algn.blocksize = data[t].blocksize;
				
				data[t].D = T;
				data[t].blocksize = 0;
				
				if ( index[t].second-- )
				{
					#if !defined(NDEBUG)
					bool const alok = 
					#endif
					        libmaus::bambam::BamDecoder::readAlignmentGz(*(streams[t]),data[t],0,false);
					        
					#if !defined(NDEBUG)
					assert ( alok );
					#endif
					
					Q.push(t);
				}
					
				return true;
			}
开发者ID:allenday,项目名称:libmaus,代码行数:38,代码来源:SnappyAlignmentMergeInput.hpp

示例8: dijkstra

void dijkstra() {
	std::fill(d + 1, d + n + 1, INF);
	for (int i = 1; i <= n; i++) {
		if (!w[i]) continue;
		heap.push((Heapnode){d[i] = 0, i});
	}
	while (!heap.empty()) {
		Heapnode top = heap.top(); heap.pop();
		if (v[top.node]) continue;
		v[top.node] = true;
		for (int i = h[top.node]; i; i = e[i].next)
			if (!v[e[i].node] && d[e[i].node] > top.dist + e[i].dist) {
				d[e[i].node] = top.dist + e[i].dist;
				p[e[i].node] = top.node;
				heap.push((Heapnode){d[e[i].node], e[i].node});
			}
	}
	s = 0;
	for (int i = 1, cnt = 0; i <= n; i++) {
		if (!w[i]) continue;
		c[i] = ++s;
	}
	for (int i = 1; i <= n; i++) {
		if (w[i]) continue;
		fa[getfa(i)] = getfa(p[i]);
	}
	for (int i = 1; i <= n; i++) {
		if (w[i]) continue;
		c[i] = c[getfa(i)];
	}
}
开发者ID:PrayStarJirachi,项目名称:Exercise-Code,代码行数:31,代码来源:B.cpp

示例9: pop

	Node::Ptr pop() {
		if (queue.empty())
			return Node::Ptr();
		Node::Ptr result = queue.top();
		queue.pop();
		return result;
	}
开发者ID:martong,项目名称:nng2014,代码行数:7,代码来源:PrioNodeQueue.hpp

示例10: main

int main() {
	freopen("F.in", "r", stdin);
	while (scanf("%d%d", &n, &m) == 2 && n && m) {
		for (int i = 1; i <= n; i++) {
			scanf("%s", map[i] + 1);
		}
		scanf("%d%d", &sx, &sy);
		scanf("%d%d", &ex, &ey);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++) {
				v[i][j] = false;
				d[i][j] = INF;
			}
		heap.push(std::make_pair(d[sx][sy] = 0, std::make_pair(sx, sy)));
		while (!heap.empty()) {
			std::pair<int, std::pair<int, int> > top = heap.top(); heap.pop();
			if (v[top.second.first][top.second.second]) continue;
			v[top.second.first][top.second.second] = true;
			for (int dir = 0; dir < 4; dir++) {
				int nx = top.second.first + dx[dir];
				int ny = top.second.second + dy[dir];
				if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
				int cost = map[nx][ny] == '.';
				if (!v[nx][ny] && d[nx][ny] > d[top.second.first][top.second.second] + cost) {
					d[nx][ny] = d[top.second.first][top.second.second] + cost;
					heap.push(std::make_pair(d[nx][ny], std::make_pair(nx, ny)));
				}
			}
		}
		printf("%d\n", d[ex][ey]);
	}
	return 0;
}
开发者ID:PrayStarJirachi,项目名称:Exercise-Code,代码行数:33,代码来源:F.cpp

示例11: peek

	Node::Ptr peek() const
	{
		if (queue.empty())
			return Node::Ptr();
		Node::Ptr result = queue.top();
		return result;
	}
开发者ID:martong,项目名称:nng2014,代码行数:7,代码来源:PrioNodeQueue.hpp

示例12:

 void operator<<(std::priority_queue<_Tp,Range,Compare> lhs)
 {
         for(;!lhs.empty();){
                 std::cout<<lhs.top()<<token;
                 lhs.pop();
         }
         std::cout<<last_token<<std::flush;
 }
开发者ID:falgon,项目名称:miko-lib,代码行数:8,代码来源:rall_cout.hpp

示例13: pushPriorityQueueBounded

//Maintains the size of the priority queue at the specified size with each push
//For now this function is for priority queue that is in ascending order, top is smallest.
void pushPriorityQueueBounded(std::priority_queue<int, std::vector<int>, std::greater<int> >  &pq,
                              int newElement, unsigned long priorityQueueBound)
{
   if(pq.empty() || newElement > pq.top())
      pq.push(newElement);
   if(pq.size() > priorityQueueBound)
      pq.pop();
}
开发者ID:thekingtat,项目名称:largest-n-integers,代码行数:10,代码来源:LargestMIntegersVS.cpp

示例14: main

int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int i;
		int flag1=1,flag2=1,flag3=1;
		while(!ty1.empty())ty1.pop();
		while(!ty2.empty())ty2.pop();
		while(!ty3.empty())ty3.pop();
		int order,x;
		for(i=1;i<=n;i++){
			scanf("%d%d",&order,&x);
			if(order==1){
				ty3.push(x);
				ty2.push(x);
				ty1.push(x);
				}
			else {
				if(flag3&&!ty3.empty()){
					if(ty3.top()==x)ty3.pop();
					else flag3=0;
					}
				else flag3=0;
				
				if(flag2&&!ty2.empty()){
					if(ty2.top()==x)ty2.pop();
					else flag2=0;
					}
				else flag2=0;
				
				if(flag1&&!ty1.empty()){
					if(ty1.front()==x)ty1.pop();
					else flag1=0;
					}
				else flag1=0;
				}
			}
		int sum=flag1+flag2+flag3;
		if(sum>=2)printf("not sure\n");
		else if(sum==0)printf("impossible\n");
		else if(flag1)printf("queue\n");
		else if(flag2)printf("priority queue\n");
		else printf("stack\n"); 
		}
	return 0;
	}
开发者ID:JintianGo,项目名称:Training,代码行数:45,代码来源:11995+-+I+Can+Guess+the+Data+Structure.cpp

示例15: NextTime

double NextTime()
{
    //std::lock_guard<std::mutex> lock(MUTEX);
    if( QUEUE.empty() ) {
        return 0;
    } else {
        return QUEUE.top();
    }
}
开发者ID:Algomorph,项目名称:HAL,代码行数:9,代码来源:DeviceTime.cpp


注:本文中的std::priority_queue::empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。