本文整理汇总了C++中Hashtable::SortByValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::SortByValue方法的具体用法?C++ Hashtable::SortByValue怎么用?C++ Hashtable::SortByValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::SortByValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
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();
AddTally(tallies, "sort", startTime, NUM_ITEMS);
startTime = GetRunTime64();
testCopy = table; // just to make sure copying a table works
AddTally(tallies, "copy", startTime, NUM_ITEMS);
startTime = GetRunTime64();
if (testCopy != table) bomb("Copy was not the same!");
AddTally(tallies, "compare", startTime, NUM_ITEMS);
startTime = GetRunTime64();
if (testCopy.IsEqualTo(table, true) == false) bomb("Copy was not the same, considering ordering!");
AddTally(tallies, "o-compare", startTime, NUM_ITEMS);
startTime = GetRunTime64();
table.Clear();
AddTally(tallies, "clear", startTime, NUM_ITEMS);
}
printf("GRAND AVERAGES OVER ALL " UINT32_FORMAT_SPEC" RUNS ARE:\n", NUM_RUNS);
for (HashtableIterator<String, double> iter(tallies); iter.HasData(); iter++) printf(" %f items/second for %s\n", iter.GetValue()/NUM_RUNS, iter.GetKey()());
}
// Now some timing test with String keys and values, for testing of the C++11 move semantics
PrintAndClearStringCopyCounts("Before String Sort test");
{
const uint32 NUM_ITEMS = 1000000;
const uint32 NUM_RUNS = 3;
Hashtable<String, String> testCopy;
Hashtable<String, double> tallies;
for (uint32 t=0; t<NUM_RUNS; t++)
{
Hashtable<String, String> table; (void) table.EnsureSize(NUM_ITEMS);