]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/alrbreaker.cpp
1 // a sorting example that uses the worst-case for conventional MSD radix sorts.
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/spreadsort.hpp>
21 using namespace boost::sort::spreadsort
;
24 #define DATA_TYPE boost::uint64_t
26 #define ALR_THRESHOLD 3
28 const unsigned max_count
= ALR_THRESHOLD
- 1;
29 const unsigned bit_shift
= detail::rough_log_2_size(max_count
) -
30 detail::int_log_mean_bin_size
;
31 const unsigned radix_threshold
= detail::rough_log_2_size(max_count
) + 1;
32 //Increase this size if too fast to test accurately
33 const unsigned top_splits
= 12;
35 const DATA_TYPE typed_one
= 1;
38 fill_vector(vector
<DATA_TYPE
> & input
, const DATA_TYPE base_value
,
39 unsigned remaining_bits
)
41 if (remaining_bits
>= radix_threshold
) {
42 input
.push_back((base_value
<< remaining_bits
) +
43 ((typed_one
<< remaining_bits
) - 1));
44 fill_vector(input
, base_value
<< bit_shift
, remaining_bits
- bit_shift
);
47 for (unsigned u
= 0; u
< max_count
; ++u
)
48 input
.push_back((base_value
<< remaining_bits
) +
49 (rand() % (1 << remaining_bits
)));
53 //Tests spreadsort on the worst-case distribution for standard MSD radix sorts.
54 int main(int, const char **) {
55 vector
<DATA_TYPE
> input
;
56 for (int ii
= (1 << top_splits
) - 1; ii
>= 0; --ii
)
57 fill_vector(input
, ii
, (sizeof(DATA_TYPE
) * 8) - top_splits
);
59 //Run both std::sort and spreadsort
60 for (unsigned u
= 0; u
< 2; ++u
) {
61 vector
<DATA_TYPE
> array
= input
;
66 std::sort(array
.begin(), array
.end());
68 boost::sort::spreadsort::spreadsort(array
.begin(), array
.end());
70 elapsed
= static_cast<double>(end
- start
);
72 printf("std::sort elapsed time %f\n", elapsed
/ CLOCKS_PER_SEC
);
74 printf("spreadsort elapsed time %f\n", elapsed
/ CLOCKS_PER_SEC
);