本文整理汇总了C++中Hashtable::ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::ContainsKey方法的具体用法?C++ Hashtable::ContainsKey怎么用?C++ Hashtable::ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::ContainsKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
{
LogTime(MUSCLE_LOG_CRITICALERROR, "String table has %i entries in it, expected 14!\n", table.GetNumItems());
ExitWithoutCleanup(10);
}
{
LogTime(MUSCLE_LOG_INFO, "Test partial backwards iteration\n");
for (HashtableIterator<String, String> iter(table, "Slash", HTIT_FLAG_BACKWARDS); iter.HasData(); iter++) LogTime(MUSCLE_LOG_INFO,"[%s] <-> [%s]\n", iter.GetKey()(), iter.GetValue()());
}
String lookup;
if (table.Get(String("Hello"), lookup) == B_NO_ERROR) LogTime(MUSCLE_LOG_DEBUG, "Hello -> %s\n", lookup());
else bomb("Lookup 1 failed.\n");
if (table.Get(String("Peanut Butter"), lookup) == B_NO_ERROR) LogTime(MUSCLE_LOG_DEBUG, "Peanut Butter -> %s\n", lookup());
else bomb("Lookup 2 failed.\n");
LogTime(MUSCLE_LOG_INFO, "Testing delete-as-you-go traveral\n");
for (HashtableIterator<String, String> st(table); st.HasData(); st++)
{
LogTime(MUSCLE_LOG_INFO, "t3 = %s -> %s (tableSize=" UINT32_FORMAT_SPEC")\n", st.GetKey()(), st.GetValue()(), table.GetNumItems());
if (table.Remove(st.GetKey()) != B_NO_ERROR) bomb("Could not remove string!\n");
#if 0
for (HashtableIterator<String,String> st2(table); st2.HasData(); st2++) printf(" tx = %s -> %s\n", nextKeyString(), nextValueString());
#endif
}
Hashtable<uint32, const char *> sillyTable;
sillyTable.Put(15, "Fifteen");
sillyTable.Put(100, "One Hundred");
sillyTable.Put(150, "One Hundred and Fifty");
sillyTable.Put(200, "Two Hundred");
sillyTable.Put((uint32)-1, "2^32 - 1!");
if (sillyTable.ContainsKey((uint32)-1) == false) bomb("large value failed!");
const char * temp = NULL;
sillyTable.Get(100, temp);
sillyTable.Get(101, temp); // will fail
printf("100 -> %s\n",temp);
printf("Entries in sillyTable:\n");
for (HashtableIterator<uint32, const char *> it(sillyTable); it.HasData(); it++)
{
const char * nextValue = NULL;
status_t ret = sillyTable.Get(it.GetKey(), nextValue);
printf("%i %s: " UINT32_FORMAT_SPEC" -> %s\n", it.HasData(), (ret == B_NO_ERROR) ? "OK" : "ERROR", it.GetKey(), nextValue);
}
}
table.Clear();
{
const uint32 NUM_ITEMS = 1000000;
const uint32 NUM_RUNS = 3;
Hashtable<int, int> testCopy;
Hashtable<String, double> tallies;
for (uint32 t=0; t<NUM_RUNS; t++)
{
Hashtable<int, int> table; (void) table.EnsureSize(NUM_ITEMS);
printf("SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC"/" UINT32_FORMAT_SPEC":\n", t+1, NUM_RUNS);
uint64 startTime = GetRunTime64();
srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) table.Put(rand(), rand()); // we want this to be repeatable, hence srand(0)
AddTally(tallies, "place", startTime, NUM_ITEMS);
startTime = GetRunTime64();
table.SortByValue();