fix issue

This commit is contained in:
Robin Dietzel 2023-12-05 10:57:17 +01:00
parent 4144ab422e
commit 35c98e180d

View File

@ -20,13 +20,11 @@ public:
private:
auto parition(std::span<T> &data) -> std::pair<std::span<T>, std::span<T>> {
std::vector<T> buf(data);
auto pivot = data.begin();
std::advance(pivot, std::distance(data.begin(), data.end()) / 2);
auto pivot = buf.begin();
std::advance(pivot, std::distance(buf.begin(), buf.end()) / 2);
auto lefti = buf.begin();
auto righti = buf.end();
auto lefti = data.begin();
auto righti = data.end();
while (1) {
for (; cmp(*lefti, *pivot); lefti++);
@ -39,7 +37,6 @@ private:
std::swap(lefti, righti);
}
std::move(buf.begin(), buf.end(), data.begin());
return {std::span<T>(data.begin(), lefti), std::span<T>(lefti, data.end())};
}
@ -54,13 +51,9 @@ private:
}
}
// Determine mid of data
auto mid = data.begin();
std::advance(mid, std::distance(data.begin(), data.end()) / 2);
// Generate left and right view on data (no copies are made here)
std::span<T> left(data.begin(), mid);
std::span<T> right(mid, data.end());
auto res = parition(data);
auto left = res.first;
auto right = res.second;
if (depth < mdepth) {
std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });