本文整理汇总了C++中Hashtable::SortByKey方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::SortByKey方法的具体用法?C++ Hashtable::SortByKey怎么用?C++ Hashtable::SortByKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::SortByKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Point as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
Hashtable<Point, int> tupleTable;
Point a(9,10);
Point b(-11,-12);
tupleTable.Put(a, 1);
tupleTable.Put(b, 2);
for (HashtableIterator<Point, int> iter(tupleTable); iter.HasData(); iter++)
{
const Point & key = iter.GetKey();
printf("key=%f,%f val=%i\n", key.x(), key.y(), iter.GetValue());
}
int * ra = tupleTable.Get(a);
int * rb = tupleTable.Get(b);
printf("Point: ra=[%p] rb=[%p]\n", ra, rb);
}
{
LogTime(MUSCLE_LOG_INFO, "Preparing large table for sort...\n");
const uint32 numItems = 100000;
Hashtable<int, Void> table; (void) table.EnsureSize(100000);
for (uint32 i=0; i<numItems; i++) table.PutWithDefault((int)rand());
uint32 actualNumItems = table.GetNumItems(); // may be smaller than numItems, due to duplicate values!
(void) table.CountAverageLookupComparisons(true);
LogTime(MUSCLE_LOG_INFO, "Sorting...\n");
uint64 start = GetRunTime64();
table.SortByKey();
uint64 end = GetRunTime64();
LogTime(MUSCLE_LOG_INFO, "Time to sort " UINT32_FORMAT_SPEC" items: " UINT64_FORMAT_SPEC "ms\n", numItems, (end-start)/1000);
// Check the resulting sorted table for correctness in both directions
CheckTable(table, actualNumItems, false);
CheckTable(table, actualNumItems, true);
}
// Test the sort algorithm for efficiency and correctness
{
LogTime(MUSCLE_LOG_INFO, "Preparing large table for sort...\n");
const uint32 numItems = 100000;
Hashtable<int, Void> table;
for (uint32 i=0; i<numItems; i++) table.PutWithDefault((int)rand());
uint32 actualNumItems = table.GetNumItems(); // may be smaller than numItems, due to duplicate values!
LogTime(MUSCLE_LOG_INFO, "Sorting...\n");
uint64 start = GetRunTime64();
table.SortByKey();
uint64 end = GetRunTime64();
LogTime(MUSCLE_LOG_INFO, "Time to sort " UINT32_FORMAT_SPEC" items: " UINT64_FORMAT_SPEC "ms\n", numItems, (end-start)/1000);
// Check the resulting sorted table for correctness in both directions
CheckTable(table, actualNumItems, false);
CheckTable(table, actualNumItems, true);
}
Hashtable<String, String> table;
{