fix issue
This commit is contained in:
parent
4144ab422e
commit
35c98e180d
@ -20,13 +20,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
auto parition(std::span<T> &data) -> std::pair<std::span<T>, std::span<T>> {
|
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();
|
auto lefti = data.begin();
|
||||||
std::advance(pivot, std::distance(buf.begin(), buf.end()) / 2);
|
auto righti = data.end();
|
||||||
|
|
||||||
auto lefti = buf.begin();
|
|
||||||
auto righti = buf.end();
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
for (; cmp(*lefti, *pivot); lefti++);
|
for (; cmp(*lefti, *pivot); lefti++);
|
||||||
@ -39,7 +37,6 @@ private:
|
|||||||
std::swap(lefti, righti);
|
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())};
|
return {std::span<T>(data.begin(), lefti), std::span<T>(lefti, data.end())};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +51,9 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine mid of data
|
auto res = parition(data);
|
||||||
auto mid = data.begin();
|
auto left = res.first;
|
||||||
std::advance(mid, std::distance(data.begin(), data.end()) / 2);
|
auto right = res.second;
|
||||||
|
|
||||||
// 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());
|
|
||||||
|
|
||||||
if (depth < mdepth) {
|
if (depth < mdepth) {
|
||||||
std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });
|
std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });
|
||||||
|
Loading…
Reference in New Issue
Block a user