template<class _RanIt,
class _Diff,
class _Pr> inline
void _Sort(_RanIt _First, _RanIt _Last, _Diff _Ideal, _Pr _Pred)
{
_Diff _Count;
for (;<big> _ISORT_MAX < (_Count = _Last - _First) </big>&& 0 < _Ideal; )
{
pair<_RanIt, _RanIt> _Mid =
_Unguarded_partition(_First, _Last, _Pred);
_Ideal /= 2, _Ideal += _Ideal / 2;
if (_Mid.first - _First < _Last - _Mid.second)
_Sort(_First, _Mid.first, _Ideal, _Pred), _First = _Mid.second;
else
_Sort(_Mid.second, _Last, _Ideal, _Pred), _Last = _Mid.first;
}
if (<big>_ISORT_MAX < _Count</big>)
{
std::make_heap(_First, _Last, _Pred);
std::sort_heap(_First, _Last, _Pred);
}
else if (1 < _Count)
_Insertion_sort(_First, _Last, _Pred);
}
This is the code of _Sort , heap sort is
closed by _ISORT_MAX.
In release heap sort may be
opened .
Changed the source ,my sort function is close to the speed of std::sort in 1M size vector.
const int _ISORT_MAX2 = 64*64;
for (;_ISORT_MAX2 < (_Count = _Last - _First) && 0 < _Ideal; )
Adjust the value of _ISORT_MAX2 , sort function will get different speed ,even quicker than std::sort.