Skip to content

Commit df9b374

Browse files
committed
Improve insertion_sort for benchmark comparison
1 parent c34b71c commit df9b374

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

source/containers/test/sort/sort_benchmark.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import containers.algorithms.sort.chunked_insertion_sort;
1010
import bounded;
1111
import containers;
1212
import std_module;
13+
import tv;
1314

1415
namespace {
1516

@@ -58,13 +59,17 @@ constexpr auto insertion_sort = [](containers::range auto && r) -> void {
5859
auto const first = containers::begin(r);
5960
auto const last = containers::end(r);
6061
for (auto it = first; it != last; ++it) {
61-
auto const insertion = containers::find_last(containers::subrange(first, it), *it);
62-
// TODO: Relocate-based algorithm
63-
std::rotate(
64-
containers::maybe_legacy_iterator(insertion),
65-
containers::maybe_legacy_iterator(it),
66-
containers::maybe_legacy_iterator(containers::next(it))
62+
auto const sorted = containers::subrange(first, it);
63+
auto const insertion = ::containers::find_if(
64+
sorted,
65+
[&](auto const & value) { return *it < value; }
6766
);
67+
auto temp = tv::relocate_into_storage(*it);
68+
containers::uninitialized_relocate_backward(
69+
containers::subrange(insertion, it),
70+
containers::next(it)
71+
);
72+
bounded::relocate_at(*insertion, temp.value);
6873
}
6974
};
7075

0 commit comments

Comments
 (0)