]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/reverseintsample.cpp
2 //! \brief integer sort with a rightshift functor reverse sorting example.
4 // Copyright Steven Ross 2009-2014.
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/sort for library home page.
12 // Caution: this file contains Quickbook markup as well as code
13 // and comments, don't change any of the special comment markups!
15 #include <boost/sort/spreadsort/spreadsort.hpp>
25 using namespace boost::sort::spreadsort
;
29 struct negrightshift
{
30 inline int operator()(const int &x
, const unsigned offset
) {
31 return -(x
>> offset
);
35 //Pass in an argument to test std::sort
36 int main(int argc
, const char ** argv
) {
37 size_t uCount
,uSize
=sizeof(DATA_TYPE
);
39 unsigned loopCount
= 1;
40 for (int u
= 1; u
< argc
; ++u
) {
41 if (std::string(argv
[u
]) == "-std")
44 loopCount
= atoi(argv
[u
]);
46 std::ifstream
input("input.txt", std::ios_base::in
| std::ios_base::binary
);
48 printf("input.txt could not be opened\n");
52 std::vector
<DATA_TYPE
> array
;
53 input
.seekg (0, std::ios_base::end
);
54 size_t length
= input
.tellg();
55 uCount
= length
/uSize
;
56 //Run multiple loops, if requested
57 for (unsigned u
= 0; u
< loopCount
; ++u
) {
58 input
.seekg (0, std::ios_base::beg
);
59 //Conversion to a vector
62 while (input
.good() && v
< uCount
)
63 input
.read(reinterpret_cast<char *>(&(array
[v
++])), uSize
);
72 std::sort(array
.begin(), array
.end(), std::greater
<DATA_TYPE
>());
76 integer_sort(array
.begin(), array
.end(), negrightshift(), std::greater
<DATA_TYPE
>());
79 elapsed
= static_cast<double>(end
- start
) ;
82 ofile
.open("standard_sort_out.txt", std::ios_base::out
|
83 std::ios_base::binary
| std::ios_base::trunc
);
85 ofile
.open("boost_sort_out.txt", std::ios_base::out
|
86 std::ios_base::binary
| std::ios_base::trunc
);
88 for (unsigned v
= 0; v
< array
.size(); ++v
) {
89 ofile
.write(reinterpret_cast<char *>(&(array
[v
])), sizeof(array
[v
]));
97 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
99 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);