@@ -60,32 +60,35 @@ constexpr auto runtime_sort_exactly_n_relocate(Iterator it, auto const size, aut
60
60
}
61
61
}
62
62
63
- export template <typename Compare = std::less<>>
64
- constexpr auto chunked_insertion_sort (range auto && r, Compare const compare = Compare()) -> void {
65
- constexpr auto chunk_size = 4_bi;
66
- auto it = containers::begin (r);
67
- auto const last = containers::end (r);
68
- #if 1
69
- auto const initial_sort_size = bounded::min (chunk_size, ::containers::size (r));
70
- ::containers::small_size_optimized_sort (
71
- subrange (it, initial_sort_size),
72
- compare,
73
- [](auto &&, auto ) { std::unreachable (); }
74
- );
75
- it += initial_sort_size;
76
- #endif
77
- auto buffer = containers::uninitialized_array<std::remove_reference_t <decltype (*it)>, chunk_size>();
78
- while (it != last) {
79
- auto const count = bounded::min (chunk_size, last - it);
80
- auto next_it = ::containers::runtime_sort_exactly_n_relocate (it, count, buffer.data (), compare);
81
- merge_relocate_second_range (
82
- subrange (containers::begin (r), it),
83
- subrange (buffer.data (), count),
84
- next_it,
85
- compare
63
+ struct chunked_insertion_sort_t {
64
+ template <typename Compare = std::less<>>
65
+ static constexpr auto operator ()(range auto && r, Compare const compare = Compare()) -> void {
66
+ constexpr auto chunk_size = 4_bi;
67
+ auto it = containers::begin (r);
68
+ auto const last = containers::end (r);
69
+ #if 1
70
+ auto const initial_sort_size = bounded::min (chunk_size, ::containers::size (r));
71
+ ::containers::small_size_optimized_sort (
72
+ subrange (it, initial_sort_size),
73
+ compare,
74
+ [](auto &&, auto ) { std::unreachable (); }
86
75
);
87
- it = next_it;
76
+ it += initial_sort_size;
77
+ #endif
78
+ auto buffer = containers::uninitialized_array<std::remove_reference_t <decltype (*it)>, chunk_size>();
79
+ while (it != last) {
80
+ auto const count = bounded::min (chunk_size, last - it);
81
+ auto next_it = ::containers::runtime_sort_exactly_n_relocate (it, count, buffer.data (), compare);
82
+ merge_relocate_second_range (
83
+ subrange (containers::begin (r), it),
84
+ subrange (buffer.data (), count),
85
+ next_it,
86
+ compare
87
+ );
88
+ it = next_it;
89
+ }
88
90
}
89
91
};
92
+ export constexpr auto chunked_insertion_sort = chunked_insertion_sort_t ();
90
93
91
94
} // namespace containers
0 commit comments