本文整理汇总了C++中PriorityQueue::getMin方法的典型用法代码示例。如果您正苦于以下问题:C++ PriorityQueue::getMin方法的具体用法?C++ PriorityQueue::getMin怎么用?C++ PriorityQueue::getMin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue::getMin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNext
std::shared_ptr<T> getNext()
{
while(true)
{
std::unique_lock<std::mutex> lock(mutex);
condition.wait(lock, [this]() -> bool
{
return !queue.empty() || isClosed;
});
lock.unlock();
if (!queue.empty())
{
auto ptr = queue.getMin();
if (ptr)
{
return ptr;
}
}
if (isClosed)
{
break;
}
}
return std::shared_ptr<T>();
}
示例2: queue_test
void queue_test()
{
std::cout << "starting queue test" << std::endl;
PriorityQueue<int> queue;
const int OPERATIONS_PER_THREAD = 500;
const int THREADS_COUNT = 20;
auto filler = [&]()
{
for (size_t index = 0; index < OPERATIONS_PER_THREAD; ++index)
{
queue.add(index, index);
}
};
auto getter = [&]()
{
for (size_t index = 0; index < OPERATIONS_PER_THREAD; ++index)
{
queue.getMin();
}
};
auto worker = [=](std::function<void()> func)
{
std::vector<boost::thread> threads;
for (size_t index = 0; index < THREADS_COUNT; ++index)
{
threads.emplace_back(func);
}
for (auto & it : threads)
{
it.join();
}
};
std::cout << "start filling" << std::endl;
worker(filler);
std::cout << "size after filling: " << queue.size() << std::endl;
std::cout << "start getting" << std::endl;
worker(getter);
std::cout << "size after getting: " << queue.size() << std::endl;
std::cout << "done" << std::endl;
assert(queue.empty());
}