本文整理汇总了C++中Queue::RemoveTail方法的典型用法代码示例。如果您正苦于以下问题:C++ Queue::RemoveTail方法的具体用法?C++ Queue::RemoveTail怎么用?C++ Queue::RemoveTail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::RemoveTail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InternalThreadEntry
virtual void InternalThreadEntry()
{
char buf[128]; muscleSprintf(buf, "TestThread-%p", this);
const String prefix = buf;
Queue<TestItemRef> q;
bool keepGoing = 1;
uint32 counter = 0;
while(keepGoing)
{
uint32 x = rand() % 10000;
while(q.GetNumItems() < x)
{
TestItemRef tRef(_pool.ObtainObject());
if (tRef())
{
char buf[128]; muscleSprintf(buf, "-" UINT32_FORMAT_SPEC, ++counter);
tRef()->SetName(prefix+buf);
q.AddTail(tRef);
}
else WARN_OUT_OF_MEMORY;
}
while(q.GetNumItems() > x) q.RemoveTail();
// Check to make sure no other threads are overwriting our objects
for (uint32 i=0; i<q.GetNumItems(); i++)
{
if (q[i]()->GetName().StartsWith(prefix) == false)
{
printf("ERROR, thread %p expected prefix [%s], saw [%s] at position " INT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, prefix(), q[i]()->GetName()(), i, q.GetNumItems());
ExitWithoutCleanup(10);
}
}
// Check to see if the main thread wants us to exit yet
MessageRef r;
while(WaitForNextMessageFromOwner(r, 0) >= 0) if (r() == NULL) keepGoing = false;
}
}
示例2: main
//.........这里部分代码省略.........
const uint32 NUM_RUNS = 3;
Queue<String> q; (void) q.EnsureSize(NUM_ITEMS, true);
double tally = 0.0;
for (uint32 t=0; t<NUM_RUNS; t++)
{
printf("STRING SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC"/" UINT32_FORMAT_SPEC":\n", t+1, NUM_RUNS);
srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) q[i] = String("FooBarBaz-%1").Arg(rand()).Pad(500); // we want this to be repeatable, hence srand(0)
uint64 startTime = GetRunTime64();
q.Sort();
uint64 elapsed = (GetRunTime64()-startTime);
double itemsPerSecond = ((double)NUM_ITEMS*((double)MICROS_PER_SECOND))/(elapsed);
printf(" It took " UINT64_FORMAT_SPEC" microseconds to sort " UINT32_FORMAT_SPEC" items, so we sorted %f items per second\n", elapsed, NUM_ITEMS, itemsPerSecond);
tally += itemsPerSecond;
}
printf("STRING GRAND AVERAGE ITEMS PER SECOND WAS %f items per second\n", tally/NUM_RUNS);
}
PrintAndClearStringCopyCounts("After String Sort Tests");
printf("REVERSE TEST\n");
{
q.Clear();
for (int i=0; i<testSize; i++) TEST(q.AddTail(i));
q.ReverseItemOrdering();
for (int j=0; j<testSize; j++) printf("After reverse, %i->%i\n", j, q[j]);
}
printf("CONCAT TEST 1\n");
{
q.Clear();
Queue<int> q2;
for (int i=0; i<testSize; i++)
{
TEST(q.AddTail(i));
TEST(q2.AddTail(i+100));
}
q.AddTailMulti(q2);
for (uint32 j=0; j<q.GetNumItems(); j++) printf("After concat, " UINT32_FORMAT_SPEC"->%i\n", j, q[j]);
}
printf("CONCAT TEST 2\n");
{
q.Clear();
Queue<int> q2;
for (int i=0; i<testSize; i++)
{
TEST(q.AddTail(i));
TEST(q2.AddTail(i+100));
}
q.AddHeadMulti(q2);
for (uint32 j=0; j<q.GetNumItems(); j++) printf("After concat, " UINT32_FORMAT_SPEC"->%i\n", j, q[j]);
}
{
printf("GetArrayPointer() test\n");
uint32 len = 0;
int * a;
for (uint32 i=0; (a = q.GetArrayPointer(i, len)) != NULL; i++)
{
printf("SubArray " UINT32_FORMAT_SPEC": " UINT32_FORMAT_SPEC" items: ", i, len);
for (uint32 j=0; j<len; j++) printf("%i, ", a[j]);
printf("\n");
}
}
printf("\nStress-testing Queue::Normalize()... this may take a minute\n");
for (uint32 i=0; i<20000; i++)
{
Queue<int> q;
int counter = 0;
for (uint32 j=0; j<i; j++)
{
switch(rand()%6)
{
case 0: case 1: q.AddTail(counter++); break;
case 2: case 3: q.AddHead(counter++); break;
case 4: q.RemoveHead(); break;
case 5: q.RemoveTail(); break;
}
}
int * compareArray = new int[q.GetNumItems()];
for (uint32 j=0; j<q.GetNumItems(); j++) compareArray[j] = q[j];
q.Normalize();
const int * a = q.HeadPointer();
if (memcmp(compareArray, a, q.GetNumItems()*sizeof(int)))
{
printf("ERROR IN NORMALIZE!\n");
for (uint32 i=0; i<q.GetNumItems(); i++) printf(" Expected %i, got %i (qi=%i at " UINT32_FORMAT_SPEC"/" UINT32_FORMAT_SPEC")\n", compareArray[i], a[i], q[i], i, q.GetNumItems());
MCRASH("ERROR IN NORMALIZE!");
}
delete [] compareArray;
}
printf("Queue test complete.\n");
return 0;
}