quicksort experiments

This commit is contained in:
Robin Dietzel 2023-12-05 21:54:43 +01:00
parent f5a5bade28
commit 0c31a3c24e

View File

@ -36,7 +36,7 @@ private:
std::swap(*lefti, *righti); std::swap(*lefti, *righti);
} }
return {std::span<T>(data.begin(), pivot - 1), std::span<T>(pivot + 1, data.end())}; return {std::span<T>(data.begin(), pivot), std::span<T>(pivot, data.end())};
} }
@ -50,9 +50,18 @@ private:
} }
} }
auto res = parition(data); auto pivot = data[std::distance(data.begin(), data.end()) / 2];
auto &left = res.first;
auto &right = res.second; auto m1 = std::partition(data.begin(), data.end(), [pivot, this](const auto &em) {
return this->cmp(em, pivot);
});
auto m2 = std::partition(m1, data.end(), [pivot, this](const auto &em) {
return !(this->cmp(em, pivot));
});
auto left = data.subspan(0, m1 - data.begin());
auto right = data.subspan(m2 - data.begin(), data.size());
if (depth < mdepth) { if (depth < mdepth) {
std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); }); std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });