]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/charstringsample.cpp
1 // Example of sorting structs with a string key and indexing functors.
3 // Copyright Steven Ross 2009-2014.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/sort for library home page.
11 #include <boost/sort/spreadsort/string_sort.hpp>
21 using namespace boost::sort::spreadsort
;
25 inline bool operator<(const DATA_TYPE
&y
) const { return a
< y
.a
;}
30 inline unsigned char operator()(const DATA_TYPE
&x
, size_t offset
) const {
36 inline size_t operator()(const DATA_TYPE
&x
) const{ return x
.a
.size(); }
41 //Pass in an argument to test std::sort
42 int main(int argc
, const char ** argv
) {
45 unsigned loopCount
= 1;
46 for (int u
= 1; u
< argc
; ++u
) {
47 if (std::string(argv
[u
]) == "-std")
50 loopCount
= atoi(argv
[u
]);
53 //Run multiple loops, if requested
54 std::vector
<DATA_TYPE
> array
;
55 for (unsigned u
= 0; u
< loopCount
; ++u
) {
56 indata
.open("input.txt", std::ios_base::in
| std::ios_base::binary
);
58 printf("input.txt could not be opened\n");
63 while (!indata
.eof() ) {
64 array
.push_back(inval
);
73 std::sort(array
.begin(), array
.end());
76 string_sort(array
.begin(), array
.end(), bracket(), getsize());
80 elapsed
= static_cast<double>(end
- start
);
83 ofile
.open("standard_sort_out.txt", std::ios_base::out
|
84 std::ios_base::binary
| std::ios_base::trunc
);
86 ofile
.open("boost_sort_out.txt", std::ios_base::out
|
87 std::ios_base::binary
| std::ios_base::trunc
);
89 for (unsigned u
= 0; u
< array
.size(); ++u
)
90 ofile
<< array
[u
].a
<< "\n";
97 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
99 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);