quicksort experiments
This commit is contained in:
parent
f5a5bade28
commit
0c31a3c24e
@ -36,7 +36,7 @@ private:
|
||||
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 &left = res.first;
|
||||
auto &right = res.second;
|
||||
auto pivot = data[std::distance(data.begin(), data.end()) / 2];
|
||||
|
||||
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) {
|
||||
std::thread left_thread([&]() { qsort(left, depth + 1, mdepth); });
|
||||
|
Loading…
Reference in New Issue
Block a user