This commit is contained in:
Spartan322
2025-07-19 14:15:00 -04:00
909 changed files with 11718 additions and 4256 deletions

View File

@@ -170,17 +170,17 @@ public:
inline int64_t partitioner(int64_t p_first, int64_t p_last, int64_t p_pivot, T *p_array) const {
const int64_t unmodified_first = p_first;
const int64_t unmodified_last = p_last;
const T &pivot_element = p_array[p_pivot];
const T *pivot_element_location = &p_array[p_pivot];
while (true) {
while (p_first != p_pivot && compare(p_array[p_first], pivot_element)) {
while (p_first != p_pivot && compare(p_array[p_first], *pivot_element_location)) {
if constexpr (Validate) {
ERR_BAD_COMPARE(p_first == unmodified_last - 1);
}
p_first++;
}
p_last--;
while (p_last != p_pivot && compare(pivot_element, p_array[p_last])) {
while (p_last != p_pivot && compare(*pivot_element_location, p_array[p_last])) {
if constexpr (Validate) {
ERR_BAD_COMPARE(p_last == unmodified_first);
}
@@ -191,6 +191,11 @@ public:
return p_first;
}
if (pivot_element_location == &p_array[p_first]) {
pivot_element_location = &p_array[p_last];
} else if (pivot_element_location == &p_array[p_last]) {
pivot_element_location = &p_array[p_first];
}
SWAP(p_array[p_first], p_array[p_last]);
p_first++;
}