if(LA_sort_traits<SORTABLE,INDEX,type>::compare(object,l,piv)){parity^=1;object.swap(l,piv);if(perm){PERMINDEXtmp=perm[l];perm[l]=perm[piv];perm[piv]=tmp;}}//and change the pivot element implicitly
if(LA_sort_traits<SORTABLE,INDEX,type>::compare(object,piv,r)){parity^=1;object.swap(r,piv);if(perm){PERMINDEXtmp=perm[r];perm[r]=perm[piv];perm[piv]=tmp;}}//and change the pivot element implicitly
if(r-l==1)returnparity;//2 elements and preparation for median
piv=l+(r-l)/2;//pivoting by median of 3 - safer
if(LA_sort_traits<SORTABLE,INDEX,type>::comparestable(object,l,piv,aux)){parity^=1;object.swap(l,piv);{INDEXtmp=aux[l];aux[l]=aux[piv];aux[piv]=tmp;}if(perm){PERMINDEXtmp=perm[l];perm[l]=perm[piv];perm[piv]=tmp;}}//and change the pivot element implicitly
if(LA_sort_traits<SORTABLE,INDEX,type>::comparestable(object,piv,r,aux)){parity^=1;object.swap(r,piv);{INDEXtmp=aux[r];aux[r]=aux[piv];aux[piv]=tmp;}if(perm){PERMINDEXtmp=perm[r];perm[r]=perm[piv];perm[piv]=tmp;}}//and change the pivot element implicitly
if(r-l==2)returnparity;//in the case of 3 elements we are finished too
//general case , l-th r-th already processed
i=l+1;j=r-1;
do{
//important sharp inequality - stops at sentinel element for efficiency
// this is inefficient if all keys are equal - unnecessary n log n swaps are done, but we assume that it is atypical input
if(r-l==1)returnparity;//2 elements and preparation for median
piv=l+(r-l)/2;//pivoting by median of 3 - safer
if(*l>*piv){parity^=1;{Stmp;tmp=*l;*l=*piv;*piv=tmp;}if(perm){PERMINDEXtmp=*perm;*perm=perm[piv-l];perm[piv-l]=tmp;}}//and change the pivot element implicitly
if(*piv>*r){parity^=1;{Stmp;tmp=*r;*r=*piv;*piv=tmp;}if(perm){PERMINDEXtmp=perm[r-l];perm[r-l]=perm[piv-l];perm[piv-l]=tmp;}}//and change the pivot element implicitly
if(r-l==2)returnparity;//in the case of 3 elements we are finished too
//general case , l-th r-th already processed
i=l+1;j=r-1;
do{
//important sharp inequality - stops at sentinel element for efficiency
// this is inefficient if all keys are equal - unnecessary n log n swaps are done, but we assume that it is atypical input
while(*piv>*i++);
i--;
while(*j-->*piv);
j++;
if(i<j)
{
// swap and keep track of position of pivoting element
if(r-l==1)returnparity;//2 elements and preparation for median
piv=l+(r-l)/2;//pivoting by median of 3 - safer
if(*l<*piv){parity^=1;{Stmp;tmp=*l;*l=*piv;*piv=tmp;}if(perm){PERMINDEXtmp=*perm;*perm=perm[piv-l];perm[piv-l]=tmp;}}//and change the pivot element implicitly
if(*piv<*r){parity^=1;{Stmp;tmp=*r;*r=*piv;*piv=tmp;}if(perm){PERMINDEXtmp=perm[r-l];perm[r-l]=perm[piv-l];perm[piv-l]=tmp;}}//and change the pivot element implicitly
if(r-l==2)returnparity;//in the case of 3 elements we are finished too
//general case , l-th r-th already processed
i=l+1;j=r-1;
do{
//important sharp inequality - stops at sentinel element for efficiency
// this is inefficient if all keys are equal - unnecessary n log n swaps are done, but we assume that it is atypical input
while(*piv<*i++);
i--;
while(*j--<*piv);
j++;
if(i<j)
{
// swap and keep track of position of pivoting element