本文整理汇总了C++中Hashtable::HasItems方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::HasItems方法的具体用法?C++ Hashtable::HasItems怎么用?C++ Hashtable::HasItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::HasItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NetworkInterfacesChanged
virtual void NetworkInterfacesChanged(const Hashtable<String, Void> & interfaceNames)
{
String s;
if (interfaceNames.HasItems())
{
s = " on these interfaces: ";
for (HashtableIterator<String, Void> iter(interfaceNames); iter.HasData(); iter++) s += iter.GetKey().Prepend(' ');
}
LogTime(MUSCLE_LOG_INFO, "TestSession: Network configuration change detected%s\n", s());
}
示例2: main
//.........这里部分代码省略.........
ok = false;
numEntries--; // let's do this one over
half = i; // so the remove code won't freak out about not everything being there
break;
}
}
}
if (ok)
{
//printf("Checking that all entries are still there...\n");
_state = 6;
{
if (t.GetNumItems() != numEntries) bomb("ERROR, WRONG SIZE %i vs %i!\n", t.GetNumItems(), numEntries);
for (int32 i=((int32)numEntries)-1; i>=0; i--)
{
char temp[300];
muscleSprintf(temp, UINT32_FORMAT_SPEC, i);
uint32 tv = 0;
if (t.Get(temp, tv) != B_NO_ERROR) bomb("ERROR, MISSING KEY [%s]\n", temp);
if (tv != ((uint32)i)) bomb("ERROR, WRONG KEY %s != " UINT32_FORMAT_SPEC"!\n", temp, tv);
}
}
//printf("Iterating through table...\n");
_state = 7;
{
uint32 count = 0;
for (HashtableIterator<String, uint32> iter(t); iter.HasData(); iter++)
{
char buf[300];
muscleSprintf(buf, UINT32_FORMAT_SPEC, count);
if (iter.GetKey() != buf) bomb("ERROR: iteration was wrong, item " UINT32_FORMAT_SPEC" was [%s] not [%s]!\n", count, iter.GetKey()(), buf);
if (iter.GetValue() != count) bomb("ERROR: iteration value was wrong, item " UINT32_FORMAT_SPEC" was " UINT32_FORMAT_SPEC" not " UINT32_FORMAT_SPEC"!i!\n", count, iter.GetValue(), count);
count++;
}
}
//printf("Removing the second half of the entries...\n");
_state = 8;
{
for (uint32 i=half; i<numEntries; i++)
{
char temp[64];
muscleSprintf(temp, UINT32_FORMAT_SPEC, i);
uint32 tv = 0; // just to shut the compiler up
if (t.Remove(temp, tv) != B_NO_ERROR) bomb("ERROR, MISSING REMOVE KEY [%s] A\n", temp);
if (tv != i) bomb("ERROR, REMOVE WAS WRONG VALUE " UINT32_FORMAT_SPEC"\n", tv);
}
}
//printf("Iterating over only first half...\n");
_state = 9;
{
uint32 sum = 0;
for (uint32 i=0; i<half; i++) sum += i;
uint32 count = 0, checkSum = 0;
for (HashtableIterator<String, uint32> iter(t); iter.HasData(); iter++)
{
count++;
checkSum += iter.GetValue();
}
if (count != half) bomb("ERROR: Count mismatch " UINT32_FORMAT_SPEC" vs " UINT32_FORMAT_SPEC"!\n", count, numEntries);
if (checkSum != sum) bomb("ERROR: Sum mismatch " UINT32_FORMAT_SPEC" vs " UINT32_FORMAT_SPEC"!\n", sum, checkSum);
}
}
//printf("Clearing Table (%s)\n", fastClear ? "Quickly" : "Slowly");
_state = 10;
if (fastClear) t.Clear();
else
{
for (uint32 i=0; i<half; i++)
{
char temp[300];
muscleSprintf(temp, UINT32_FORMAT_SPEC, i);
uint32 tv = 0; // just to shut the compiler up
if (t.Remove(temp, tv) != B_NO_ERROR) bomb("ERROR, MISSING REMOVE KEY [%s] (" UINT32_FORMAT_SPEC"/" UINT32_FORMAT_SPEC") B\n", temp, i, half);
if (tv != i) bomb("ERROR, REMOVE WAS WRONG VALUE " UINT32_FORMAT_SPEC"\n", tv);
}
}
HashtableIterator<String, uint32> paranoia(t);
if (paranoia.HasData()) bomb("ERROR, ITERATOR CONTAINED ITEMS AFTER CLEAR!\n");
if (t.HasItems()) bomb("ERROR, SIZE WAS NON-ZERO (" UINT32_FORMAT_SPEC") AFTER CLEAR!\n", t.GetNumItems());
fastClear = !fastClear;
}
printf("Finished torture test successfully!\n");
}
#ifdef MUSCLE_AVOID_THREAD_SAFE_HASHTABLE_ITERATORS
printf("Thread-safe hashtable iterators were disabled at compile time, so I won't test them!\n");
return 0;
#else
return DoThreadTest();
#endif
}