return true;
}
-void DataArrayDouble::sort() throw(INTERP_KERNEL::Exception)
+void DataArrayDouble::sort(bool asc) throw(INTERP_KERNEL::Exception)
{
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
- _mem.sort();
+ _mem.sort(asc);
}
void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
return a->isEqualWithoutConsideringStr(*b);
}
-void DataArrayInt::sort() throw(INTERP_KERNEL::Exception)
+void DataArrayInt::sort(bool asc) throw(INTERP_KERNEL::Exception)
{
checkAllocated();
if(getNumberOfComponents()!=1)
throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
- _mem.sort();
+ _mem.sort(asc);
}
void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
void fillWithValue(const T& val);
T *fromNoInterlace(int nbOfComp) const;
T *toNoInterlace(int nbOfComp) const;
- void sort();
+ void sort(bool asc);
void reverse();
void alloc(int nbOfElements) throw(INTERP_KERNEL::Exception);
void reAlloc(int newNbOfElements) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void fillWithValue(double val) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void iota(double init=0.) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void sort() throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void sort(bool asc=true) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void reverse() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayInt& other) const;
MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception);
- MEDCOUPLING_EXPORT void sort() throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT void sort(bool asc=true) throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void reverse() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void fillWithZero() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void fillWithValue(int val) throw(INTERP_KERNEL::Exception);
}
template<class T>
- void MemArray<T>::sort()
+ void MemArray<T>::sort(bool asc)
{
T *pt=_pointer.getPointer();
- std::sort(pt,pt+_nb_of_elem);
+ if(asc)
+ std::sort(pt,pt+_nb_of_elem);
+ else
+ {
+ typename std::reverse_iterator<T *> it1(pt+_nb_of_elem);
+ typename std::reverse_iterator<T *> it2(pt);
+ std::sort(it1,it2);
+ }
}
template<class T>