mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
common/array: ++neat code
no logical changes
This commit is contained in:
parent
7e8743e8fe
commit
cd12618529
1 changed files with 15 additions and 22 deletions
|
@ -95,6 +95,13 @@ struct Array
|
||||||
return data[idx];
|
return data[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void operator=(const Array& rhs)
|
||||||
|
{
|
||||||
|
reserve(rhs.count);
|
||||||
|
if (rhs.count > 0) memcpy(data, rhs.data, sizeof(T) * rhs.count);
|
||||||
|
count = rhs.count;
|
||||||
|
}
|
||||||
|
|
||||||
const T* begin() const
|
const T* begin() const
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
|
@ -157,17 +164,9 @@ struct Array
|
||||||
return count == 0;
|
return count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class COMPARE>
|
template<class COMPARE> void sort()
|
||||||
void sort()
|
|
||||||
{
|
{
|
||||||
qsort<COMPARE>(data, 0, static_cast<int32_t>(count) - 1);
|
qsort<COMPARE>(data, 0, count - 1);
|
||||||
}
|
|
||||||
|
|
||||||
void operator=(const Array& rhs)
|
|
||||||
{
|
|
||||||
reserve(rhs.count);
|
|
||||||
if (rhs.count > 0) memcpy(data, rhs.data, sizeof(T) * rhs.count);
|
|
||||||
count = rhs.count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Array()
|
~Array()
|
||||||
|
@ -177,23 +176,17 @@ struct Array
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class COMPARE>
|
template<class COMPARE>
|
||||||
void qsort(T* arr, int32_t low, int32_t high)
|
void qsort(T* arr, uint32_t low, uint32_t high)
|
||||||
{
|
{
|
||||||
if (low < high) {
|
if (low < high) {
|
||||||
int32_t i = low;
|
auto i = low;
|
||||||
int32_t j = high;
|
auto j = high;
|
||||||
T tmp = arr[low];
|
auto tmp = arr[low];
|
||||||
while (i < j) {
|
while (i < j) {
|
||||||
while (i < j && !COMPARE{}(arr[j], tmp)) --j;
|
while (i < j && !COMPARE{}(arr[j], tmp)) --j;
|
||||||
if (i < j) {
|
if (i < j) arr[i++] = arr[j];
|
||||||
arr[i] = arr[j];
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (i < j && COMPARE{}(arr[i], tmp)) ++i;
|
while (i < j && COMPARE{}(arr[i], tmp)) ++i;
|
||||||
if (i < j) {
|
if (i < j) arr[j--] = arr[i];
|
||||||
arr[j] = arr[i];
|
|
||||||
--j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
arr[i] = tmp;
|
arr[i] = tmp;
|
||||||
qsort<COMPARE>(arr, low, i - 1);
|
qsort<COMPARE>(arr, low, i - 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue