]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/sort/example/reverseintsample.cpp
update sources to v12.2.4
[ceph.git] / ceph / src / boost / libs / sort / example / reverseintsample.cpp
index c4777be9388f4803b0ff6828141f2f8fce2de201..fe31edf8cc78bb8db310949181171067ea73ac0d 100644 (file)
-//! \file
-//! \brief integer sort with a rightshift functor reverse sorting example.
-//
-//  Copyright Steven Ross 2009-2014.
-//
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org/libs/sort for library home page.
-
-// Caution: this file contains Quickbook markup as well as code
-// and comments, don't change any of the special comment markups!
-
-#include <boost/sort/spreadsort/spreadsort.hpp>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <algorithm>
-#include <vector>
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <functional>
-using namespace boost::sort::spreadsort;
-
-#define DATA_TYPE int
-
-struct negrightshift {
-  inline int operator()(const int &x, const unsigned offset) {
-    return -(x >> offset);
-  }
-};
-
-//Pass in an argument to test std::sort
-int main(int argc, const char ** argv) {
-  size_t uCount,uSize=sizeof(DATA_TYPE);
-  bool stdSort = false;
-  unsigned loopCount = 1;
-  for (int u = 1; u < argc; ++u) {
-    if (std::string(argv[u]) == "-std")
-      stdSort = true;
-    else
-      loopCount = atoi(argv[u]);
-  }
-  std::ifstream input("input.txt", std::ios_base::in | std::ios_base::binary);
-  if (input.fail()) {
-    printf("input.txt could not be opened\n");
-    return 1;
-  }
-  double total = 0.0;
-  std::vector<DATA_TYPE> array;
-  input.seekg (0, std::ios_base::end);
-    size_t length = input.tellg();
-  uCount = length/uSize;
-  //Run multiple loops, if requested
-  for (unsigned u = 0; u < loopCount; ++u) {
-    input.seekg (0, std::ios_base::beg);
-    //Conversion to a vector
-    array.resize(uCount);
-    unsigned v = 0;
-    while (input.good() && v < uCount)
-      input.read(reinterpret_cast<char *>(&(array[v++])), uSize );
-    if (v < uCount)
-      array.resize(v);
-    clock_t start, end;
-    double elapsed;
-    start = clock();
-    if (stdSort)
-
-//[reverse_int_1
-      std::sort(array.begin(), array.end(), std::greater<DATA_TYPE>());
-//] [/reverse_int_1]
-    else
-//[reverse_int_2
-      integer_sort(array.begin(), array.end(), negrightshift(), std::greater<DATA_TYPE>());
-//] [/reverse_int_2]
-    end = clock();
-    elapsed = static_cast<double>(end - start) ;
-    std::ofstream ofile;
-    if (stdSort)
-      ofile.open("standard_sort_out.txt", std::ios_base::out |
-                 std::ios_base::binary | std::ios_base::trunc);
-    else
-      ofile.open("boost_sort_out.txt", std::ios_base::out |
-                 std::ios_base::binary | std::ios_base::trunc);
-    if (ofile.good()) {
-      for (unsigned v = 0; v < array.size(); ++v) {
-        ofile.write(reinterpret_cast<char *>(&(array[v])), sizeof(array[v]));
-      }
-      ofile.close();
-    }
-    total += elapsed;
-    array.clear();
-  }
-  if (stdSort)
-    printf("std::sort elapsed time %f\n", total / CLOCKS_PER_SEC);
-  else
-    printf("spreadsort elapsed time %f\n", total / CLOCKS_PER_SEC);
-  return 0;
-}
+//! \file\r
+//! \brief integer sort with a rightshift functor reverse sorting example.\r
+//\r
+//  Copyright Steven Ross 2009-2014.\r
+//\r
+// Distributed under the Boost Software License, Version 1.0.\r
+//    (See accompanying file LICENSE_1_0.txt or copy at\r
+//          http://www.boost.org/LICENSE_1_0.txt)\r
+\r
+//  See http://www.boost.org/libs/sort for library home page.\r
+\r
+// Caution: this file contains Quickbook markup as well as code\r
+// and comments, don't change any of the special comment markups!\r
+\r
+#include <boost/sort/spreadsort/spreadsort.hpp>\r
+#include <time.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <algorithm>\r
+#include <vector>\r
+#include <string>\r
+#include <fstream>\r
+#include <iostream>\r
+#include <functional>\r
+using namespace boost::sort::spreadsort;\r
+\r
+#define DATA_TYPE int\r
+\r
+struct negrightshift {\r
+  inline int operator()(const int &x, const unsigned offset) {\r
+    return -(x >> offset);\r
+  }\r
+};\r
+\r
+//Pass in an argument to test std::sort\r
+int main(int argc, const char ** argv) {\r
+  size_t uCount,uSize=sizeof(DATA_TYPE);\r
+  bool stdSort = false;\r
+  unsigned loopCount = 1;\r
+  for (int u = 1; u < argc; ++u) {\r
+    if (std::string(argv[u]) == "-std")\r
+      stdSort = true;\r
+    else\r
+      loopCount = atoi(argv[u]);\r
+  }\r
+  std::ifstream input("input.txt", std::ios_base::in | std::ios_base::binary);\r
+  if (input.fail()) {\r
+    printf("input.txt could not be opened\n");\r
+    return 1;\r
+  }\r
+  double total = 0.0;\r
+  std::vector<DATA_TYPE> array;\r
+  input.seekg (0, std::ios_base::end);\r
+    size_t length = input.tellg();\r
+  uCount = length/uSize;\r
+  //Run multiple loops, if requested\r
+  for (unsigned u = 0; u < loopCount; ++u) {\r
+    input.seekg (0, std::ios_base::beg);\r
+    //Conversion to a vector\r
+    array.resize(uCount);\r
+    unsigned v = 0;\r
+    while (input.good() && v < uCount)\r
+      input.read(reinterpret_cast<char *>(&(array[v++])), uSize );\r
+    if (v < uCount)\r
+      array.resize(v);\r
+    clock_t start, end;\r
+    double elapsed;\r
+    start = clock();\r
+    if (stdSort)\r
+\r
+//[reverse_int_1\r
+      std::sort(array.begin(), array.end(), std::greater<DATA_TYPE>());\r
+//] [/reverse_int_1]\r
+    else\r
+//[reverse_int_2\r
+      integer_sort(array.begin(), array.end(), negrightshift(), std::greater<DATA_TYPE>());\r
+//] [/reverse_int_2]\r
+    end = clock();\r
+    elapsed = static_cast<double>(end - start) ;\r
+    std::ofstream ofile;\r
+    if (stdSort)\r
+      ofile.open("standard_sort_out.txt", std::ios_base::out |\r
+                 std::ios_base::binary | std::ios_base::trunc);\r
+    else\r
+      ofile.open("boost_sort_out.txt", std::ios_base::out |\r
+                 std::ios_base::binary | std::ios_base::trunc);\r
+    if (ofile.good()) {\r
+      for (unsigned v = 0; v < array.size(); ++v) {\r
+        ofile.write(reinterpret_cast<char *>(&(array[v])), sizeof(array[v]));\r
+      }\r
+      ofile.close();\r
+    }\r
+    total += elapsed;\r
+    array.clear();\r
+  }\r
+  if (stdSort)\r
+    printf("std::sort elapsed time %f\n", total / CLOCKS_PER_SEC);\r
+  else\r
+    printf("spreadsort elapsed time %f\n", total / CLOCKS_PER_SEC);\r
+  return 0;\r
+}\r