本文整理汇总了C++中PQ::remove方法的典型用法代码示例。如果您正苦于以下问题:C++ PQ::remove方法的具体用法?C++ PQ::remove怎么用?C++ PQ::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PQ
的用法示例。
在下文中一共展示了PQ::remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sanityCheck
static bool sanityCheck()
{
PQ set;
uint32_t seed = 0;
for (uint32_t i = 0; i < INIT_SIZE; i++) {
int key = rand_r_32(&seed) % KEY_RANGE;
set.add(key);
}
bench_begin = false;
bench_stop = false;
thread * thrs[NUM_THREADS];
sanity_thread_arg_t args[NUM_THREADS];
for (uint32_t j = 0; j < NUM_THREADS; j++) {
sanity_thread_arg_t & arg = args[j];
arg.tid = j + 1;
arg.set = &set;
arg.ops = 0;
thrs[j] = new thread(sanityThread<PQ>, &arg);
}
// broadcast begin signal
bench_begin = true;
sleep(DURATION);
bench_stop = true;
for (uint32_t j = 0; j < NUM_THREADS; j++) thrs[j]->join();
uint32_t old = 0;
for (uint32_t i = 0; i < INIT_SIZE; i++) {
uint32_t num = set.remove();
if (old > num) {
cout << "error: heap invariant violated: "
<< "prev = " << old << " "
<< "curr = " << num << endl;
return false;
}
if (num == PQ_VAL_MAX) {
cout << "error: missing element(not linearizable)" << endl;
return false;
}
old = num;
}
uint32_t num = set.remove();
if (num != PQ_VAL_MAX) {
cout << "error: extra element(not linearizable)" << endl;
return false;
}
cout << "Sanity check: okay." << endl;
return true;
}
示例2: benchOpsThread
void benchOpsThread(bench_ops_thread_arg_t * arg)
{
wbmm_thread_init(arg->tid);
uint32_t seed1 = arg->tid;
uint32_t seed2 = seed1 + 1;
uint64_t ops = 0;
PQ * set = (PQ *)arg->set;
while (!bench_begin);
while (!bench_stop) {
int op = rand_r_32(&seed1) % 100;
int key = rand_r_32(&seed2) % KEY_RANGE;
if (op < 50) {
set->add(key);
}
else {
key = set->remove();
}
for (int i = 0; i < DELAY; i++) spin64();
ops++;
}
arg->ops = ops;
}
示例3: sanityThread
void sanityThread(sanity_thread_arg_t * arg)
{
wbmm_thread_init(arg->tid);
uint32_t seed1 = arg->tid;
uint32_t seed2 = seed1 + 1;
uint64_t ops = 0;
PQ * set = (PQ *)arg->set;
while (!bench_begin);
while (!bench_stop) {
int key = rand_r_32(&seed2) % KEY_RANGE;
set->add(key);
key = set->remove();
ops++;
}
arg->ops = ops;
}
示例4: sanityCheckSequential
bool sanityCheckSequential()
{
const int max = 10000;
std::priority_queue<int32_t, vector<int32_t>, pqcompare> contrast;
PQ m;
uint32_t seed = 0;
for (int i = 0; i < max; i++) {
int32_t temp = rand_r_32(&seed) % KEY_RANGE;
contrast.push(temp);
m.add(temp);
}
for (int i = 0; i < max - 1; i++) {
uint32_t r1 = m.remove();
uint32_t r2 = contrast.empty() ? PQ_VAL_MAX : contrast.top();
if (!contrast.empty()) contrast.pop();
if (r1 != r2) {
cout << "different element at index " << i << ":"
<< r1 << " " << r2 << endl;
return false;
}
}
cout << "Sanity check: okay." << endl;
return true;
}