当前位置: 首页>>代码示例>>C++>>正文


C++ Hashtable::SortByValue方法代码示例

本文整理汇总了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);
开发者ID:ModeenF,项目名称:muscle,代码行数:67,代码来源:testhashtable.cpp


注:本文中的Hashtable::SortByValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。